00001 00012 #ifndef VARIABLECONTAINER_H 00013 #define VARIABLECONTAINER_H 00014 00015 #include <vector> 00016 #include <boost/shared_ptr.hpp> 00017 #include "Variable.h" 00018 #include "VariableTableTemplate.h" 00019 //#include "TemplateTable.h" 00020 00021 namespace green 00022 { 00024 typedef size_t ID; 00025 00032 class VariableTableInstance 00033 { 00034 public: 00035 00039 VariableTableInstance(boost::shared_ptr<VariableTableInstance> copy) : 00040 mID(copy->mID), 00041 mVariables(copy->mVariables), 00042 mTemplate(copy->mTemplate) 00043 { 00044 } 00045 00049 VariableTableInstance(Key templ) : 00050 mID(0), 00051 mTemplate(templ) 00052 {} 00053 00058 Key GetTemplate() const { 00059 return mTemplate; 00060 } 00061 00066 void SetTemplate(Key templ) { 00067 mTemplate = templ; 00068 } 00069 00073 virtual void CopyFrom(boost::shared_ptr<VariableTableInstance> copy) 00074 { 00075 CHECK_SHARED(copy); 00076 mID = copy->mID; 00077 mTemplate = copy->mTemplate; 00078 mVariables = copy->mVariables; 00079 } 00080 00082 virtual ~VariableTableInstance() {} 00083 00085 ID GetID() const { 00086 return mID; 00087 } 00088 00090 void SetID(ID newID) { 00091 mID = newID; 00092 } 00093 00097 virtual void AddVariable(Variable::Value value) { 00098 mVariables.push_back(value); 00099 } 00100 00103 size_t GetNumVariables() const { 00104 return mVariables.size(); 00105 } 00106 00112 virtual Variable::Value GetVariable(Key key) const { 00113 if(key > mVariables.size()) 00114 THROW_ERROR("variable does not exist in instance"); 00115 return mVariables[key]; 00116 } 00117 00123 virtual void SetVariable(Key key, Variable::Value value) 00124 { 00125 if(key > mVariables.size()) 00126 THROW_ERROR("variable does not exist in instance"); 00127 mVariables[key] = value; 00128 } 00129 00130 00131 protected: 00133 VariableTableInstance() {} 00134 00135 ID mID; 00136 std::vector<Variable::Value> mVariables; 00137 Key mTemplate; 00138 }; 00139 typedef boost::shared_ptr<VariableTableInstance> VariableTableInstancePtr; 00140 #define VARIABLE_TABLE_INSTANCE_CAST(x) boost::dynamic_pointer_cast<VariableTableInstance>(x) 00141 } 00142 00143 #endif