00001 #ifndef MediaTable_TableDataSource_h
00002 #define MediaTable_TableDataSource_h
00003
00004 #include <algorithm>
00005
00006 #include "TableDataSourceListener.h"
00007 #include "TableColumn.h"
00008
00009 #include "Core/Array/Arrays.h"
00010 #include "Basis/Quid.h"
00011
00012 namespace Impala {
00013 namespace Application {
00014 namespace MediaTable {
00015
00016 class TableDataSource
00017 {
00018 public:
00019 typedef Impala::Core::Array::Array2dVec3UInt8 Array2dVec3UInt8;
00020
00021 enum MEDIATABLE_TYPE { TYPE_TEXT = 32,
00022 TYPE_FLAG_IMAGE = 4,
00023 TYPE_IMAGE = 5,
00024 TYPE_VIDEO = 6,
00025 TYPE_FLAG_NUMBER = 8,
00026 TYPE_INT = 9,
00027 TYPE_FLAG_FLOAT = 16,
00028 TYPE_DOUBLE = 25,
00029 TYPE_NORMALIZEDVALUE = 26,
00030 TYPE_FLAG_ALL = 63,
00031 };
00032
00033 TableDataSource()
00034 {
00035 mQuid = 0;
00036 mQuidNextObject = 1;
00037 }
00038
00039 virtual int GetTotalRows()
00040 {
00041 return 0;
00042 }
00043
00044
00045 void AddTableDataSourceListener(TableDataSourceListener* l)
00046 {
00047 mTableListeners.push_back(l);
00048 }
00049
00050
00051 void DoUpdateRowsEvent()
00052 {
00053 for (int i=0; i< mTableListeners.size(); i++)
00054 if (mTableListeners[i]->GetListenTableUpdates())
00055 mTableListeners[i]->UpdateRowsEvent();
00056 }
00057
00058 void DoUpdateNumberOfRowsEvent() {
00059 for (int i=0; i< mTableListeners.size(); i++)
00060 if (mTableListeners[i]->GetListenTableUpdates())
00061 mTableListeners[i]->UpdateNumberOfRowsEvent();
00062 }
00063
00064
00065
00066 virtual String
00067 GetTextDataByID(String column, int row)
00068 {
00069 std::ostringstream os;
00070 os << column << ":" << row;
00071 return os.str();
00072 }
00073
00074 virtual Array2dVec3UInt8*
00075 GetImageDataByID(String column, int row)
00076 {
00077 return 0;
00078 }
00079
00080 virtual Array2dVec3UInt8*
00081 GetVideoDataByID(String column, int row)
00082 {
00083 return 0;
00084 }
00085
00086 virtual double
00087 GetNormalizedDataByID(String column, int row)
00088 {
00089 return row / (double) GetTotalRows();
00090 }
00091
00092 virtual int
00093 GetIntDataByID(String column, int row)
00094 {
00095 return 0;
00096 }
00097
00098 virtual double
00099 GetDoubleDataByID(String column, int row)
00100 {
00101 return 0;
00102 }
00103
00104 Array2dVec3UInt8*
00105 GetImageDataByQuid(Quid quid)
00106 {
00107 std::map<std::string, Quid>::iterator it;
00108 if(QuidClass(mQuid) != QuidClass(quid)) return 0;
00109 for (it=mQuids.begin(); it!=mQuids.end(); ++it)
00110 {
00111
00112
00113
00114
00115
00116
00117
00118
00119 if(QuidSet(it->second) != QuidSet(quid)) continue;
00120 if(QuidObject(it->second) != QuidObject(quid)) continue;
00121
00122 return GetImageDataByID(it->first, QuidId(quid));
00123 }
00124 return 0;
00125 }
00126
00127 int GetIDForQuid(Quid quid)
00128 {
00129 return QuidId(quid);
00130 }
00131
00132 Quid GetQuid(String column, int row) {
00133 return mQuid + mQuids[column] + row;
00134 }
00135
00136 void SetQuid(int id) {
00137 mQuid = MakeQuid(id, 0, 0, 0);
00138 }
00139
00140 public:
00141 virtual std::vector<TableColumn*> GetColumns(bool StaticColumns, bool ExtraColumns)
00142 {
00143 std::vector<TableColumn*> columns;
00144 for (std::vector<TableColumn>::iterator it=mColumns.begin(); it!=mColumns.end(); ++it) {
00145 if(StaticColumns & !it->GetIsExtra())
00146 columns.push_back(&(*it));
00147 if(ExtraColumns & it->GetIsExtra())
00148 columns.push_back(&(*it));
00149 }
00150 return columns;
00151 }
00152
00153 inline std::vector<TableColumn*>
00154 GetColumns()
00155 {
00156 GetColumns(true, false);
00157 }
00158
00159 inline std::vector<TableColumn*>
00160 GetExtraColumns()
00161 {
00162 GetColumns(false, true);
00163 }
00164
00165 virtual TableColumn* GetColumn(std::string column) {
00166 for (std::vector<TableColumn>::iterator it=mColumns.begin(); it!=mColumns.end(); ++it)
00167 if(it->GetName() == column)
00168 return (&*it);
00169 return 0;
00170 }
00171
00172 protected:
00173 void AddStaticColumn(String name, int coltype, int width=120, int param=0)
00174 {
00175 TableColumn p(name, coltype, false, width, param);
00176 mColumns.push_back(p);
00177 mQuids[name] = MakeQuid(0, coltype, mQuidNextObject++, 0);
00178 }
00179
00180 void AddColumn(String name, int coltype, int width=120, int param=0)
00181 {
00182 TableColumn p(name, coltype, true, width, param);
00183 mColumns.push_back(p);
00184 mQuids[name] = MakeQuid(0, coltype, mQuidNextObject++, 0);
00185 }
00186
00187 public:
00188 bool MultiThreadImageCacheSupported;
00189
00190 private:
00191
00192 std::vector<TableColumn> mColumns;
00193 std::map<std::string, Quid> mQuids;
00194
00195 std::vector<TableDataSourceListener*> mTableListeners;
00196
00197 Quid mQuid;
00198 int mQuidNextObject;
00199
00200 ILOG_VAR_DEC;
00201 };
00202
00203 ILOG_VAR_INIT(TableDataSource, Application.MediaTable);
00204
00205 }
00206 }
00207 }
00208
00209 #endif // TableDataSource_h