[Avida-SVN] r1942 - in development/source: analyze cpu main tools

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Aug 15 13:46:51 PDT 2007


Author: brysonda
Date: 2007-08-15 16:46:50 -0400 (Wed, 15 Aug 2007)
New Revision: 1942

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/cpu/cHardwareManager.cc
   development/source/cpu/cInstSet.cc
   development/source/main/cAvidaConfig.cc
   development/source/main/cEnvironment.cc
   development/source/main/cEventList.cc
   development/source/main/cGenomeUtil.cc
   development/source/main/cPopulation.cc
   development/source/tools/cHelpManager.cc
   development/source/tools/cInitFile.cc
   development/source/tools/cInitFile.h
Log:
Rework cInitFile, folding in all common actions into the constructor(s).   Extended functionality so that files can now be included with #!include <filename>.

Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/analyze/cAnalyze.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -142,7 +142,7 @@
   m_ctx.SetAnalyzeMode();
   
   cInitFile analyze_file(filename);
-  if (!analyze_file.IsOpen()) {
+  if (!analyze_file.WasOpened()) {
     cerr << "Warning: Cannot load file: \"" << filename << "\"." << endl
     << "...creating it..." << endl;
     ofstream fp(filename);
@@ -158,10 +158,6 @@
     //if (exit_on_error) exit(1);
   }
   else {
-    analyze_file.Load();
-    analyze_file.Compress();
-    analyze_file.Close();
-    
     LoadCommandList(analyze_file, command_list);
     ProcessCommands(command_list);
   }
@@ -209,13 +205,10 @@
   cout << "Loading: " << filename << '\n';
   
   cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
+  if (!input_file.WasOpened()) {
     cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
     if (exit_on_error) exit(1);
   }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
   
   // Setup the genome...
   
@@ -251,13 +244,10 @@
   cout << "Loading: " << filename << '\n';
   
   cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
+  if (!input_file.WasOpened()) {
     cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
     if (exit_on_error) exit(1);
   }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
   
   // Setup the genome...
   
@@ -344,13 +334,10 @@
       << endl;
     
     cInitFile input_file(filename);
-    if (!input_file.IsOpen()) {
+    if (!input_file.WasOpened()) {
       cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
       if (exit_on_error) exit(1);
     }
-    input_file.Load();
-    input_file.Compress();
-    input_file.Close();
     
     // Setup the genome...
     
@@ -955,16 +942,10 @@
   cout << "Loading: " << filename << endl;
   
   cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
+  if (!input_file.WasOpened()) {
     cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
     if (exit_on_error) exit(1);
   }
-  input_file.Load();
-  input_file.ReadHeader();
-  input_file.Compress();
-  if (input_file.Close() == false) {
-    cerr << "Error: Failed to Close file!" << endl;
-  }
   
   const cString filetype = input_file.GetFiletype();
   if (filetype != "population_data" &&  // Depricated
@@ -7581,9 +7562,6 @@
     cString filename = cur_string.PopWord();
     
     cInitFile include_file(filename);
-    include_file.Load();
-    include_file.Compress();
-    include_file.Close();
     
     tList<cAnalyzeCommand> include_list;
     LoadCommandList(include_file, include_list);
@@ -8027,8 +8005,8 @@
 
 void cAnalyze::LoadCommandList(cInitFile& init_file, tList<cAnalyzeCommand>& clist)
 {
-  while (init_file.GetLineNum() < init_file.GetNumLines()) {
-    cString cur_string = init_file.GetNextLine();
+  for (int i = 0; i < init_file.GetNumLines(); i++) {
+    cString cur_string = init_file.GetLine(i);
     cString command = cur_string.PopWord();
     
     cAnalyzeCommand* cur_command;

Modified: development/source/cpu/cHardwareManager.cc
===================================================================
--- development/source/cpu/cHardwareManager.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/cpu/cHardwareManager.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -81,13 +81,10 @@
   
   cInitFile file(filename);
   
-  if (file.IsOpen() == false) {
+  if (file.WasOpened() == false) {
     m_world->GetDriver().RaiseFatalException(1, cString("Could not open instruction set '") + filename + "'.");
   }
   
-  file.Load();
-  file.Compress();
-  
   const cInstLib& inst_lib = *m_inst_set->GetInstLib();
   for (int line_id = 0; line_id < file.GetNumLines(); line_id++) {
     cString cur_line = file.GetLine(line_id);

Modified: development/source/cpu/cInstSet.cc
===================================================================
--- development/source/cpu/cInstSet.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/cpu/cInstSet.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -148,14 +148,10 @@
   
   
   cInitFile file(filename);
-  if (!file.Good()) {
+  if (!file.WasOpened()) {
     m_world->GetDriver().RaiseFatalException(1, cString("Unable to load instruction set '") + filename + "'.");
   }
   
-  file.Load();
-  file.Close();
-  file.Compress();
-  
   tList<cString> errors;
   bool success = true;
   for (int line_id = 0; line_id < file.GetNumLines(); line_id++) {

Modified: development/source/main/cAvidaConfig.cc
===================================================================
--- development/source/main/cAvidaConfig.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/main/cAvidaConfig.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -58,7 +58,7 @@
   // Load the contents from the file.
   cInitFile init_file(filename);
   
-  if (!init_file.IsOpen()) {
+  if (!init_file.WasOpened()) {
     if (crash_if_not_found) {
       // exit the program if the requested configuration file is not found
       cerr << "Warning: Unable to find file '" << filename 
@@ -72,17 +72,12 @@
     }
   }
   
-  init_file.Load();
-  init_file.Compress();
-  init_file.Close();
-
   cString version_id = init_file.ReadString("VERSION_ID", "Unknown");
   if (version_id != VERSION) {
     cerr << "Warning: Configuration file version number mismatch." << endl;
     cerr << "         Avida Version: \"" << VERSION << "\".  Config Version: \"" << version_id << "\"" << endl;
   }
   
-  init_file.SetVerbose();  
 
   // Loop through all groups, then all entrys, and try to load each one.
   tListIterator<cBaseConfigGroup> group_it(group_list);

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/main/cEnvironment.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -749,15 +749,11 @@
 bool cEnvironment::Load(const cString& filename)
 {
   cInitFile infile(filename);
-  if (infile.Good() == false) {
+  if (!infile.WasOpened()) {
     cerr << "Error: Failed to load environment '" << filename << "'." << endl;
     return false;
   }
   
-  infile.Load();
-  infile.Close();
-  infile.Compress();
-  
   for (int line_id = 0; line_id < infile.GetNumLines(); line_id++) {
     // Load the next line from the file.
     bool load_ok = LoadLine(infile.GetLine(line_id));

Modified: development/source/main/cEventList.cc
===================================================================
--- development/source/main/cEventList.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/main/cEventList.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -87,13 +87,8 @@
 {
   cInitFile event_file(filename);
   
-  if (!event_file.IsOpen()) return false;
+  if (!event_file.WasOpened()) return false;
 
-  // Load in the proper event list and set it up.
-  event_file.Load();
-  event_file.Compress();
-  event_file.Close();
-  
   // Loop through the line_list and change the lines to events.
   for (int line_id = 0; line_id < event_file.GetNumLines(); line_id++) {
     AddEventFileFormat(event_file.GetLine(line_id));

Modified: development/source/main/cGenomeUtil.cc
===================================================================
--- development/source/main/cGenomeUtil.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/main/cGenomeUtil.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -249,12 +249,8 @@
   cInitFile input_file(filename);
   bool success = true;
   
-  if (!input_file.IsOpen()) return false;
+  if (!input_file.WasOpened()) return false;
   
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
-  
   // Setup the code array...
   cGenome new_genome(input_file.GetNumLines());
   

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/main/cPopulation.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -2280,13 +2280,10 @@
   cout << "Loading: " << filename << endl;
   
   cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
+  if (!input_file.WasOpened()) {
     cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
     exit(1);
   }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
   
   // First, we read in all the genotypes and store them in a list
   

Modified: development/source/tools/cHelpManager.cc
===================================================================
--- development/source/tools/cHelpManager.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/tools/cHelpManager.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -55,9 +55,6 @@
 void cHelpManager::LoadFile(const cString & filename)
 {
   cInitFile help_file(filename);
-  help_file.Load();
-  help_file.Compress();
-  help_file.Close();
 
   cHelpType * type = NULL;
   cString keyword;

Modified: development/source/tools/cInitFile.cc
===================================================================
--- development/source/tools/cInitFile.cc	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/tools/cInitFile.cc	2007-08-15 20:46:50 UTC (rev 1942)
@@ -25,111 +25,105 @@
 
 #include "cInitFile.h"
 
+#include "cFile.h"
 #include "cStringIterator.h"
 
+
 using namespace std;
 
 
-void cInitFile::Load()
+cInitFile::cInitFile(const cString& filename) : m_filename(filename), m_ftype("unknown")
 {
-  if (!IsOpen()) return;   // The file must be opened!
-  cStringList line_list;   // Create a list to load all of the lines into.
-
-  cString buf;
-  ReadLine(buf);
-
-  // If this file doesn't work properly, return!
-  if ( Eof() && !buf.GetSize() ) return;
-
-  line_list.PushRear(buf);
-
-  ReadLine(buf);
-  while( !Eof() || buf.GetSize() ){
-    line_list.PushRear(buf);
-    ReadLine(buf);
-  }
-
-  // Copy all of the lines into the line array.
-  const int file_size = line_list.GetSize();
-  line_array.Resize(file_size);
-
-  for (int i = 0; i < file_size; i++) {
-    line_array[i].line = line_list.Pop();
-    line_array[i].line_num = i;
-    line_array[i].used = false;
-  }
+  tSmartArray<sLine*> lines;
+  m_opened = LoadFile(filename, lines);
+  PostProcess(lines);
 }
 
-void cInitFile::LoadStream(istream & in_stream)
+cInitFile::cInitFile(istream& in_stream) : m_filename("(stream)"), m_ftype("unknown")
 {
   if (in_stream.good() == false) {
     cerr << "Bad stream sent to cInitFile::LoadStream()" << endl;
+    m_opened = false;
     return;
   }
-
-  cStringList line_list;   // Create a list to load all of the lines into.
-
+  
+  tSmartArray<sLine*> lines;
+  
   char cur_line[MAX_STRING_LENGTH];
   in_stream.getline(cur_line, MAX_STRING_LENGTH);
-
+  
   // If this file doesn't work properly, return.
-  if( !in_stream && !strlen(cur_line) )  return;
-
-  in_stream.getline(cur_line, MAX_STRING_LENGTH);
-  while ( in_stream ) {
-    line_list.PushRear(cur_line);
+  if (!in_stream && !strlen(cur_line)) {
+    m_opened = false;
+    return;
+  }
+  
+  int linenum = 1;
+  while (in_stream) {
+    if (cur_line[0] == '#' && cur_line[1] == '!') ProcessCommand(cur_line, lines);
+    else lines.Push(new sLine(cur_line, "(stream)", linenum));
+    
     in_stream.getline(cur_line, MAX_STRING_LENGTH);
+    linenum++;
   }
-
-  // Copy all of the lines into the line array.
-  const int file_size = line_list.GetSize();
-  line_array.Resize(file_size);
-
-  for (int i = 0; i < file_size; i++) {
-    line_array[i].line = line_list.Pop();
-    line_array[i].line_num = i;
-    line_array[i].used = false;
-  }
+  
+  PostProcess(lines);
 }
 
 
-void cInitFile::Save(const cString & in_filename)
+bool cInitFile::LoadFile(const cString& filename, tSmartArray<sLine*>& lines)
 {
-  cString save_filename(GetFilename());
-  if (in_filename != "") save_filename = in_filename;
+  cFile file(filename);
+  if (!file.IsOpen()) return false;   // The file must be opened!
   
-  ofstream fp_save(save_filename);
+  cStringList line_list;   // Create a list to load all of the lines into.
 
-  // Go through the lines saving them...
-  for (int i = 0; i < line_array.GetSize(); i++) {
-    fp_save << line_array[i].line << endl;
-  }
+  int linenum = 0;
+  cString buf;
+  while (!file.Eof() && file.ReadLine(buf)) {
+    linenum++;
 
-  fp_save.close();
+    if (buf.GetSize() > 1 && buf[0] == '#' && buf[1] == '!') ProcessCommand(buf, lines);
+    else lines.Push(new sLine(buf, filename, linenum));
+  }
+  file.Close();
+  
+  if (linenum == 0) return false; // @DMB - should this be the case?
+  
+  return true;
 }
 
 
-void cInitFile::ReadHeader()
+void cInitFile::ProcessCommand(cString cmdstr, tSmartArray<sLine*>& lines)
 {
-  cString type_line = GetLine(0);
-  cString format_line = GetLine(1);
-
-  if (type_line.PopWord() == "#filetype") filetype = type_line.PopWord();
-  if (format_line.PopWord() == "#format") file_format.Load(format_line);
+  cString cmd = cmdstr.PopWord();
+  
+  if (cmd == "#!include") {
+    LoadFile(cmdstr.PopWord(), lines); // @TODO - report error
+  }
 }
 
 
-void cInitFile::Compress()
+void cInitFile::PostProcess(tSmartArray<sLine*>& lines)
 {
+  if (lines.GetSize() >= 2) {
+    cString type_line = lines[0]->line;
+    cString format_line = lines[1]->line;
+    
+    if (type_line.PopWord() == "#filetype") m_ftype = type_line.PopWord();
+    if (format_line.PopWord() == "#format") m_format.Load(format_line);
+  }
+
+  
   // We're going to handle this compression in multiple passes to make it
   // clean and easy.
 
-  const int num_lines = line_array.GetSize();
+  const int num_lines = lines.GetSize();
 
   // PASS 1: Remove all comments -- everything after a '#' sign -- and
   // compress all whitespace into a single space.
   for (int i = 0; i < num_lines; i++) {
-    cString & cur_line = line_array[i].line;
+    cString& cur_line = lines[i]->line;
 
     // Remove all characters past a comment mark and reduce whitespace.
     int comment_pos = cur_line.Find('#');
@@ -145,15 +139,14 @@
   for (int i = 0; i < num_lines; i++) {
     // If the current line is a continuation, append it to the previous line.
     if (continued == true) {
-      line_array[prev_line_id].line += line_array[i].line;
-      line_array[i].line = "";
+      lines[prev_line_id]->line += lines[i]->line;
+      lines[i]->line = "";
     }
     else prev_line_id = i;
 
     // See if the prev_line is continued, and if it is, take care of it.
-    cString & prev_line = line_array[prev_line_id].line;
-    if (prev_line.GetSize() > 0 &&
-	prev_line[prev_line.GetSize() - 1] == '\\') {
+    cString& prev_line = lines[prev_line_id]->line;
+    if (prev_line.GetSize() > 0 && prev_line[prev_line.GetSize() - 1] == '\\') {
       prev_line.ClipEnd(1);  // Remove continuation mark.
       continued = true;
     }
@@ -165,69 +158,68 @@
   int next_id = 0;
   for (int i = 0; i < num_lines; i++) {
     // If we should keep this line, compact it.
-    if (line_array[i].line.GetSize() > 0) {
-      if (next_id != i) line_array[next_id] = line_array[i];
+    if (lines[i]->line.GetSize() > 0) {
+      if (next_id != i) {
+        delete lines[next_id];
+        lines[next_id] = lines[i];
+        lines[i] = NULL;
+      }
       next_id++;
     }
   }
 
-  // Clip any extra lines at the end of the array.
-
-  line_array.Resize(next_id);
-
-  // Move the active line back to the beginning to avoid confusion.
-  active_line = 0;
+  // Resize the internal line structure and move the line structs to it
+  m_lines.Resize(next_id);
+  for (int i = 0; i < next_id; i++) m_lines[i] = lines[i];
 }
 
 
-void cInitFile::AddLine(cString & in_string)
+void cInitFile::Save(const cString& in_filename)
 {
-  extra_lines.Push(in_string);
+  cString save_filename(in_filename);
+  if (save_filename != "") save_filename = m_filename;
+  
+  ofstream fp_save(save_filename);
+  
+  // Go through the lines saving them...
+  for (int i = 0; i < m_lines.GetSize(); i++) {
+    fp_save << m_lines[i]->line << endl;
+  }
+  
+  fp_save.close();
 }
 
+
+
 cString cInitFile::GetLine(int line_num)
 {
-  if (line_num < 0 || line_num >= line_array.GetSize()) return "";
-  return line_array[line_num].line;
+  if (line_num < 0 || line_num >= m_lines.GetSize()) return "";
+  return m_lines[line_num]->line;
 }
 
 
-bool cInitFile::Find(cString & in_string, const cString & keyword,
-		     int col) const
+bool cInitFile::Find(cString& in_string, const cString& keyword, int col) const
 {
   bool found = false;
 
   // Loop through all of the lines looking for this keyword.  Start with
   // the actual file...
-  for (int line_id = 0; line_id < line_array.GetSize(); line_id++) {
-    cString cur_string = line_array[line_id].line;
+  for (int line_id = 0; line_id < m_lines.GetSize(); line_id++) {
+    cString cur_string = m_lines[line_id]->line;
 
     // If we found the keyword, return it and stop.    
     if (cur_string.GetWord(col) == keyword) {
-      line_array[line_id].used = true;
+      m_lines[line_id]->used = true;
       in_string = cur_string;
       found = true;
     }
   }
 
-  // Next, look through any extra lines appended to the file.
-  cStringIterator list_it(extra_lines);
-  while ( list_it.AtEnd() == false ) {
-    list_it.Next();
-    cString cur_string = list_it.Get();
-
-    // If we found the keyword, return it and stop.
-    if (cur_string.GetWord(col) == keyword) {
-      in_string = cur_string;
-      found = true;
-    }
-  }
-
   return found;    // Not Found...
 }
 
 
-cString cInitFile::ReadString(const cString & name, cString def) const
+cString cInitFile::ReadString(const cString& name, cString def) const
 {
   // See if we definately can't find the keyword.
   if (name == "") return def;
@@ -235,10 +227,7 @@
   // Search for the keyword.
   cString cur_line;
   if (Find(cur_line, name, 0) == false) {
-    if (verbose == true) {
-      cerr << "Warning: " << name << " not in \"" << GetFilename()
-	   << "\", defaulting to: " << def <<endl;
-    }
+    cerr << "Warning: " << name << " not in '" << m_filename << "', defaulting to: " << def << endl;
     return def;
   }
 
@@ -252,13 +241,13 @@
 {
   bool found = false;
 
-  for (int i = 0; i < line_array.GetSize(); i++) {
-    if (line_array[i].used == false) {
+  for (int i = 0; i < m_lines.GetSize(); i++) {
+    if (m_lines[i]->used == false) {
       if (found == false) {
         found = true;
-        cerr << "Warning: unknown lines in input file '" << filename << "':" << endl;
+        cerr << "Warning: unknown lines in input file '" << m_filename << "'" << endl;
       }
-      cerr << " " << line_array[i].line_num + 1 << ": " << line_array[i].line << endl;
+      cerr << "    " << m_lines[i]->file << ":" << m_lines[i]->line_num << ": " << m_lines[i]->line << endl;
     }
   }
   

Modified: development/source/tools/cInitFile.h
===================================================================
--- development/source/tools/cInitFile.h	2007-08-15 19:56:33 UTC (rev 1941)
+++ development/source/tools/cInitFile.h	2007-08-15 20:46:50 UTC (rev 1942)
@@ -26,23 +26,15 @@
 #ifndef cInitFile_h
 #define cInitFile_h
 
-#ifndef cFile_h
-#include "cFile.h"
-#endif
 #ifndef cString_h
 #include "cString.h"
 #endif
 #ifndef cStringList_h
 #include "cStringList.h"
 #endif
-#ifndef tArray_h
-#include "tArray.h"
+#ifndef tSmartArray_h
+#include "tSmartArray.h"
 #endif
-#if USE_tMemTrack
-# ifndef tMemTrack_h
-#  include "tMemTrack.h"
-# endif
-#endif
 
 
 #include <iostream>
@@ -51,126 +43,56 @@
  * A class to handle initialization files.
  **/
 
-class cInitFile : public cFile
+class cInitFile
 {
-#if USE_tMemTrack
-  tMemTrack<cInitFile> mt;
-#endif
 private:
-  struct sFileLineInfo {
+  cString m_filename;
+  bool m_opened;
+  
+  struct sLine {
     cString line;
+    cString file;
     int line_num;
     mutable bool used;
-
-    template<class Archive>
-    void save(Archive & a, const unsigned int version) const
-    {
-      int __used = (used == false)?(0):(1);
-      a.ArkvObj("line", line);
-      a.ArkvObj("line_num", line_num);
-      a.ArkvObj("used", __used);
-    }
-    template<class Archive>
-    void load(Archive & a, const unsigned int version)
-    {
-      int __used;
-      a.ArkvObj("line", line);
-      a.ArkvObj("line_num", line_num);
-      a.ArkvObj("used", __used);
-      used = (__used == false)?(0):(1);
-    }
-    template<class Archive>
-    void serialize(Archive & a, const unsigned int version)
-    { a.SplitLoadSave(*this, version); }
-
+    
+    sLine(const cString& in_line, const cString& in_file, int in_line_num)
+      : line(in_line), file(in_file), line_num(in_line_num), used(false) { ; }
   };
 
-  tArray<sFileLineInfo> line_array;
-  cStringList extra_lines;
-  cString filetype;
-  cStringList file_format;
+  tArray<sLine*> m_lines;
+  cString m_ftype;
+  cStringList m_format;
 
-  int active_line;
 
+  bool LoadFile(const cString& filename, tSmartArray<sLine*>& lines);
+  void ProcessCommand(cString cmdstr, tSmartArray<sLine*>& lines);
+  void PostProcess(tSmartArray<sLine*>& lines);
 
+  
   cInitFile(const cInitFile&); // @not_implemented
   cInitFile& operator=(const cInitFile&); // @not_implemented
   
+
 public:
-  /**
-   * The empty constructor constructs an object that is in a clean
-   * state. You can set the file to open with @ref cFile::Open() later on.
-   **/
-  cInitFile() : filetype("unknown"), active_line(0) { ; }
+  cInitFile(const cString& filename);
+  cInitFile(std::istream& in_stream);
+  ~cInitFile() { for (int i = 0; i < m_lines.GetSize(); i++) delete m_lines[i]; }
   
-  /**
-   * Opens the file with the given name.
-   * 
-   * @param in_filename Name of the initialization file to open.
-   **/
-  cInitFile(cString in_filename) : cFile(in_filename), filetype("unknown"), active_line(0) { ; }
+  bool WasOpened() const { return m_opened; }
   
-  ~cInitFile() { ; }
+  void Save(const cString& in_filename = "");
   
   /**
-   * Loads the file into memory.
-   **/
-  void Load();
-  
-  /**
-   * Loads a stream into memory rather than a file.
-   **/
-  void LoadStream(std::istream & in_steam);
-  
-  void Save(const cString & in_filename = "");
-  
-  /**
-   * Parse heading information about the contents of the file loaded into
-   * memory, if available.
-   **/
-  void ReadHeader();
-
-  /**
-   * Remove all comments and whitespace from a file loaded into memory.
-   * Comments are currently marked with the character '#'.
-   **/
-  void Compress();
-  
-  /** 
-   * Add a line to the beginning of the file in memory.
-   * This function is used by @ref cGenesis.
-   *
-   * @param in_string The string to be added.
-   **/
-  void AddLine(cString & in_string);
-  
-  /**
    * Get a line from the file in memory. If called without parameters,
    * the first line of the file is returned.
    *
    * @param line_num The line count of the line to be returned 
    * (starting from 0).
    **/
-  cString GetLine(int line_num=0);
+  cString GetLine(int line_num = 0);
   
 
   /**
-   * Get the active line and advance to the next line.
-   **/
-  cString GetNextLine() { return GetLine(active_line++); }
-
-
-  /**
-   * Reset the active line to the beginning (or the point specified...
-   **/
-  void ResetLine(int new_pos=0) { active_line = new_pos; }
-
-  /**
-   * Returns the line number that is active.
-   **/
-  int GetLineNum() { return active_line; }
-
-  /**
    * Checks whether any line contains a given keyword in the specified 
    * column. Stops when the first occurrence of the keyword is found.
    *
@@ -180,7 +102,7 @@
    * @param keyword The keyword to look for.
    * @param col The column in which the keyword should be found.
    **/
-  bool Find(cString & in_string, const cString & keyword, int col) const;
+  bool Find(cString& in_string, const cString& keyword, int col) const;
   
   /**
    * Reads an entry in the initialization file that has a given keyword
@@ -192,7 +114,7 @@
    * one to set standard values that are used if the user does not override
    * them.
    **/
-  cString ReadString(const cString & name, cString def = "") const;
+  cString ReadString(const cString& name, cString def = "") const;
   
   /**
    * Looks over all lines loaded into the file, and warns if any of them
@@ -202,27 +124,10 @@
    **/
   bool WarnUnused() const;
 
-  /**
-   * Return the number of lines in memory.
-   **/
-  int GetNumLines() const { return line_array.GetSize(); }
+  int GetNumLines() const { return m_lines.GetSize(); }
 
-  const cString & GetFiletype() { return filetype; }
-  cStringList & GetFormat() { return file_format; }
-
-
-  template<class Archive>
-  void serialize(Archive & a, const unsigned int version)
-  {
-    a.ArkvBase("cFile", (cFile &)(*this), *this);
-    a.ArkvObj("line_array", line_array);
-    a.ArkvObj("extra_lines", extra_lines);
-    a.ArkvObj("filetype", filetype);
-    a.ArkvObj("file_format", file_format);
-    a.ArkvObj("active_line", active_line);
-  }
-
-
+  const cString& GetFiletype() { return m_ftype; }
+  const cStringList& GetFormat() { return m_format; }
 };
 
 #endif




More information about the Avida-cvs mailing list