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  

ExCFile2.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 
00021  *
00022  */
00023  
00024 #include "ExCFile2.h"
00025 
00026 
00027 ExCFile2::ExCFile2()
00028 {
00029         
00030 }
00031 
00032 ExCFile2::~ExCFile2()
00033 {
00034 }
00035 
00036 tFileInfo ExCFile2::LoadFile(std::string FileName)
00037 {
00038         char                            ch;
00039         int                                     RetVal;
00040         FILE                            *MyFile;
00041         std::string                     StBuffer;
00042 
00043         m_Info.m_NumberElement=0; 
00044         m_Info.m_FileName=FileName;
00045         MyFile=fopen (FileName.data(),"r");
00046         if(!MyFile)
00047         { 
00048                 m_Info.m_NumberElement=-1;
00049                 return m_Info;
00050         }
00051         
00052         //-------------------------------
00053         //Reading file type
00054         //-------------------------------
00055         fseek(MyFile,0,SEEK_SET);
00056         do
00057         {
00058                 RetVal=fread(&ch,sizeof(char),1,MyFile);
00059         }while(ch!='#');
00060         do
00061         {
00062                 RetVal=fread(&ch,sizeof(char),1,MyFile);
00063                 StBuffer=StBuffer+ch;   
00064         }while(ch!='#');
00065         StBuffer.erase(StBuffer.end()-1,StBuffer.end());
00066         m_Info.m_FileType=StBuffer;
00067         //-------------------------------
00068         //Reading data
00069         //-------------------------------
00070         while(!feof(MyFile))
00071         {
00072                 StBuffer.erase(StBuffer.begin(),StBuffer.end());
00073                 do
00074                 {
00075                         RetVal=fread(&ch,sizeof(char),1,MyFile);
00076                         if(ch!='\n')StBuffer=StBuffer+ch;
00077                 }while(ch!='#');
00078                 StBuffer.erase(StBuffer.end()-1,StBuffer.end());
00079                 m_VecElement.push_back(StBuffer);
00080                 m_Info.m_NumberElement++;
00081         }
00082         fclose(MyFile);
00083           
00084         std::cout<<"File Name :"<<m_Info.m_FileName<<std::endl;
00085         std::cout<<"File Type :"<<m_Info.m_FileType<<std::endl;
00086         std::cout<<"Numb elem :"<<m_Info.m_NumberElement<<std::endl;
00087 
00088         return m_Info; 
00089 }
00090 
00091 float ExCFile2::GetElementFloatAt(int position)
00092 {
00093 Guard(float ExCFile2::GetElementFloatAt(int position))
00094         try
00095         {       
00096                 return atof(m_VecElement.at(position).data());
00097         }catch(...)
00098         {
00099                 return 0;
00100         }
00101 UnGuard
00102 }
00103 
00104 std::string ExCFile2::GetElementStringAt(int position)
00105 {
00106 Guard(std::string ExCFile2::GetElementStringAt(int position))
00107         try
00108         {       
00109                 return m_VecElement.at(position);
00110         }catch(...)
00111         {
00112                 return "NULL";
00113         }
00114 UnGuard
00115 }
00116 
00117 int ExCFile2::GetElementIntAt(int position)
00118 {
00119 Guard(int ExCFile2::GetElementIntAt(int position))
00120         try
00121         {       
00122                 return atoi(m_VecElement.at(position).data());
00123         }catch(...)
00124         {
00125                 return 0;
00126         }
00127 UnGuard
00128 }

Généré le Tue Dec 10 18:18:08 2002 pour ExNihilo par doxygen1.3-rc1