forked from Mirrors/openclonk
Add more overloads of the C4Value constructor
This allows one to use the C4Value constructor instead of C4ValueConv. To avoid unintended implicit conversions like const char * to bool, add a private template constructor that catches everything not in the list of intended constructors.epoxy
parent
05359179e7
commit
b08f51372a
|
@ -106,6 +106,7 @@ class C4PlayerInfoList;
|
|||
class C4PlayerInfoListBox;
|
||||
class C4PlayerList;
|
||||
class C4PropList;
|
||||
class C4PropListStatic;
|
||||
class C4PXS;
|
||||
class C4PXSSystem;
|
||||
class C4RankSystem;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <C4GameObjects.h>
|
||||
#include <C4Object.h>
|
||||
#include <C4Log.h>
|
||||
#include <C4Effect.h>
|
||||
|
||||
const C4Value C4VNull;
|
||||
|
||||
|
@ -59,10 +60,10 @@ const char* GetC4VName(const C4V_Type Type)
|
|||
}
|
||||
}
|
||||
|
||||
C4Value::C4Value(C4Object *pObj): NextRef(NULL), Type(pObj ? C4V_PropList : C4V_Nil)
|
||||
{
|
||||
Data.PropList = pObj; AddDataRef();
|
||||
}
|
||||
C4Value::C4Value(C4PropListStatic * p): C4Value(static_cast<C4PropList *>(p)) {}
|
||||
C4Value::C4Value(C4Def * p): C4Value(static_cast<C4PropList *>(p)) {}
|
||||
C4Value::C4Value(C4Object * p): C4Value(static_cast<C4PropList *>(p)) {}
|
||||
C4Value::C4Value(C4Effect * p): C4Value(static_cast<C4PropList *>(p)) {}
|
||||
|
||||
C4Object * C4Value::getObj() const
|
||||
{
|
||||
|
@ -179,20 +180,6 @@ StdStrBuf C4Value::GetDataString(int depth) const
|
|||
}
|
||||
}
|
||||
|
||||
C4Value C4VString(const char *strString)
|
||||
{
|
||||
// safety
|
||||
if (!strString) return C4Value();
|
||||
return C4Value(::Strings.RegString(strString));
|
||||
}
|
||||
|
||||
C4Value C4VString(StdStrBuf Str)
|
||||
{
|
||||
// safety
|
||||
if (Str.isNull()) return C4Value();
|
||||
return C4Value(::Strings.RegString(Str));
|
||||
}
|
||||
|
||||
const C4Value & C4ValueNumbers::GetValue(uint32_t n)
|
||||
{
|
||||
if (n <= LoadedValues.size())
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define INC_C4Value
|
||||
|
||||
#include "C4StringTable.h"
|
||||
#include <C4ObjectPtr.h>
|
||||
|
||||
// C4Value type
|
||||
enum C4V_Type
|
||||
|
@ -44,6 +45,7 @@ enum C4V_Type
|
|||
#define C4V_FirstPointer C4V_PropList
|
||||
|
||||
const char* GetC4VName(const C4V_Type Type);
|
||||
template<typename T> class Nillable;
|
||||
|
||||
union C4V_Data
|
||||
{
|
||||
|
@ -70,17 +72,29 @@ public:
|
|||
|
||||
explicit C4Value(bool data): NextRef(NULL), Type(C4V_Bool)
|
||||
{ Data.Int = data; }
|
||||
explicit C4Value(int32_t data): NextRef(NULL), Type(C4V_Int)
|
||||
explicit C4Value(int data): NextRef(NULL), Type(C4V_Int)
|
||||
{ Data.Int = data; }
|
||||
explicit C4Value(long data): NextRef(NULL), Type(C4V_Int)
|
||||
{ Data.Int = int32_t(data); }
|
||||
explicit C4Value(C4PropListStatic *p);
|
||||
explicit C4Value(C4Def *p);
|
||||
explicit C4Value(C4Object *pObj);
|
||||
explicit C4Value(C4Effect *p);
|
||||
explicit C4Value(C4String *pStr): NextRef(NULL), Type(pStr ? C4V_String : C4V_Nil)
|
||||
{ Data.Str = pStr; AddDataRef(); }
|
||||
explicit C4Value(const char * s): NextRef(NULL), Type(s ? C4V_String : C4V_Nil)
|
||||
{ Data.Str = s ? ::Strings.RegString(s) : NULL; AddDataRef(); }
|
||||
explicit C4Value(const StdStrBuf & s): NextRef(NULL), Type(s.isNull() ? C4V_Nil : C4V_String)
|
||||
{ Data.Str = s.isNull() ? NULL: ::Strings.RegString(s); AddDataRef(); }
|
||||
explicit C4Value(C4ValueArray *pArray): NextRef(NULL), Type(pArray ? C4V_Array : C4V_Nil)
|
||||
{ Data.Array = pArray; AddDataRef(); }
|
||||
explicit C4Value(C4AulFunc * pFn): NextRef(NULL), Type(pFn ? C4V_Function : C4V_Nil)
|
||||
{ Data.Fn = pFn; AddDataRef(); }
|
||||
explicit C4Value(C4PropList *p): NextRef(NULL), Type(p ? C4V_PropList : C4V_Nil)
|
||||
{ Data.PropList = p; AddDataRef(); }
|
||||
C4Value(const Nillable<void> & x): C4Value() {}
|
||||
C4Value(C4ObjectPtr p): C4Value(p.operator C4Object *()) {}
|
||||
template<typename T> C4Value(Nillable<T> v): C4Value(v.IsNil() ? C4Value() : C4Value(v.operator T())) {}
|
||||
|
||||
C4Value& operator = (const C4Value& nValue) { Set(nValue); return *this; }
|
||||
|
||||
|
@ -194,7 +208,7 @@ public:
|
|||
static inline bool IsNullableType(C4V_Type Type)
|
||||
{ return Type == C4V_Int || Type == C4V_Bool; }
|
||||
|
||||
protected:
|
||||
private:
|
||||
// data
|
||||
C4V_Data Data;
|
||||
|
||||
|
@ -204,7 +218,6 @@ protected:
|
|||
// data type
|
||||
C4V_Type Type;
|
||||
|
||||
|
||||
void Set(C4V_Data nData, C4V_Type nType);
|
||||
|
||||
void AddDataRef();
|
||||
|
@ -215,6 +228,9 @@ protected:
|
|||
bool FnCnvEffect() const;
|
||||
void LogDeletedObjectWarning(C4PropList *);
|
||||
|
||||
// Prevent unintended type conversions
|
||||
template<typename T> explicit C4Value(T);
|
||||
|
||||
friend class C4PropList;
|
||||
};
|
||||
|
||||
|
@ -224,12 +240,11 @@ inline C4Value C4VBool(bool b) { return C4Value(b); }
|
|||
C4Value C4VObj(C4Object *pObj);
|
||||
inline C4Value C4VPropList(C4PropList * p) { return C4Value(p); }
|
||||
inline C4Value C4VString(C4String *pStr) { return C4Value(pStr); }
|
||||
inline C4Value C4VString(StdStrBuf strString) { return C4Value(strString); }
|
||||
inline C4Value C4VString(const char *strString) { return C4Value(strString); }
|
||||
inline C4Value C4VArray(C4ValueArray *pArray) { return C4Value(pArray); }
|
||||
inline C4Value C4VFunction(C4AulFunc * pFn) { return C4Value(pFn); }
|
||||
|
||||
C4Value C4VString(StdStrBuf strString);
|
||||
C4Value C4VString(const char *strString);
|
||||
|
||||
extern const C4Value C4VNull;
|
||||
|
||||
// C4Values can contain data structures that have to maintain their
|
||||
|
|
Loading…
Reference in New Issue