src/engine/VariableTableTemplate.h

Go to the documentation of this file.
00001 
00013 #ifndef VARIABLETABLETEMPLATE_H_
00014 #define VARIABLETABLETEMPLATE_H_
00015 
00016 #include <iostream>
00017 #include <string>
00018 #include <vector>
00019 #include <map>
00020 #include <boost/shared_ptr.hpp>
00021 #include "Variable.h"
00022 #include "KeyNameTable.h"
00023 
00024 namespace green
00025 {
00029         class VariableEntry
00030         {
00031         public:
00032                 VariableEntry(Variable::Type type, Variable::Value defaultValue) :
00033                         mType(type), mDefaultValue(defaultValue) {}
00034                 
00035                 VariableEntry() : mType(Variable::INT_VAR), mDefaultValue(0) {}
00036                 Variable::Type mType;
00037                 Variable::Value mDefaultValue;
00038         };
00039         
00044         class InitArgFormat
00045         {
00046                 public:
00047                         InitArgFormat(  Key key, Variable::Type type) :
00048                                 mKey(key),
00049                                                  mType(type)
00050                                                  {}
00051                         Key mKey;                       
00052                         Variable::Type mType;
00053         };
00054         typedef boost::shared_ptr<InitArgFormat> InitArgFormatPtr;
00055         typedef std::vector<InitArgFormat> InitFormat;
00056         typedef boost::shared_ptr<InitFormat> InitFormatPtr;
00057         
00058                 
00066         class VariableTableTemplate : public KeyNameTable<VariableEntry>
00067         {
00068         public:
00069                 
00070                 VariableTableTemplate() :
00071                         KeyNameTable<VariableEntry>(),
00072                         mInitFormat(new InitFormat())
00073                 {}
00074                         
00077                 virtual ~VariableTableTemplate() {}
00078                 
00082                 inline
00083                 InitFormatPtr GetInitFormat() const {
00084                         return mInitFormat;
00085                 }
00086                 
00090                  void SetInitFormat(InitFormatPtr format)
00091                  {
00092                          CHECK_SHARED(format);
00093 /*                       for(size_t i = 0; i < format->size(); i++)
00094                          {
00095                                 if(!this->HasEntry(format->at(i).mKey))
00096                                          THROW_ERROR("argument key is not in table");
00097                          }
00098 */                       mInitFormat = format;
00099                  }
00100                  
00107                 Key AddEntry(const Name& name, Variable::Type type, Variable::Value value)
00108                 {
00109                         VariableEntry f;
00110                         f.mType = type;
00111                         f.mDefaultValue = value;
00112                         return KeyNameTable<VariableEntry>::AddEntry(name, f); 
00113                 }
00114 
00118                 virtual
00119                 void Print(std::ostream& os)
00120                 {
00121                         os << "InitFormat: ";
00122                         for(size_t i = 0; i < mInitFormat->size(); i++) {
00123                                 os << "[Key: " << mInitFormat->at(i).mKey;
00124                                 os << " Type: " << mInitFormat->at(i).mType << "] ";
00125                         }
00126                         os << std::endl;
00127                         for(Key i = 0; i < this->GetNumEntries(); i++)
00128                         {
00129                                 _entryPtr curEntry(this->_getEntry(i));
00130                                 os << " Variable Key: " << i << " Name: " << curEntry->mName;
00131                                 os << " Type: " << curEntry->mValue.mType;
00132                                 os << " Default Value: " << curEntry->mValue.mDefaultValue << std::endl;
00133                         }
00134                                 
00135                 }
00136                         
00137         protected:
00138         
00140                 InitFormatPtr mInitFormat;
00141                   
00142         };
00143         typedef boost::shared_ptr<VariableTableTemplate> VariableTableTemplatePtr;
00144         #define VARIABLE_TABLE_TEMPLATE_CAST(x) boost::dynamic_pointer_cast<VariableTableTemplate>(x)
00145 }
00146 
00147 #endif /*VARIABLETABLETEMPLATE_H_*/

Generated on Fri Apr 27 10:27:38 2007 for Green Engine by  doxygen 1.5.1