Skip to content

Instantly share code, notes, and snippets.

@winterdyne
Created December 5, 2011 22:55
Show Gist options
  • Save winterdyne/1435789 to your computer and use it in GitHub Desktop.
Save winterdyne/1435789 to your computer and use it in GitHub Desktop.
DataVariable class
// Wrapper around basic variable types.
class DataVariable
{
public:
enum VariableType // RTTI encoding.
{
UNKNOWN_TYPE, // Dunno What this is, variable exists but isn't set?
UNKNOWN_VARIABLE, // Variable doesn't exist. Used as an error code.
INTEGER_TYPE, // Integer / char / short.
FLOAT_TYPE, // Float
STRING_TYPE, // Text. 0 terminated.
BLOB_TYPE, // Binary Object. May contain 0's!
COLOUR_TYPE // Colour Type.
};
protected:
VariableType m_Type;
public:
DataVariable(VariableType type = UNKNOWN_TYPE) { m_Type = type };
virtual ~DataVariable() { };
virtual VariableType getType() { return m_Type; };
virtual DataVariable& operator=(const DataVariable& rhs)= 0;
};
This shows the base class for datavariables. These are held in a map by name in various dataobjects for the purpose of deriving information from scripted structures.
I was asking about the failure mechanism for stupid assignments in derived classes. Some types can be allowed to be inter-assigned,
for example float and integer (and possibly 'sensible' strings). LUA represents all numbers as double, so it's more likely to be the float converted to int than the other way aroudn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment