00001 #ifndef MediaTable_WritableTableDataSource_h
00002 #define MediaTable_WritableTableDataSource_h
00003
00004 #include "TableDataSource.h"
00005
00006 namespace Impala {
00007 namespace Application {
00008 namespace MediaTable {
00009
00010 class WritableTableDataSource : public TableDataSource, public TableDataSourceListener
00011 {
00012 public:
00013
00014 WritableTableDataSource() : TableDataSource()
00015 {
00016 Init();
00017 }
00018
00019 ~WritableTableDataSource()
00020 {
00021 ILOG_DEBUG("Destroying WritableTableDataSource @ " << this);
00022 }
00023
00024 int GetTotalRows() {
00025 if (mTotalRows >= 0) return mTotalRows;
00026 std::map<std::string, std::vector<int> >::iterator mIntMapIterator;
00027 std::map<std::string, std::vector<double> >::iterator mDoubleMapIterator;
00028 std::map<std::string, std::vector<std::string> >::iterator mTextMapIterator;
00029 std::map<std::string, std::vector<Array2dVec3UInt8*> >::iterator mImageMapIterator;
00030
00031 uint maxRows = 0;
00032 for(mIntMapIterator = mIntMap.begin(); mIntMapIterator != mIntMap.end(); ++mIntMapIterator )
00033 if(mIntMapIterator->second.size() > maxRows)
00034 maxRows = mIntMapIterator->second.size();
00035 for(mDoubleMapIterator = mDoubleMap.begin(); mDoubleMapIterator != mDoubleMap.end(); ++mDoubleMapIterator )
00036 if(mDoubleMapIterator->second.size() > maxRows)
00037 maxRows = mDoubleMapIterator->second.size();
00038 for(mTextMapIterator = mTextMap.begin(); mTextMapIterator != mTextMap.end(); ++mTextMapIterator )
00039 if(mTextMapIterator->second.size() > maxRows)
00040 maxRows = mTextMapIterator->second.size();
00041 for(mImageMapIterator = mImageMap.begin(); mImageMapIterator != mImageMap.end(); ++mImageMapIterator )
00042 if(mImageMapIterator->second.size() > maxRows)
00043 maxRows = mImageMapIterator->second.size();
00044
00045 return mTotalRows = maxRows;
00046 }
00047
00048
00049 String GetTextDataByID(String column, int row)
00050 {
00051 if(mTextMap.count(column)&& row < mTextMap[column].size())
00052 return mTextMap[column][row];
00053 if(mIntMap.count(column) && row < mIntMap[column].size())
00054 return MakeString(mIntMap[column][row]);
00055 if(mDoubleMap.count(column) && row < mDoubleMap[column].size())
00056 return MakeString(mDoubleMap[column][row]);
00057 return "";
00058 }
00059
00060 int GetIntDataByID(String column, int row)
00061 {
00062 return mIntMap[column][row];
00063 }
00064
00065 double GetDoubleDataByID(String column, int row)
00066 {
00067 return mDoubleMap[column][row];
00068 }
00069
00070
00071 double GetNormalizedDataByID(String column, int row)
00072 {
00073 return GetDoubleDataByID(column, row);
00074 }
00075
00076 Array2dVec3UInt8* GetImageDataByID(String column, int row)
00077 {
00078 return mImageMap[column][row];
00079 }
00080
00081 void AddStaticColumn(String name, int coltype) {
00082 TableDataSource::AddStaticColumn(name, coltype);
00083 }
00084 void AddColumn(String name, int coltype) {
00085 TableDataSource::AddColumn(name, coltype);
00086 }
00087
00088 void AddTextData(String column, String data) {
00089 mTextMap[column].push_back(data);
00090 DoUpdateRowsEvent();
00091 }
00092
00093 void AddImageData(String column, Array2dVec3UInt8* data) {
00094 mImageMap[column].push_back(data);
00095 DoUpdateRowsEvent();
00096 }
00097
00098 void AddIntData(String column, int data) {
00099 mIntMap[column].push_back(data);
00100 DoUpdateRowsEvent();
00101 }
00102
00103 void AddDoubleData(String column, double data) {
00104 mDoubleMap[column].push_back(data);
00105 DoUpdateRowsEvent();
00106 }
00107
00108 private:
00109
00110 void Init()
00111 {
00112 AddTableDataSourceListener(this);
00113 mTotalRows = -1;
00114 }
00115
00116 void UpdateRowsEvent() {
00117 mTotalRows = -1;
00118 }
00119
00120 int mTotalRows;
00121
00122 std::map<std::string, std::vector<int> > mIntMap;
00123 std::map<std::string, std::vector<double> > mDoubleMap;
00124 std::map<std::string, std::vector<std::string> > mTextMap;
00125 std::map<std::string, std::vector<Array2dVec3UInt8*> > mImageMap;
00126
00127 ILOG_VAR_DEC;
00128 };
00129
00130 ILOG_VAR_INIT(WritableTableDataSource, Application.MediaTable);
00131
00132 }
00133 }
00134 }
00135
00136 #endif // WritableTableDataSource_h