emcConfigurationFile.C

Go to the documentation of this file.
00001 #include "emcConfigurationFile.h"
00002 #include <fstream>
00003 #include <cassert>
00004 
00005 emcConfigurationFile::emcConfigurationFile(const char* filename)
00006   : fCurrent(0),fStart(0)
00007 {
00008   fEnd.setToFarFuture();
00009   std::ifstream in(filename);
00010   if (!in) {
00011     fIsValid = false;
00012   }
00013   else {
00014     fContent = "";
00015     char c;
00016     int n = 0;
00017     while ( in.get(c) ) {
00018       fContent += c;
00019       n++;
00020     }
00021     assert(n!=0);
00022     fIsValid = true;
00023   }
00024 }
00025 
00026 bool emcConfigurationFile::IsValid(const PHTimeStamp& cwhen) const
00027 {
00028   PHTimeStamp& when = const_cast<PHTimeStamp&>(cwhen);
00029   return ( fIsValid && when.isInRange(fStart,fEnd) );
00030 }
00031 
00032 bool emcConfigurationFile::GetLine(char* s, int size)
00033 {  
00034   if ( fCurrent >= static_cast<int>(GetSize()) ) { 
00035     s[0] = '\0'; 
00036     return false; 
00037   }
00038 
00039   int i;
00040   int pos = 0;
00041 
00042   for ( i = 0; i < size-1; i++ ) {
00043     pos = i + fCurrent;
00044     if ( pos >= static_cast<int>(GetSize())-1 ) {
00045       s[i] = '\0'; 
00046       fCurrent = pos+1;
00047       return true;
00048     }
00049     else {
00050       s[i] = fContent[pos];
00051       if ( s[i] == '\n' ) { s[i+1] = '\0'; fCurrent = pos+1; return true; }
00052     }
00053   }
00054 
00055   fCurrent = pos + 1;
00056   s[size-1] = '\0';
00057   return true;
00058 }
00059