00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __EXMANAGEROBJECT_H__
00025 #define __EXMANAGEROBJECT_H__
00026
00027
00028
00029 #include "ExDefine.h"
00030 #include "ExCObject.h"
00031 #include "ExMath.h"
00032 #include "ExManager.h"
00033 #include "ExManagerId.h"
00034 #include "ExNihiloNameSpace.h"
00035
00036
00037
00038 class ErrNotExCObject{};
00039
00040 template <class TypeA>
00041 class ExManagerObject : public ExManager
00042 {
00043 protected:
00044
00045
00046
00047 typename std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > > *m_Map;
00048 typename std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >::iterator m_ItMap;
00049
00050 ExManagerId *ManagerId;
00051 ExNihilo::ExId m_CurrentObjectId;
00052
00053
00054
00055 std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >::iterator GetIterator(ExNihilo::ExId id);
00056 std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >::iterator GetIterator(std::string Name);
00057 public :
00058
00059
00060
00061 ExManagerObject();
00062 ~ExManagerObject();
00063
00064
00065
00066 inline void SetManagerId(ExManagerId *Id){ManagerId = Id;}
00067
00068 void Reset(void);
00069 void Init(void);
00070 void Init(std::string FileName);
00071 void List(void);
00072 void Draw(void){};
00073
00074 bool Add(TypeA object);
00075 bool Add(std::string FileName);
00076 bool Load(std::string FileName);
00077
00078 bool Remove(ExNihilo::ExId id);
00079 bool Remove(std::string Name);
00080 bool RemoveCurrentObject(void);
00081
00082 TypeA * GetObject(ExNihilo::ExId id);
00083 TypeA * GetObject(std::string Name);
00084 TypeA * GetCurrentObject(void);
00085 TypeA * GetFirstObject(void);
00086 TypeA * GetLasstObject(void);
00087 ExNihilo::ExId GetFirstObjectId(void);
00088 ExNihilo::ExId GetLasstObjectId(void);
00089
00090 bool SetCurrentObject(ExNihilo::ExId id);
00091 bool SetCurrentObject(std::string Name);
00092 ExNihilo::ExId NextObject(void);
00093 ExNihilo::ExId PreviousObject(void);
00094
00095 inline unsigned int GetNumberObject(void){return m_Vec->size();}
00096 };
00097
00098
00099
00100 template<class TypeA>
00101 ExManagerObject<TypeA>::ExManagerObject(void)
00102 {
00103 Guard(ExManagerObject<TypeA>::ExManagerObject(void))
00104
00105 UnGuard
00106 }
00107
00108 template<class TypeA>
00109 ExManagerObject<TypeA>::~ExManagerObject(void)
00110 {
00111 Guard(ExManagerObject<TypeA>::~ExManagerObject(void))
00112 UnGuard
00113 }
00114
00115
00116 template<class TypeA>
00117 void ExManagerObject<TypeA>::Reset(void)
00118 {
00119 Guard(void ExManagerObject<TypeA>::Reset(void))
00120 m_CurrentObjectId=-1;
00121 m_Map->clear();
00122 UnGuard
00123 }
00124
00125 template<class TypeA>
00126 void ExManagerObject<TypeA>::Init(void)
00127 {
00128 Guard(void ExManagerObject<TypeA>::Init(void))
00129 m_CurrentObjectId=-1;
00130 m_Map=new std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >;
00131 UnGuard
00132 }
00133
00134 template<class TypeA>
00135 void ExManagerObject<TypeA>::Init(std::string FileName)
00136 {
00137 Guard(void ExManagerObject<TypeA>::Init(std::string FileName))
00138 UnGuard
00139 }
00140
00141 template<class TypeA>
00142 void ExManagerObject<TypeA>::List(void)
00143 {
00144 Guard(void ExManagerObject<TypeA>::List(void))
00145 *Consol<<"---------------List of Object Type :"<<typeid(&m_ItMap->second).name()<<"--------------"<<std::endl;
00146 for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00147 {
00148 *Consol<<" Id:"<<m_ItMap->second.GetId()<<" Name :"<<m_ItMap->second.GetName()<<std::endl;
00149 }
00150 *Consol<<"-----------------------------------------------------------------"<<std::endl;
00151 *Consol<<" Number Total of Object : "<<m_Map->size()<<std::endl;
00152 *Consol<<" Current Object Id : "<<m_CurrentObjectId<<std::endl;
00153 *Consol<<"-----------------------------------------------------------------"<<std::endl;
00154
00155 UnGuard
00156 }
00157
00158 template<class TypeA>
00159 bool ExManagerObject<TypeA>::Add(TypeA object)
00160 {
00161 Guard(bool ExManagerObject<TypeA>::Add(TypeA object))
00162 try
00163 {
00164
00165
00166
00167 std::pair<ExNihilo::ExId,TypeA> obj;
00168 obj.first=ManagerId->RecordObject(object);
00169 obj.second=object;
00170 m_Map->insert(obj);
00171 return true;
00172 }
00173 catch(ExCExpRecordObject)
00174 {
00175 *Consol<<"Managerobject:: Exception record object"<<std::endl;
00176 return false;
00177 }
00178 catch(...)
00179 {
00180 *Consol<<"Managerobject:: Exception add object"<<std::endl;
00181 return false;
00182 }
00183 UnGuard
00184 }
00185
00186 template<class TypeA>
00187 bool ExManagerObject<TypeA>::Load(std::string FileName)
00188 {
00189 Guard(bool ExManagerObject<TypeA>::Load(std::string FileName))
00190 return Add(TypeA(FileName));
00191 UnGuard
00192 }
00193
00194 template<class TypeA>
00195 bool ExManagerObject<TypeA>::Add(std::string FileName)
00196 {
00197 Guard(bool ExManagerObject<TypeA>::Add(std::string FileName))
00198 return Load(FileName);
00199 UnGuard
00200 }
00201
00202 template<class TypeA>
00203 bool ExManagerObject<TypeA>::Remove(ExNihilo::ExId id)
00204 {
00205 Guard(bool ExManagerObject<TypeA>::Remove(ExNihilo::ExId id))
00206 if(0==m_Map->erase(id))return false;
00207 else{if(m_CurrentObjectId==id)m_CurrentObjectId=-1;return true;}
00208 UnGuard
00209 }
00210
00211 template<class TypeA>
00212 bool ExManagerObject<TypeA>::Remove(std::string Name)
00213 {
00214 Guard(bool ExManagerObject<TypeA>::Remove(std::string Name))
00215 return Remove(ManagerId->GetObjectId(Name,typeid(&TypeA)));
00216 UnGuard
00217 }
00218
00219 template<class TypeA>
00220 bool ExManagerObject<TypeA>::RemoveCurrentObject(void)
00221 {
00222 Guard(bool ExManagerObject<TypeA>::RemoveCurrentObject(void))
00223 return Remove(m_CurrentObjectId);
00224 UnGuard
00225 }
00226
00227 template<class TypeA>
00228 TypeA * ExManagerObject<TypeA>::GetObject(ExNihilo::ExId id)
00229 {
00230 Guard(TypeA * ExManagerObject<TypeA>::GetObject(ExNihilo::ExId id))
00231 if(m_Map->find(id)==m_Map->end())return NULL;
00232 return &m_Map->find(id)->second;
00233 UnGuard
00234 }
00235
00236 template<class TypeA>
00237 TypeA * ExManagerObject<TypeA>::GetObject(std::string Name)
00238 {
00239 Guard(TypeA * ExManagerObject<TypeA>::GetObject(std::string Name))
00240 return GetObject(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name()));
00241 UnGuard
00242 }
00243
00244 template<class TypeA>
00245 TypeA * ExManagerObject<TypeA>::GetCurrentObject(void)
00246 {
00247 Guard(TypeA * ExManagerObject<TypeA>::GetCurrentObject(void))
00248 return GetObject(m_CurrentObjectId);
00249 UnGuard
00250 }
00251
00252 template<class TypeA>
00253 typename std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >::iterator ExManagerObject<TypeA>::GetIterator(ExNihilo::ExId id)
00254 {
00255 Guard(... iterator ExManagerObject<TypeA>::GetIterator(ExNihilo::ExId id))
00256 return m_Map->find(id);
00257 UnGuard
00258 }
00259
00260 template<class TypeA>
00261 typename std::map< ExNihilo::ExId , TypeA , std::less <ExNihilo::ExId > >::iterator ExManagerObject<TypeA>::GetIterator(std::string Name)
00262 {
00263 Guard(... iterator ExManagerObject<TypeA>::GetIterator(std::string Name))
00264 return GetIterator(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name()));
00265 UnGuard
00266 }
00267
00268 template<class TypeA>
00269 bool ExManagerObject<TypeA>::SetCurrentObject(ExNihilo::ExId id)
00270 {
00271 Guard(bool ExManagerObject<TypeA>::SetCurrentObject(ExNihilo::ExId id))
00272 if(GetObject(id)!=NULL)m_CurrentObjectId=id;return true;
00273 return false;
00274 UnGuard
00275 }
00276
00277 template<class TypeA>
00278 bool ExManagerObject<TypeA>::SetCurrentObject(std::string Name)
00279 {
00280 Guard(bool ExManagerObject<TypeA>::SetCurrentObject(std::string Name))
00281 return SetCurrentObject(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name()));
00282 UnGuard
00283 }
00284
00285 template<class TypeA>
00286 ExNihilo::ExId ExManagerObject<TypeA>::NextObject(void)
00287 {
00288 Guard(ExNihilo::ExId ExManagerObject<TypeA>::NextObject(void))
00289 if(m_Map->upper_bound(m_CurrentObjectId)==m_Map->end())
00290 {
00291 m_CurrentObjectId=m_Map->begin()->first;
00292 }else
00293 {
00294 m_CurrentObjectId=m_Map->upper_bound(m_CurrentObjectId)->first;
00295 }
00296 return m_CurrentObjectId;
00297 UnGuard
00298 }
00299
00300 template<class TypeA>
00301 ExNihilo::ExId ExManagerObject<TypeA>::PreviousObject(void)
00302 {
00303 Guard(ExNihilo::ExId ExManagerObject<TypeA>::PreviousObject(void))
00304 if(m_Map->begin()->first==m_CurrentObjectId)
00305 {
00306 m_CurrentObjectId=m_Map->rbegin()->first;
00307 }else
00308 {
00309 m_ItMap=m_Map->find(m_CurrentObjectId);
00310 m_ItMap--;
00311 m_CurrentObjectId=m_ItMap->first;
00312 }
00313 return m_CurrentObjectId;
00314 UnGuard
00315 }
00316
00317
00318
00319 #endif //__EXMANAGEROBJECT_H__