Page principale   Liste des namespaces   Hiérarchie des classes   Liste par ordre alphabétique   Liste des composants   Liste des fichiers   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.6 2002/08/01 18:45:58 data Exp $
00021  *
00022  */
00023 
00024 #include "ExManagerId.h"
00025 
00026 ExManagerId::ExManagerId()
00027 {
00028 Guard(ExManagerId::ExManagerId())
00029         m_ExIdCounter=0;
00030 UnGuard
00031 }
00032 
00033 ExManagerId::~ExManagerId()
00034 {
00035 Guard(ExManagerId::~ExManagerId())
00036 UnGuard
00037 }
00038 
00040 
00041 void ExManagerId::Reset(void)
00042 {
00043 Guard(ExManagerId::Reset(void))
00044         m_VecObject.clear();    
00045 UnGuard
00046 }
00047 
00048 char * ExManagerId::GetAviableName(const char *Name,int occu)
00049 {
00050 Guard(char * ExManagerId::GetAviableName(const char *Name,int occu))
00051         char *NameB;
00052         NameB=new char[strlen(Name)];
00053         sprintf(NameB,"%s",Name);
00054 
00055         if(GetObjectIdByName(NameB)==-1)//new name
00056         {
00057                 return NameB;
00058         }else
00059         {
00060                 //here code to change name
00061                 std::string newname(NameB);
00062                 if(occu>0)
00063                 {
00064                         newname.erase(newname.end()-1,newname.end());
00065                 }
00066                 if(occu>10)
00067                 {
00068                         newname.erase(newname.end()-1,newname.end());
00069                 }
00070                 if(occu>100)
00071                 {
00072                         newname.erase(newname.end()-1,newname.end());
00073                 }
00074                 if(occu>1000)
00075                 {
00076                         newname.erase(newname.end()-1,newname.end());
00077                 }
00078                 if(occu>10000)
00079                 {
00080                         newname.erase(newname.end()-1,newname.end());
00081                 }
00082                 char buffer[255];
00083                 memset(buffer,0,255);
00084                 sprintf(buffer,"%s%d",newname.data(),occu);
00085 
00086                 return GetAviableName(buffer,occu+1);
00087         }
00088 UnGuard
00089 }
00090 
00091 IdName ExManagerId::GetNewIdName(char * Name)
00092 {
00093 Guard(IdName ExManagerId::GetNewIdName(char * Name));
00094         IdName idname;
00095         idname.first=m_ExIdCounter;
00096         idname.second=GetAviableName(Name,0);
00097         m_ExIdCounter++;
00098         //char buffer[255];
00099         //sprintf(buffer,"New Id :%ld For:%s",idname.first,idname.second);
00100         //WriteToConsol(buffer);
00101         m_VecObject.push_back(idname);
00102         return idname;
00103 UnGuard
00104 }
00105 
00106 ExId ExManagerId::GetObjectIdByName(char * Name)
00107 {
00108 Guard(ExId ExManagerId::GetObjectIdByName(char * Name))
00109         for(m_ItVecObject=m_VecObject.begin();m_ItVecObject!=m_VecObject.end();m_ItVecObject++)
00110         {
00111                 if(strcmp(m_ItVecObject->second,Name)==0)
00112                 {
00113                         return m_ItVecObject->first;
00114                 }
00115         }
00116         return -1;
00117 UnGuard
00118 }
00119 
00120 char * ExManagerId::GetObjectNameById(ExId Id)
00121 {
00122 Guard(char * ExManagerId::GetObjectNameById(ExId Id))
00123         for(m_ItVecObject=m_VecObject.begin();m_ItVecObject!=m_VecObject.end();m_ItVecObject++)
00124         {
00125                 if(m_ItVecObject->first==Id)
00126                 {
00127                         return m_ItVecObject->second;
00128                 }
00129         }
00130         return "NOTHING";
00131 UnGuard
00132 }
00133 
00134 bool ExManagerId::isNameAviable(char * Name)
00135 {
00136 Guard(bool ExManagerId::isNameAviable(char * Name))
00137         for(m_ItVecObject=m_VecObject.begin();m_ItVecObject!=m_VecObject.end();m_ItVecObject++)
00138         {
00139                 if(strcmp(m_ItVecObject->second,Name)==0)
00140                 {
00141                         return false;
00142                 }
00143         }
00144         return true;
00145 UnGuard
00146 }
00147 
00148 bool ExManagerId::RemoveIdName(char * Name)
00149 {
00150 Guard(bool ExManagerId::RemoveIdName(char * Name))
00151         for(m_ItVecObject=m_VecObject.begin();m_ItVecObject!=m_VecObject.end();m_ItVecObject++)
00152         {
00153                 if(strcmp(m_ItVecObject->second,Name)==0)
00154                 {
00155                         m_VecObject.erase(m_ItVecObject);
00156                         return true;
00157                 }
00158         }
00159         return false;
00160 UnGuard
00161 }
00162 
00163 bool ExManagerId::RemoveIdName(ExId Id)
00164 {
00165 Guard(bool ExManagerId::RemoveIdName(ExId Id))
00166         for(m_ItVecObject=m_VecObject.begin();m_ItVecObject!=m_VecObject.end();m_ItVecObject++)
00167         {
00168                 if(m_ItVecObject->first==Id)
00169                 {
00170                         m_VecObject.erase(m_ItVecObject);
00171                         return true;
00172                 }
00173         }
00174         return false;
00175 UnGuard
00176 }
00177 
00178 bool ExManagerId::RecordIdName(ExId Id,char * Name)
00179 {
00180 Guard(bool ExManagerId::RecordIdName(ExId Id,char * Name));
00181         IdName idname;
00182         idname.first=Id;
00183         idname.second=GetAviableName(Name,0);
00184         m_ExIdCounter++;
00185         *Consol<<"New Id :"<<idname.first<<"  For:"<<idname.second<<std::endl;
00186         m_VecObject.push_back(idname);
00187         return true;
00188 UnGuard
00189 }

Généré le Tue Aug 6 20:25:29 2002 pour ExNihilo par doxygen1.2.17