IndexedTuple.h
Go to the documentation of this file.
00001 #ifndef IndexedTuple_H
00002 #define IndexedTuple_H
00003 
00004 #include <vector>
00005 #include <stdexcept>
00006 
00007 
00008 using namespace std;
00009 using namespace momdp;
00010 namespace momdp 
00011 {
00012 template <typename T>
00013 class IndexedTuple
00014 {
00015 private:
00016         vector<T> tupleTable;
00017 
00018 public:
00019         IndexedTuple(void)
00020         {
00021         }
00022         virtual ~IndexedTuple(void)
00023         {
00024         }
00025 
00026         T& set(size_t index) 
00027         {
00028                 if(index < 0)
00029                 {
00030                         throw runtime_error("bug, index < 0 ");
00031                 }
00032                 if(index >= tupleTable.size())
00033                 {
00034                         // expand the table
00035                         tupleTable.resize(index+1);
00036                 }
00037                 return tupleTable[index];
00038         }
00039         const T& get(size_t index) 
00040         {
00041                 if(index < 0)
00042                 {
00043                         throw runtime_error("bug, index < 0 ");
00044                 }
00045                 if(index >= tupleTable.size())
00046                 {
00047                         // expand the table
00048                         throw runtime_error("bug, index > size ");
00049                 }
00050 
00051                 return tupleTable[index];
00052         }
00053 
00054 
00055 };
00056 
00057 }
00058 
00059 #endif
00060 


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29