Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

ExManagerObject.h

Aller à la documentation de ce fichier.
00001 /************************************************************************/
00002 /* Ex Nihlo Engine by Hermanns Christophe                                                               */
00003 /************************************************************************/
00004 /* This program is free software; you can redistribute it and/or                */
00005 /* modify it under the terms of the GNU General Public License                  */
00006 /* as published by the Free Software Foundation; either version 2               */
00007 /* of the License, or (at your option) any later version.                               */
00008 /*                                                                                                                                              */
00009 /* This program is distributed in the hope that it will be useful,              */
00010 /* but WITHOUT ANY WARRANTY; without even the implied warranty of               */
00011 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                                 */
00012 /*                                                                                                                                              */
00013 /* See the GNU General Public License for more details.                                 */
00014 /*                                                                                                                                              */
00015 /* You should have received a copy of the GNU General Public License    */
00016 /* along with this program; if not, write to the Free Software                  */
00017 /* Foundation, Inc., 59 Temple Place - Suite 330,                                               */
00018 /* Boston, MA  02111-1307, USA.                                                                                 */
00019 /*                                                                                                                                              */
00020 /* If you use a important part of this code please send me a mail               */
00021 /* I just want to see where my code go thks :)                                                  */
00022 /************************************************************************/
00023 
00024 /************************************************************************/
00025 /* Contact                                                              */  
00026 /************************************************************************/
00027 /* ExNihilo Website :www.ploksoftware.org                               */
00028 /*                                                                      */
00029 /* Hermanns Christophe ExNihilo creator and main programmer             */
00030 /*                                                                      */
00031 /* Mail             : Data@ploksoftware.org                                                             */
00032 /* ICQ              : 8030901                                                                                   */
00033 /* MSN Messenger    : Data_7@hotmail.com                                                                */
00034 /*                                                                      */
00035 /*                                                                      */
00036 /************************************************************************/
00037 
00038 /************************************************************************/
00039 /* File Description                                                                                             */
00040 /************************************************************************/
00041 /* File Name   :ExManagerObject.h                                                                               */
00042 /*                                                                                                                                              */
00043 /* Start Date  :03/20/2002                                                                                              */
00044 /*                                                                                                                                              */
00045 /* Last Update :06/20/2003                                              */
00046 /*                                                                                                                                              */
00047 /* File Description :                                                                                                   */
00048 /*                                                                      */
00049 /* For update of this file check : www.ploksoftware.org                 */
00050 /************************************************************************/
00051 
00052 #ifndef __EXMANAGEROBJECT_H__
00053 #define __EXMANAGEROBJECT_H__
00054 //------------------------------------------------------------------------
00055 //Includes
00056 //------------------------------------------------------------------------
00057 #include "ExDefine.h"
00058 #include "ExNihiloNameSpace.h"
00059 #include "ExNihiloExecption.h"
00060 //------------------------------------------------------------------------
00061 #include "Object/ExCObject.h"
00062 //------------------------------------------------------------------------
00063 #include "Math/ExMath.h"
00064 //------------------------------------------------------------------------
00065 #include "Manager/ExManager.h"
00066 #include "Manager/ExManagerId.h"
00067 //------------------------------------------------------------------------
00068 template <class TypeA> 
00069 class ExManagerObject : public ExManager
00070 {
00071 protected:
00072 //------------------------------------------------------------------------
00073 // Variable
00074 //------------------------------------------------------------------------
00075         typename std::map<  ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >                  *m_Map;
00076         typename std::map<  ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >::iterator        m_ItMap;
00077         
00078         ExManagerId                                             *ManagerId;
00079         ExNihilo::ExId                                          m_CurrentObjectId;
00080 //------------------------------------------------------------------------
00081 // Methode
00082 //------------------------------------------------------------------------
00083         //std::map< ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >::iterator GetIterator(ExNihilo::ExId id);
00084         //std::map< ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >::iterator GetIterator(std::string  Name);
00085 public :
00086 //------------------------------------------------------------------------
00087 // Constructor // Destructor
00088 //------------------------------------------------------------------------
00089         ExManagerObject();
00090         ~ExManagerObject();
00091 //------------------------------------------------------------------------
00092 // Methode
00093 //------------------------------------------------------------------------
00094         inline void SetManagerId(ExManagerId *Id){ManagerId     = Id;}
00095 //------------------------------------------------------------------------
00096         void Reset(void);
00097         void Init(void);
00098         void Init(std::string FileName);
00099         void Reload(void);
00100         void List(void);
00101         virtual void Draw(void){};
00102 //------------------------------------------------------------------------
00103         bool Add(TypeA object);
00104         bool Add(std::string FileName);
00105         bool Load(std::string FileName);
00106 //------------------------------------------------------------------------
00107         bool Remove(ExNihilo::ExId id);
00108         bool Remove(std::string  Name);
00109         bool RemoveCurrentObject(void);
00110 //------------------------------------------------------------------------
00111         TypeA * GetObject(ExNihilo::ExId id);
00112         TypeA * GetObject(std::string  Name);
00113         TypeA * GetCurrentObject(void);
00114         TypeA * GetFirstObject(void);
00115         TypeA * GetLastObject(void);
00116         ExNihilo::ExId GetFirstObjectId(void);
00117         ExNihilo::ExId GetLasstObjectId(void);
00118 //------------------------------------------------------------------------
00119         bool SetCurrentObject(ExNihilo::ExId id);
00120         bool SetCurrentObject(std::string  Name);
00121         ExNihilo::ExId  NextObject(void);
00122         ExNihilo::ExId  PreviousObject(void);
00123 //------------------------------------------------------------------------
00124         inline unsigned int GetNumberObject(void){return m_Map->size();}
00125 };
00126 //------------------------------------------------------------------------
00127 // Constructor // Destructor
00128 //------------------------------------------------------------------------
00129 template<class TypeA>
00130 ExManagerObject<TypeA>::ExManagerObject(void)
00131 {
00132 Guard(ExManagerObject<TypeA>::ExManagerObject(void))
00133 
00134 UnGuard
00135 }
00136 
00137 template<class TypeA>
00138 ExManagerObject<TypeA>::~ExManagerObject(void)
00139 {
00140 Guard(ExManagerObject<TypeA>::~ExManagerObject(void))
00141 UnGuard
00142 }
00143 
00144 //------------------------------------------------------------------------
00145 template<class TypeA>
00146 void  ExManagerObject<TypeA>::Reset(void)
00147 {
00148 Guard(void  ExManagerObject<TypeA>::Reset(void))
00149         m_CurrentObjectId=-1;
00150         m_Map->clear();
00151 UnGuard
00152 }
00153 
00154 template<class TypeA>
00155 void  ExManagerObject<TypeA>::Init(void)
00156 {
00157 Guard(void  ExManagerObject<TypeA>::Init(void))
00158         m_CurrentObjectId=-1;
00159         m_Map=new std::map< ExNihilo::ExId  , TypeA , std::less <ExNihilo::ExId  >  >;
00160 UnGuard
00161 }
00162 
00163 template<class TypeA>
00164 void  ExManagerObject<TypeA>::Init(std::string FileName)
00165 {
00166 Guard(void  ExManagerObject<TypeA>::Init(std::string FileName))
00167 UnGuard
00168 }
00169 
00170 template<class TypeA>
00171 void  ExManagerObject<TypeA>::Reload(void)
00172 {
00173 Guard(void  ExManagerObject<TypeA>::Reload(void))
00174 UnGuard
00175 }
00176 
00177 
00178 template<class TypeA>
00179 void  ExManagerObject<TypeA>::List(void)
00180 {
00181 Guard(void  ExManagerObject<TypeA>::List(void))
00182         *Consol<<"---------------List of Object Type :"<<typeid(&m_ItMap->second).name()<<"--------------"<<std::endl;
00183         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00184         {
00185                 *Consol<<" Id:"<<m_ItMap->second.GetId()<<" Name :"<<m_ItMap->second.GetName()<<std::endl;
00186         }       
00187         *Consol<<"-----------------------------------------------------------------"<<std::endl;
00188         *Consol<<" Number Total of Object : "<<m_Map->size()<<std::endl;
00189         *Consol<<" Current Object Id : "<<m_CurrentObjectId<<std::endl;
00190         *Consol<<"-----------------------------------------------------------------"<<std::endl;
00191 
00192 UnGuard
00193 }
00194 //----------------------------------------------------------------------------------
00195 template<class TypeA>
00196 bool  ExManagerObject<TypeA>::Add(TypeA object)
00197 {
00198 Guard(bool  ExManagerObject<TypeA>::Add(TypeA object))
00199         try
00200         {
00201                 //Ask ManagerId for Aviable Id and Avialbe name
00202                 //object.SetIdName(ManagerId->GetNewIdName(object.GetName()));
00203                 
00204                 std::pair<ExNihilo::ExId,TypeA>  obj;
00205                 obj.first=ManagerId->RecordObject(object);
00206                 obj.second=object;
00207                 m_Map->insert(obj);
00208                 return true;
00209         }
00210         catch(ExCExpRecordObject)
00211         {
00212                 *Consol<<"ExManagerObject:: Exception record object"<<std::endl;
00213                 std::cout<<"ExManagerObject:: Exception record object"<<std::endl;
00214                 return false;
00215         }
00216         catch(...)
00217         {
00218                 *Consol<<"ExManagerObject:: Exception add object"<<std::endl;
00219                 std::cout<<"ExManagerObject:: Exception add object"<<std::endl;
00220                 return false;
00221         }
00222 UnGuard
00223 }
00224 
00225 template<class TypeA>
00226 bool  ExManagerObject<TypeA>::Load(std::string FileName)
00227 {
00228 Guard(bool  ExManagerObject<TypeA>::Load(std::string FileName))
00229         return  Add(TypeA(FileName));
00230 UnGuard
00231 }
00232 
00233 template<class TypeA>
00234 bool  ExManagerObject<TypeA>::Add(std::string FileName)
00235 {
00236 Guard(bool  ExManagerObject<TypeA>::Add(std::string FileName))
00237         return Load(FileName);          
00238 UnGuard
00239 }
00240 //----------------------------------------------------------------------------------
00241 template<class TypeA>
00242 bool  ExManagerObject<TypeA>::Remove(ExNihilo::ExId id)
00243 {
00244 Guard(bool  ExManagerObject<TypeA>::Remove(ExNihilo::ExId id))
00245         if(0==m_Map->erase(id))return false;
00246         else{if(m_CurrentObjectId==id)m_CurrentObjectId=-1;return true;}
00247 UnGuard
00248 }
00249 
00250 template<class TypeA>
00251 bool  ExManagerObject<TypeA>::Remove(std::string  Name)
00252 {
00253 Guard(bool  ExManagerObject<TypeA>::Remove(std::string  Name))
00254         return  Remove(ManagerId->GetObjectId(Name,typeid(&TypeA)));
00255 UnGuard
00256 }
00257 
00258 template<class TypeA>
00259 bool  ExManagerObject<TypeA>::RemoveCurrentObject(void)
00260 {
00261 Guard(bool  ExManagerObject<TypeA>::RemoveCurrentObject(void))
00262         return  Remove(m_CurrentObjectId);
00263 UnGuard
00264 }
00265 //----------------------------------------------------------------------------------
00266 template<class TypeA>
00267 TypeA *  ExManagerObject<TypeA>::GetObject(ExNihilo::ExId id)
00268 {
00269 Guard(TypeA *  ExManagerObject<TypeA>::GetObject(ExNihilo::ExId id))
00270         if(m_Map->find(id)==m_Map->end())return NULL;
00271         return &m_Map->find(id)->second;
00272 UnGuard
00273 }
00274 
00275 template<class TypeA>
00276 TypeA *  ExManagerObject<TypeA>::GetObject(std::string  Name)
00277 {
00278 Guard(TypeA *  ExManagerObject<TypeA>::GetObject(std::string  Name))
00279         return GetObject(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name())); 
00280 UnGuard
00281 }
00282 
00283 template<class TypeA>
00284 TypeA *  ExManagerObject<TypeA>::GetCurrentObject(void)
00285 {
00286 Guard(TypeA *  ExManagerObject<TypeA>::GetCurrentObject(void))
00287         return GetObject(m_CurrentObjectId);    
00288 UnGuard
00289 }
00290 
00291 template<class TypeA>
00292 TypeA *  ExManagerObject<TypeA>::GetLastObject(void)
00293 {
00294 Guard(TypeA *  ExManagerObject<TypeA>::GetLastObject(void))
00295         m_ItMap=m_Map->end();
00296         m_ItMap--;
00297         return GetObject(m_ItMap->second.GetId());      
00298 UnGuard
00299 }
00300 //----------------------------------------------------------------------------------
00301 /*template<class TypeA>
00302 typename std::map< ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >::iterator ExManagerObject<TypeA>::GetIterator(ExNihilo::ExId id)
00303 {
00304 Guard(... iterator ExManagerObject<TypeA>::GetIterator(ExNihilo::ExId id))
00305         return m_Map->find(id);
00306 UnGuard
00307 }
00308    
00309 template<class TypeA> 
00310 typename std::map< ExNihilo::ExId   , TypeA , std::less <ExNihilo::ExId  >  >::iterator ExManagerObject<TypeA>::GetIterator(std::string  Name)
00311 {
00312 Guard(... iterator ExManagerObject<TypeA>::GetIterator(std::string  Name))
00313         return GetIterator(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name()));       
00314 UnGuard
00315 }        */
00316 //----------------------------------------------------------------------------------
00317 template<class TypeA>
00318 bool  ExManagerObject<TypeA>::SetCurrentObject(ExNihilo::ExId id)
00319 {
00320 Guard(bool  ExManagerObject<TypeA>::SetCurrentObject(ExNihilo::ExId id))
00321         if(GetObject(id)!=NULL)m_CurrentObjectId=id;return true;
00322         return false;
00323 UnGuard
00324 }
00325 
00326 template<class TypeA>
00327 bool  ExManagerObject<TypeA>::SetCurrentObject(std::string  Name)
00328 {
00329 Guard(bool  ExManagerObject<TypeA>::SetCurrentObject(std::string  Name))
00330         return SetCurrentObject(ManagerId->GetObjectId(Name,typeid(&m_ItMap->second).name()));
00331 UnGuard
00332 }
00333 
00334 template<class TypeA>
00335 ExNihilo::ExId   ExManagerObject<TypeA>::NextObject(void)
00336 {
00337 Guard(ExNihilo::ExId   ExManagerObject<TypeA>::NextObject(void))
00338         if(m_Map->upper_bound(m_CurrentObjectId)==m_Map->end())
00339         {
00340                 m_CurrentObjectId=m_Map->begin()->first;
00341         }else
00342         {
00343                 m_CurrentObjectId=m_Map->upper_bound(m_CurrentObjectId)->first;
00344         }
00345         return m_CurrentObjectId;
00346 UnGuard
00347 }
00348 
00349 template<class TypeA>
00350 ExNihilo::ExId   ExManagerObject<TypeA>::PreviousObject(void)
00351 {
00352 Guard(ExNihilo::ExId   ExManagerObject<TypeA>::PreviousObject(void))
00353         if(m_Map->begin()->first==m_CurrentObjectId)
00354         {
00355                 m_CurrentObjectId=m_Map->rbegin()->first;
00356         }else
00357         {
00358                 m_ItMap=m_Map->find(m_CurrentObjectId);
00359                 m_ItMap--;
00360                 m_CurrentObjectId=m_ItMap->first;
00361         }
00362         return m_CurrentObjectId;
00363 UnGuard
00364 }
00365 
00366 //----------------------------------------------------------------------------------
00367 
00368 #endif //__EXMANAGEROBJECT_H__

Généré le Tue Oct 28 12:43:37 2003 pour ExNihilo par doxygen 1.3.4