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

ExManagerId.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (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.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExManagerId.cpp,v 1.12 2002/11/24 11:58:57 data Exp $
00021  *
00022  */
00023 
00024 #include "ExManagerId.h"
00025 
00026 bool ExManagerId::m_flag = false; 
00027 ExManagerId* ExManagerId::m_instance = NULL; 
00028 
00029 ExManagerId* ExManagerId::CreateSingleton(void){
00030 Guard(ExManagerId* ExManagerId::CreateSingleton(void))
00031         if(!m_flag)
00032         {
00033                 m_flag = true; // We are creating the error log now, so set flag to true
00034                 m_instance = new ExManagerId; // Create the error log
00035         }else
00036         {
00037                 std::cout<<"Error singleton already created"<<std::endl;
00038         }
00039         return m_instance; 
00040 UnGuard
00041 }
00042 
00043 ExManagerId::ExManagerId()
00044 {
00045 Guard(ExManagerId::ExManagerId())
00046         m_ExIdCounter=0;
00047 UnGuard
00048 }
00049 
00050 ExManagerId::~ExManagerId()
00051 {
00052 Guard(ExManagerId::~ExManagerId())
00053 UnGuard
00054 }
00055 
00057 
00058 void ExManagerId::Reset(void)
00059 {
00060 Guard(ExManagerId::Reset(void))
00061         m_MapObjectInfo->clear();
00062         delete m_MapObjectInfo;
00063         m_ExIdCounter=0;
00064         Init();
00065 UnGuard
00066 }
00067 
00068 void ExManagerId::Init(void)
00069 {
00070 Guard(ExManagerId::Init(void))
00071         m_MapObjectInfo=new std::map<  ExNihilo::ExId   , ExNihilo::ExObjectInfo , std::less <ExNihilo::ExId  >  >;     
00072 UnGuard
00073 }
00074 
00075 std::string ExManagerId::GetAviableName(std::string Name,std::string Type,int occu)
00076 {
00077 Guard(std::string ExManagerId::GetAviableName(std::string Name,std::string Type,int occu))
00078         if(GetObjectId(Name,Type)==-1)//new name
00079         {
00080                 return Name;
00081         }
00082         
00083         //here code to change name
00084         if(occu>0)
00085         {
00086                 Name.erase(Name.end()-1,Name.end());
00087         }
00088         if(occu>10)
00089         {
00090                 Name.erase(Name.end()-1,Name.end());
00091         }
00092         if(occu>100)
00093         {
00094                 Name.erase(Name.end()-1,Name.end());
00095         }
00096         if(occu>1000)
00097         {
00098                 Name.erase(Name.end()-1,Name.end());
00099         }
00100         if(occu>10000)
00101         {
00102                 Name.erase(Name.end()-1,Name.end());
00103         }
00104         char buffer[255];
00105         memset(buffer,0,255);
00106         sprintf(buffer,"%s%d",Name.data(),occu);
00107 
00108         return GetAviableName(buffer,Type,occu+1);
00109         
00110 UnGuard
00111 }
00112 
00113 ExNihilo::ExId ExManagerId::RecordObject(ExCObject &object)
00114 {
00115 Guard(ExNihilo::ExId ExManagerId::RecordObject(ExCObject &object))
00116         try
00117         {       
00118                 object.SetId(m_ExIdCounter);m_ExIdCounter++;
00119                 std::string name(object.GetType());
00120                 if(name.find(" *")<name.length())
00121                 {
00122                         name.erase(name.find(" *"),name.length()-name.find(" *"));
00123                 }
00124                 object.SetName(GetAviableName(object.GetName(),object.GetType(),0));
00125                 object.SetType(name);
00126                 object.SetFlux(Consol,FluxAction);
00127                 
00128 
00129                 ExNihilo::ExObjectInfo Info;
00130                 Info.m_Id       = object.GetId();
00131                 Info.m_Name     = object.GetName();
00132                 Info.m_Type = object.GetType();
00133                 
00134                 std::pair<ExNihilo::ExId,ExNihilo::ExObjectInfo>  obj;
00135                 obj.first=object.GetId();
00136                 obj.second=Info;
00137                 m_MapObjectInfo->insert(obj);
00138 
00139                 
00140 
00141                 *Consol<<"ExManagerId:: New Id :"<<Info.m_Id<<"  For name:"<<Info.m_Name<<" Type:"<<Info.m_Type<<std::endl;
00142                 return Info.m_Id;
00143         }catch(...)
00144         {
00145                 throw ExCExpRecordObject();
00146         }
00147 UnGuard
00148 }
00149 
00150 ExNihilo::ExId ExManagerId::RecordObject(ExCObject *object)
00151 {
00152 Guard(ExNihilo::ExId ExManagerId::RecordObject(ExCObject *object))
00153         object->SetId(m_ExIdCounter);m_ExIdCounter++;
00154         std::string name(object->GetType());
00155         if(name.find(" *")<name.length())
00156         {
00157                 name.erase(name.find(" *"),name.length()-name.find(" *"));
00158         }
00159         object->SetName(GetAviableName(object->GetName(),object->GetType(),0));
00160         object->SetType(name);
00161 
00162         ExNihilo::ExObjectInfo Info;
00163         Info.m_Id       = object->GetId();
00164         Info.m_Name     = object->GetName();
00165         Info.m_Type = object->GetType();
00166         
00167         std::pair<ExNihilo::ExId,ExNihilo::ExObjectInfo>  obj;
00168         obj.first=object->GetId();
00169         obj.second=Info;
00170         m_MapObjectInfo->insert(obj);
00171 
00172         *Consol<<"ExManagerId:: New Id :"<<Info.m_Id<<"  For name:"<<Info.m_Name<<" Type:"<<Info.m_Type<<std::endl;
00173         return Info.m_Id;
00174 UnGuard
00175 }
00176 
00177 ExNihilo::ExId  ExManagerId::GetObjectId(std::string Name,std::string Type)
00178 {
00179 Guard(ExNihilo::ExId    ExManagerId::GetObjectId(std::string Name,std::string Type))
00180         for(m_ItMapObjectInfo=m_MapObjectInfo->begin();m_ItMapObjectInfo!=m_MapObjectInfo->end();m_ItMapObjectInfo++)
00181         {
00182                 if(Name==m_ItMapObjectInfo->second.m_Name)//||Type==m_ItMapObjectInfo->second.m_Type)
00183                         return  m_ItMapObjectInfo->second.m_Id;
00184         }
00185         return -1;
00186 UnGuard
00187 }
00188 
00189 std::string             ExManagerId::GetObjectName(ExNihilo::ExId id)
00190 {
00191 Guard(std::string               ExManagerId::GetObjectName(ExNihilo::ExId id))
00192         try
00193         {
00194                 return m_MapObjectInfo->find(id)->second.m_Name;        
00195         }
00196         catch(...)
00197         {
00198                 return "NoName";
00199         }
00200 UnGuard
00201 }
00202 
00203 std::string             ExManagerId::GetObjectType(ExNihilo::ExId id)
00204 {
00205 Guard(std::string               ExManagerId::GetObjectType(ExNihilo::ExId id))
00206         try
00207         {
00208                 return m_MapObjectInfo->find(id)->second.m_Type;        
00209         }
00210         catch(...)
00211         {
00212                 return "NoName";
00213         }
00214 UnGuard
00215 }
00216 
00217 void ExManagerId::List(void)
00218 {
00219 Guard(void ExManagerId::List(void))
00220         for(m_ItMapObjectInfo=m_MapObjectInfo->begin();m_ItMapObjectInfo!=m_MapObjectInfo->end();m_ItMapObjectInfo++)
00221         {
00222                 *Consol<<"Id :"<<m_ItMapObjectInfo->second.m_Id<<"  For name:"<<m_ItMapObjectInfo->second.m_Name<<" Type:"<<m_ItMapObjectInfo->second.m_Type<<std::endl;
00223         }       
00224 UnGuard
00225 }
00226 
00227 ExCAction ExManagerId::InputAction(ExCAction Action)
00228 {
00229 Guard(ExCAction ExManagerId::InputAction(ExCAction Action))
00230         switch(Action.m_Action)
00231         {
00232         case ID_LIST:
00233                 List();
00234                 break;
00235         }
00236         if(Action.m_NextAction){return *Action.m_NextAction;}
00237         else{return NOTHING;}
00238 UnGuard
00239 }
00240 
00241 std::string             ExManagerId::GetObjectManagerType(std::string ObjectType)
00242 {
00243 Guard(std::string               ExManagerId::GetObjectManagerType(std::string ObjectType))
00244         //std::cout<<"Type:"<<ObjectType<<std::endl;
00245         try
00246         {
00247                 //Entity manager
00248                 if(strcmpi(ObjectType.data(),"ExCEntity")==0)return "ExManagerEntity";
00249                 //Camera manager
00250                 if(strcmpi(ObjectType.data(),"ExCCamera")==0)return "ExManagerCamera";
00251                 if(strcmpi(ObjectType.data(),"ExCCameraFree")==0)return "ExManagerCamera";
00252                 if(strcmpi(ObjectType.data(),"ExCCameraChase")==0)return "ExManagerCamera";
00253                 if(strcmpi(ObjectType.data(),"ExCCameraFirst")==0)return "ExManagerCamera";
00254                 if(strcmpi(ObjectType.data(),"ExCCameraFlight")==0)return "ExManagerCamera";
00255                 //Model Manager
00256                 if(strcmpi(ObjectType.data(),"ExCModel")==0)return "ExManagerModel";
00257                 if(strcmpi(ObjectType.data(),"ExCModelASC")==0)return "ExManagerModel";
00258                 if(strcmpi(ObjectType.data(),"ExCModelASE")==0)return "ExManagerModel";
00259                 if(strcmpi(ObjectType.data(),"ExCModelEXM")==0)return "ExManagerModel";
00260                 if(strcmpi(ObjectType.data(),"ExCModelMD")==0)return "ExManagerModel";
00261                 if(strcmpi(ObjectType.data(),"ExCModelMD2")==0)return "ExManagerModel";
00262                 if(strcmpi(ObjectType.data(),"ExCModelMD3")==0)return "ExManagerModel";
00263                 if(strcmpi(ObjectType.data(),"ExCModel3DS")==0)return "ExManagerModel";
00264                 if(strcmpi(ObjectType.data(),"ExCModelOBJ")==0)return "ExManagerModel";
00265                 //MEsh Manager
00266                 if(strcmpi(ObjectType.data(),"ExCMesh")==0)return "ExManagerMesh";
00267                 if(strcmpi(ObjectType.data(),"ExCMeshFireEffect")==0)return "ExManagerMesh";
00268                 if(strcmpi(ObjectType.data(),"ExCMeshWaterEffect")==0)return "ExManagerMesh";
00269                 if(strcmpi(ObjectType.data(),"ExCMeshSummonCylenderEffect")==0)return "ExManagerMesh";
00270                 if(strcmpi(ObjectType.data(),"ExCMeshSmogEffect")==0)return "ExManagerMesh";
00271                 if(strcmpi(ObjectType.data(),"ExCMeshWaterDisqueEffect")==0)return "ExManagerMesh";
00272                 if(strcmpi(ObjectType.data(),"ExCMeshLOD3ds")==0)return "ExManagerMesh";
00273                 if(strcmpi(ObjectType.data(),"ExCMeshSauronEffect")==0)return "ExManagerMesh";
00274                 if(strcmpi(ObjectType.data(),"ExCMesh3ds")==0)return "ExManagerMesh";
00275         }
00276         catch(...)
00277         {
00278                 return "Unknow manager";
00279         }
00280 UnGuard
00281 }
00282 
00283 

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