tStatFile Class Reference

#include <tStatFile.h>

Collaboration diagram for tStatFile:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 tStatFile (tString name, tList< tStatEntry > *inList)
void read ()
void write ()
 ~tStatFile ()

Private Member Functions

void open ()
void flushWrites ()
void close ()

Private Attributes

tList< tStatEntry > * theList
tString fileName
int betweenWrites
tList< tStatEntrybuffer
std::fstream myFileD


Detailed Description

Definition at line 36 of file tStatFile.h.


Constructor & Destructor Documentation

tStatFile::tStatFile ( tString  name,
tList< tStatEntry > *  inList 
)

Definition at line 32 of file tStatFile.cpp.

References betweenWrites, fileName, and theList.

00033 {
00034     fileName = name << ".txt";
00035     betweenWrites = 0;
00036 
00037     theList = inList;
00038 }

tStatFile::~tStatFile (  ) 

Definition at line 148 of file tStatFile.cpp.

References close(), and flushWrites().

00149 {
00150     //  std::cout << fileName << ": deconstruction!\n";
00151     //necessary!
00152     flushWrites();
00153     close();
00154 }

Here is the call graph for this function:


Member Function Documentation

void tStatFile::read (  ) 

Definition at line 40 of file tStatFile.cpp.

References tList< T, MALLOC, REFERENCE >::Add(), tStatEntry::id, myFileD, open(), tString::ReadLine(), REAL, and theList.

Referenced by gStatList::gStatList().

00041 {
00042     if (!myFileD.is_open())
00043     {
00044         open();
00045     }
00046 
00047     while (myFileD.good() && !myFileD.eof())
00048     {
00049         //              std::cout << "file " << fileName << ": reading line\n";
00050         REAL t1;
00051         tString t2;
00052 
00053         myFileD >> t1;
00054         t2.ReadLine(myFileD);
00055 
00056         //              std::cout << "file " << fileName << ": " << t1 << "-" << t2 << ".\n";
00057 
00058         if (t2 != "")
00059         {
00060             tStatEntry *newone = new tStatEntry(t2, t1);
00061             theList->Add(newone, newone->id);
00062             //                  delete newone; should this be here?
00063         }
00064     }
00065 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tStatFile::write (  ) 

Definition at line 67 of file tStatFile.cpp.

References betweenWrites, and flushWrites().

Referenced by gStatList::output().

00068 {
00069     betweenWrites++;
00070 
00071     if (betweenWrites == 20)
00072     {
00073         flushWrites();
00074         betweenWrites = 0;
00075     }
00076 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tStatFile::open (  )  [private]

Definition at line 78 of file tStatFile.cpp.

References fileName, myFileD, tPath::Open(), and tDirectories::Var().

Referenced by read().

00079 {
00080     bool open = tDirectories::Var().Open(myFileD, fileName);
00081     if (!open)
00082     {
00083         std::ofstream t;
00084         tDirectories::Var().Open(t, fileName);
00085         t << std::flush;
00086         t.close();
00087         tDirectories::Var().Open(myFileD, fileName);
00088     }
00089 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tStatFile::flushWrites (  )  [private]

Definition at line 91 of file tStatFile.cpp.

References c, tString::Len(), GrowingArrayBase::Len(), myFileD, pos, tString::ReadLine(), REAL, tString::SetPos(), and theList.

Referenced by write(), and ~tStatFile().

00092 {
00093     for (int c = theList->Len() - 1; c >= 0; c--)
00094     {
00095         if ((*theList)[c]->toWrite == true)
00096         {
00097             //                  std::cout << "file " << fileName << ": un-buffering " << (*theList)[c]->getName() << " (" << c << ")" << std::endl;
00098 
00099             myFileD.clear();
00100             myFileD.seekg(0, std::ios::beg);
00101             //read thru each line in while loop !eof until the line matching the name is found or the end of file is hit
00102             //update the line or add the new one at the end. sorting can wait
00103             //fixed spacing for values important otherwise writing in place... tricky
00104 
00105             tString out;
00106             out << (*theList)[c]->getValue();
00107             out.SetPos(9, true);
00108             out << " " << (*theList)[c]->getName() << "\n";
00109 
00110             int found = 0;
00111             REAL t1;
00112             tString t2;
00113             while (!myFileD.eof())
00114             {
00115                 myFileD >> t1;
00116                 t2.ReadLine(myFileD);
00117                 if (t2 == (*theList)[c]->getName())
00118                 {
00119                     found = 1;
00120                     int pos = myFileD.tellg();
00121                     pos = pos - t2.Len() - 9;
00122                     myFileD.clear(); //in case last line?
00123                     myFileD.seekg(pos, std::ios::beg);
00124                     myFileD << out;
00125                 }
00126             }
00127 
00128             if (found == 0)
00129             {
00130                 myFileD.clear();
00131                 myFileD << out;
00132             }
00133             (*theList)[c]->toWrite = false;
00134         }
00135     }
00136 
00137     myFileD.flush();
00138 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tStatFile::close (  )  [private]

Definition at line 140 of file tStatFile.cpp.

References myFileD.

Referenced by ~tStatFile().

00141 {
00142     if (myFileD.is_open())
00143     {
00144         myFileD.close();
00145     }
00146 }

Here is the caller graph for this function:


Member Data Documentation

tList<tStatEntry>* tStatFile::theList [private]

Definition at line 48 of file tStatFile.h.

Referenced by flushWrites(), read(), and tStatFile().

tString tStatFile::fileName [private]

Definition at line 49 of file tStatFile.h.

Referenced by open(), and tStatFile().

int tStatFile::betweenWrites [private]

Definition at line 50 of file tStatFile.h.

Referenced by tStatFile(), and write().

tList<tStatEntry> tStatFile::buffer [private]

Definition at line 52 of file tStatFile.h.

std::fstream tStatFile::myFileD [private]

Definition at line 55 of file tStatFile.h.

Referenced by close(), flushWrites(), open(), and read().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:59:17 2008 for Armagetron Advanced by  doxygen 1.5.4