7 #ifndef CAFU_TYPESYS_VARIABLES_HPP_INCLUDED
8 #define CAFU_TYPESYS_VARIABLES_HPP_INCLUDED
10 #include "Templates/Array.hpp"
11 #include "Math3D/Vector2.hpp"
12 #include "Math3D/Vector3.hpp"
13 #include "Math3D/BoundingBox.hpp"
15 #if defined(_WIN32) && _MSC_VER<1600
97 namespace Network {
class InStreamT; }
98 namespace Network {
class OutStreamT; }
117 VarBaseT(
const char* Name,
const char* Flags[])
118 : m_Name(Name), m_Flags(Flags) { }
120 const char* GetName()
const {
return m_Name; }
122 const char** GetFlags()
const {
return m_Flags; }
123 bool HasFlag(
const char* Flag)
const;
124 const char* GetFlag(
const char* Flag,
unsigned int Nr,
const char* Default=NULL)
const;
148 virtual void accept(
VisitorT& Visitor) = 0;
155 const char** m_Flags;
173 template<
class T>
class VarT :
public VarBaseT
178 VarT(
const char* Name,
const T& Value,
const char* Flags[]=NULL)
179 :
VarBaseT(Name, Flags), m_Value(Value) { }
182 const T&
Get()
const {
return m_Value; }
189 virtual void Set(
const T& v) { m_Value = v; }
231 template<
class T>
class VarArrayT :
public VarBaseT
236 VarArrayT(
const char* Name,
unsigned int InitSize,
const T& InitValue,
const char* Flags[]=NULL);
238 const ArrayT<T>& Get()
const {
return m_Array; }
239 unsigned int Size()
const {
return m_Array.Size(); }
240 void Clear() { m_Array.Clear(); }
241 void Overwrite() { m_Array.Overwrite(); }
242 void PushBack(
const T Element) { m_Array.PushBack(Element); }
244 const T& operator [] (
unsigned int i)
const {
return m_Array[i]; }
245 T& operator [] (
unsigned int i) {
return m_Array[i]; }
247 void Serialize(Network::OutStreamT& Stream)
const ;
250 void accept(VisitorT& Visitor) ;
251 void accept(VisitorConstT& Visitor)
const ;
302 virtual void visit(
const VarT<int>& Var) = 0;
306 virtual void visit(
const VarT<bool>& Var) = 0;
334 bool operator () (
const char* a,
const char* b)
const {
return std::strcmp(a, b) < 0; }
337 typedef std::map<const char*, VarBaseT*, CompareCStr> MapVarBaseT;
350 VarBaseT* Find(
const char* Name)
const
352 const MapVarBaseT::const_iterator It = m_VarsMap.find(Name);
354 return It != m_VarsMap.end() ? It->second : NULL;
361 MapVarBaseT m_VarsMap;
This is the base class for the visitors of VarTs.
Definition: Variables.hpp:266
Like VisitorT, but for const VarTs.
Definition: Variables.hpp:294
void Serialize(Network::OutStreamT &Stream) const
Stores the value of this variable in the given Stream.
Definition: Variables.cpp:50
This class is a simple container for pointers to VarBaseTs.
Definition: Variables.hpp:326
This is a "wrapper" around a normal C++ variable specifically of type ArrayT<T>.
Definition: SetCompVar.hpp:16
void Serialize(Network::OutStreamT &Stream) const
Stores the value of this variable in the given Stream.
Definition: Variables.cpp:211
virtual void Deserialize(Network::InStreamT &Stream)=0
Restores the value of this variable from the given Stream.
virtual void Serialize(Network::OutStreamT &Stream) const =0
Stores the value of this variable in the given Stream.
Definition: Variables.hpp:330
This class is used for reading data from a StateT instance (deserialization).
Definition: State.hpp:207
VarT(const char *Name, const T &Value, const char *Flags[]=NULL)
The constructor.
Definition: Variables.hpp:178
virtual std::string GetExtraMessage() const
Sometimes actions on variables generate extra messages that are relevant to the user.
Definition: Variables.hpp:132
This class is used for writing data into a StateT instance (serialization).
Definition: State.hpp:81
virtual void GetChoices(ArrayT< std::string > &Strings, ArrayT< T > &Values) const
This method returns a list of acceptable input values for this variable, along with a string represen...
Definition: Variables.hpp:197
This is the common base class for the VarT classes.
Definition: Variables.hpp:113
void AddAlias(const char *Alias, VarBaseT *Var)
Adds an alias name for the given variable so that a call to Find() will also find the variable under ...
Definition: Variables.cpp:252
virtual void Set(const T &v)
Sets the value of this variable to the given value v.
Definition: Variables.hpp:189
void Deserialize(Network::InStreamT &Stream)
Restores the value of this variable from the given Stream.
Definition: Variables.cpp:101
void Deserialize(Network::InStreamT &Stream)
Restores the value of this variable from the given Stream.
Definition: Variables.cpp:218
const T & Get() const
Returns the value of this variable.
Definition: Variables.hpp:182
VarArrayT(const char *Name, unsigned int InitSize, const T &InitValue, const char *Flags[]=NULL)
The constructor.
Definition: Variables.cpp:200