00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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 }