[Avida-cvs] [avida-svn] r910 - in development: Avida.xcodeproj documentation source/main

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Aug 30 14:03:42 PDT 2006


Author: brysonda
Date: 2006-08-30 17:03:41 -0400 (Wed, 30 Aug 2006)
New Revision: 910

Removed:
   development/documentation/code_init_file.html
Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/documentation/code_genome.html
   development/documentation/index.html
   development/source/main/cGenome.h
   development/source/main/cInstruction.cc
   development/source/main/cInstruction.h
Log:
Begin updating Virtual CPU Building Block documentation.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2006-08-30 20:08:33 UTC (rev 909)
+++ development/Avida.xcodeproj/project.pbxproj	2006-08-30 21:03:41 UTC (rev 910)
@@ -598,7 +598,6 @@
 		70920C1E0A9CCE2C00757CDB /* code_death_birth.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_death_birth.html; sourceTree = "<group>"; };
 		70920C1F0A9CCE2C00757CDB /* code_environment.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_environment.html; sourceTree = "<group>"; };
 		70920C220A9CCE2C00757CDB /* code_genome.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_genome.html; sourceTree = "<group>"; };
-		70920C230A9CCE2C00757CDB /* code_init_file.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_init_file.html; sourceTree = "<group>"; };
 		70920C240A9CCE2C00757CDB /* code_instruction.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_instruction.html; sourceTree = "<group>"; };
 		70920C250A9CCE2C00757CDB /* code_life_cycle.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_life_cycle.html; sourceTree = "<group>"; };
 		70920C260A9CCE2C00757CDB /* code_task.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html.documentation; path = code_task.html; sourceTree = "<group>"; };
@@ -1123,7 +1122,6 @@
 				70920C1E0A9CCE2C00757CDB /* code_death_birth.html */,
 				70920C1F0A9CCE2C00757CDB /* code_environment.html */,
 				70920C220A9CCE2C00757CDB /* code_genome.html */,
-				70920C230A9CCE2C00757CDB /* code_init_file.html */,
 				70920C240A9CCE2C00757CDB /* code_instruction.html */,
 				70920C250A9CCE2C00757CDB /* code_life_cycle.html */,
 				70920C260A9CCE2C00757CDB /* code_task.html */,

Modified: development/documentation/code_genome.html
===================================================================
--- development/documentation/code_genome.html	2006-08-30 20:08:33 UTC (rev 909)
+++ development/documentation/code_genome.html	2006-08-30 21:03:41 UTC (rev 910)
@@ -1,133 +1,138 @@
 <html>
-<title>The building blocks of the virtual CPU</title>
-<body
- bgcolor="#FFFFFF"
- text="#000000"
- link="#0000AA"
- alink="#0000FF"
- vlink="#000044">
+<head>
+  <title>Avida : The Building Blocks of the Virtual CPU</title>
+</head>
+<body>
 
-<h2 align=center>The building blocks of the virtual CPU</h2>
+<div style="float: right">
+Revised 2006-08-30 DMB
+</div>
 
+<p><a href="index.html">Return to the Index</a></p>
+<hr />
+
+<div align="center">
+<h1>The Building Blocks of the Virtual CPU</h1>
+</div>
+
 <p>
 This document discusses the implementation of the cInstruction, cGenome,
 and cInstLib (instruction library) classes.
+</p>
 
-<p>
-<h3>The cInstruction class</h3>
 
+<p>&nbsp;</p>
+<h2>The cInstruction Class</h2>
+
 <p>
 This class is used to represent a single instruction within a genome.  The
 private portion of this class consists of a single number that uniquely
 identifies the type of instruction, and the public section
 has a number of helper methods that allow us to work with that number.
+</p>
 
 <pre>
-  class <font color="#880000">cInstruction</font> {
-  private:
-    <font color="#880000">UCHAR</font> <font color="#000088">operand</font>;
- 
-  public:
-    <font color="#886600">// Accessors...</font>
-    <font color="#880000">int</font> <font color="#008800">GetOp()</font> const { return (<font color="#880000">int</font>) <font color="#000088">operand</font>; }
-    void <font color="#008800">SetOp</font>(<font color="#880000">int</font> <font color="#000088">in_op</font>) { <font color="#008800">assert</font>(<font color="#000088">in_op</font> &lt; 256); <font color="#000088">operand</font> = <font color="#000088">in_op</font>; }
- 
-    <font color="#886600">// Operators...</font>
-    void <font color="#008800">operator=</font>(const <font color="#880000">cInstruction</font> & <font color="#000088">inst</font>) { <font color="#000088">operand</font> = <font color="#000088">inst</font>.<font color="#000088">operand</font>; }
-    <font color="#880000">bool</font> <font color="#008800">operator==</font>(const <font color="#880000">cInstruction</font> & <font color="#000088">inst</font>) const
-      { return (<font color="#000088">operand</font> == <font color="#000088">inst</font>.<font color="#000088">operand</font>); }
-    <font color="#880000">bool</font> <font color="#008800">operator!=</font>(const <font color="#880000">cInstruction</font> & <font color="#000088">inst</font>) const
-      { return !(<font color="#008800">operator==</font>(<font color="#000088">inst</font>)); }
+class <font color="#880000">cInstruction</font> {
+private:
+  unsigned char <font color="#000088">m_operand</font>;
 
-    <font color="#886600">// Constructors and Destructor...</font>
-    <font color="#008800">cInstruction()</font> { <font color="#000088">operand</font> = 0; }
-    <font color="#008800">cInstruction</font>(const <font color="#880000">cInstruction</font> & <font color="#000088">_inst</font>) { *<font color="#000088">this</font> = <font color="#000088">_inst</font>; }
-    explicit <font color="#008800">cInstruction</font>(<font color="#880000">int</font> <font color="#000088">in_op</font>) { <font color="#008800">SetOp</font>(<font color="#000088">in_op</font>); }
-    <font color="#008800">~cInstruction</font>() { ; }
- 
-    <font color="#886600">// Some extra methods to convert too and from alpha-numeric symbols...</font>
-    <font color="#880000">char</font> <font color="#008800">GetSymbol()</font> const;
-    void <font color="#008800">SetSymbol</font>(<font color="#880000">char</font> <font color="#000088">symbol</font>);
-  };
+public:
+  <font color="#886600">// Constructors and Destructor...</font>
+  <font color="#008800">cInstruction()</font> : <font color="#000088">m_operand</font>(0) { ; }
+  <font color="#008800">cInstruction</font>(const <font color="#880000">cInstruction</font>&amp; <font color="#000088">inst</font>) { *<font color="#000088">this</font> = <font color="#000088">inst</font>; }
+  explicit <font color="#008800">cInstruction</font>(<font color="#880000">int</font> <font color="#000088">in_op</font>) { <font color="#008800">SetOp</font>(<font color="#000088">in_op</font>); }
+  <font color="#008800">~cInstruction</font>() { ; }
+
+  <font color="#886600">// Accessors...</font>
+  <font color="#880000">int</font> <font color="#008800">GetOp()</font> const { return static_cast&lt;int&gt;(<font color="#000088">m_operand</font>); }
+  void <font color="#008800">SetOp</font>(<font color="#880000">int</font> <font color="#000088">in_op</font>) { <font color="#008800">assert</font>(<font color="#000088">in_op</font> &lt; 256); <font color="#000088">m_operand</font> = <font color="#000088">in_op</font>; }
+
+  <font color="#886600">// Operators...</font>
+  void <font color="#008800">operator=</font>(const <font color="#880000">cInstruction</font>&amp; <font color="#000088">inst</font>) { <font color="#000088">m_operand</font> = <font color="#000088">inst</font>.<font color="#000088">m_operand</font>; }
+  <font color="#880000">bool</font> <font color="#008800">operator==</font>(const <font color="#880000">cInstruction</font>&amp; <font color="#000088">inst</font>) const { return (<font color="#000088">m_operand</font> == <font color="#000088">inst</font>.<font color="#000088">m_operand</font>); }
+  <font color="#880000">bool</font> <font color="#008800">operator!=</font>(const <font color="#880000">cInstruction</font>&amp; <font color="#000088">inst</font>) const { return !(<font color="#008800">operator==</font>(<font color="#000088">inst</font>)); }
+
+  <font color="#886600">// Some extra methods to convert too and from alpha-numeric symbols...</font>
+  <font color="#880000">char</font> <font color="#008800">GetSymbol</font>() const;
+  void <font color="#008800">SetSymbol</font>(<font color="#880000">char</font> <font color="#000088">symbol</font>);
+};
 </pre>
 
 <p>
-As I stated above, the only private datum is a numerical value that
-identifies this instruction.  The name "<font color="#000088">operand</font>"
-is the term that is used for a command name in an assembly language.  Most
-normal assembly languages have both an operand and arguments associated with
-each full command.  In avida, the commands have no arguments, and hence they
-just consist of a single operand.  The data type used for this is 
-<font color="#880000">UCHAR</font>, which is short for
-"<font color="#880000">unsigned char</font>".  A char is an 8 bit number,
-so when one is unsigned, it represents a number from 0 to 255.  As avida
-is currently implemented, we are limited to 256 distinct instructions.  To
-the outside world, we treat the instruction operand like an integer, so it
-would be easy to 
-modify this class were we ever to need more than 256 instructions in the
-set.  The only reason to limit it to 8 bits internally (rather than the 32
-of an int) is to save memory when we have a very large number of instructions
-throughout a population.  Instructions already make up over half of all
-the memory resources used by avida.
-
+As stated above, the only private datum is a numerical value that identifies
+this instruction.  The name <font color="#000088">m_operand</font> is the term
+that is used for a command name in an assembly language.  Most normal assembly
+languages have both an operand and arguments associated with each full command.
+In Avida, the commands have no arguments, and hence they just consist of a
+single operand.  The data type used for this is <code>unsigned char</code>.  A
+char is an 8 bit number, so when one is unsigned, it represents a number from 0
+to 255. As Avida is currently implemented, we are limited to 256 distinct
+instructions.  To the outside world, we treat the instruction operand like an
+integer, so it would be easy to modify this class were we ever to need more
+than 256 instructions in the set.  The only reason to limit it to 8 bits
+internally (rather than the 32 of an int) is to save memory when we have a very
+large number of instructions throughout a population.  Instructions already
+make up over half of all the memory resources used by Avida.
+</p>
 <p>
-The public methods begin with the <font color="#008800">GetOp()</font> and
-<font color="#008800">SetOp()</font> methods, which  are standard accessors.
-Next, we have a collection of methods that begin with the word "operator".
+The public methods begin with the <font color="#008800">GetOp</font>() and
+<font color="#008800">SetOp</font>() methods, which are standard accessors.
+Next, we have a collection of methods that begin with the word 'operator'.
 These are used to define how the corresponding symbols should be treated
 when applied to objects of this class.  For example, the method 
-<font color="#008800">operator==()</font> is called when we try to compare
-on object of type cInstruction to another.  We have full control over the
+<font color="#008800">operator==</font>() is called when we try to compare
+an object of type cInstruction to another.  We have full control over the
 definition of this method, just like any other.
-
+</p>
 <p>
-The next batch of methods we come to are the constructors and destructor.
-Notice that there are three different constructors, so there are multiple
-ways an instruction object can be created.
-
-<p>
 Finally, we have a pair of methods that convert instructions to and from
-alphanumeric characters (symbols).  These methods are used to 
-print instructions out in a maximally compressed format, and to load them back
-in.  The order of symbols used are the letters 'a' through 'z' in lowercase,
-followed by an uppercase 'A' through 'Z' and finally the numbers '0' through
-'9'.  If there are more
-than 62 possible instructions, all the rest are assigned a '?' when printed
-out, and cannot be read back in properly from this format.
+alphanumeric characters (symbols). These methods are used to print instructions
+out in a maximally compressed format, and to load them back in.  The order of
+symbols used are the letters 'a' through 'z' in lowercase, followed by an
+uppercase 'A' through 'Z' and finally the numbers '0' through '9'.  If there
+are more than 62 possible instructions, all the rest are assigned a '?' when
+printed out, and cannot be read back in properly from this format.
+</p>
 
 
-<h3>The cGenome class</h3>
+<p>&nbsp;</p>
+<h2>The cGenome class</h2>
 
 <p>
-A genome is a sequence of instructions.  The following
-class maintains this sequence as an array, and provides a collection of
-methods to manipulate the total construct.
+A genome is a sequence of instructions.  The following class maintains this
+sequence as an array, and provides a collection of methods to manipulate the
+total construct.
+</p>
 
 <pre>
-  class <font color="#880000">cGenome</font> {
-  protected:
-    <font color="#880000">tArray</font>&lt;<font color="#880000">cInstruction</font>&gt; <font color="#000088">genome</font>;
-    <font color="#880000">int</font> <font color="#000088">active_size</font>;
-   
-  public:
-    explicit <font color="#008800">cGenome</font>(<font color="#880000">int</font> <font color="#000088">_size</font>);
-    <font color="#008800">cGenome</font>(const <font color="#880000">cGenome</font> & <font color="#000088">in_genome</font>);
-    <font color="#008800">cGenome</font>(const <font color="#880000">cString</font> & <font color="#000088">in_string</font>);
-    virtual <font color="#008800">~cGenome</font>();
-   
-    virtual void <font color="#008800">operator=</font>(const <font color="#880000">cGenome</font> & <font color="#000088">other_genome</font>);
-    virtual <font color="#880000">bool</font> <font color="#008800">operator==</font>(const <font color="#880000">cGenome</font> & <font color="#000088">other_genome</font>) const;
-   
-    <font color="#880000">cInstruction</font> & <font color="#008800">operator[]</font>(<font color="#880000">int</font> <font color="#000088">index</font>)
-      { <font color="#008800">assert</font>(<font color="#000088">index</font> &gt;= 0 && <font color="#000088">index</font> &lt; <font color="#000088">active_size</font>);  return <font color="#000088">genome</font>[<font color="#000088">index</font>]; }
-    const <font color="#880000">cInstruction</font> & <font color="#008800">operator[]</font>(<font color="#880000">int</font> <font color="#000088">index</font>) const
-      { <font color="#008800">assert</font>(<font color="#000088">index</font> &gt;= 0 && <font color="#000088">index</font> &lt; <font color="#000088">active_size</font>);  return <font color="#000088">genome</font>[<font color="#000088">index</font>]; }
-   
-    virtual void <font color="#008800">Copy</font>(<font color="#880000">int</font> <font color="#000088">to</font>, <font color="#880000">int</font> <font color="#000088">from</font>);
-   
-    <font color="#880000">int</font> <font color="#008800">GetSize()</font> const { return <font color="#000088">active_size</font>; }
-    <font color="#880000">cString</font> <font color="#008800">AsString()</font> const;
-  };
+class <font color="#880000">cGenome</font>
+{
+protected:
+  <font color="#880000">tArray</font>&lt;<font color="#880000">cInstruction</font>&gt; <font color="#000088">genome</font>;
+  int <font color="#000088">active_size</font>;
+ 
+public:
+  <font color="#008800">cGenome</font>() { ; }
+  explicit <font color="#008800">cGenome</font>(int <font color="#000088">_size</font>);
+  <font color="#008800">cGenome</font>(const <font color="#880000">cGenome</font>&amp; <font color="#000088">in_genome</font>);
+  <font color="#008800">cGenome</font>(const <font color="#880000">cString</font>&amp; <font color="#000088">in_string</font>);
+  virtual <font color="#008800">~cGenome</font>();
+ 
+  virtual void <font color="#008800">operator=</font>(const <font color="#880000">cGenome</font>&amp; <font color="#000088">other_genome</font>);
+  virtual bool <font color="#008800">operator==</font>(const <font color="#880000">cGenome</font>&amp; <font color="#000088">other_genome</font>) const;
+  virtual bool <font color="#008800">operator!=</font>(const <font color="#880000">cGenome</font>&amp; <font color="#000088">other_genome</font>) const { return !(<font color="#000088">this</font>-&gt;<font color="#008800">operator==</font>(<font color="#000088">other_genome</font>)); }
+  virtual bool <font color="#008800">operator&lt;</font>(const <font color="#880000">cGenome</font>&amp; <font color="#000088">other_genome</font>) const { return <font color="#008800">AsString</font>() &lt; <font color="#000088">other_genome</font>.<font color="#008800">AsString</font>(); }
+ 
+  <font color="#880000">cInstruction</font> & <font color="#008800">operator[]</font>(<font color="#880000">int</font> <font color="#000088">index</font>)
+    { <font color="#008800">assert</font>(<font color="#000088">index</font> &gt;= 0 && <font color="#000088">index</font> &lt; <font color="#000088">active_size</font>);  return <font color="#000088">genome</font>[<font color="#000088">index</font>]; }
+  const <font color="#880000">cInstruction</font> & <font color="#008800">operator[]</font>(<font color="#880000">int</font> <font color="#000088">index</font>) const
+    { <font color="#008800">assert</font>(<font color="#000088">index</font> &gt;= 0 && <font color="#000088">index</font> &lt; <font color="#000088">active_size</font>);  return <font color="#000088">genome</font>[<font color="#000088">index</font>]; }
+ 
+  virtual void <font color="#008800">Copy</font>(<font color="#880000">int</font> <font color="#000088">to</font>, <font color="#880000">int</font> <font color="#000088">from</font>);
+ 
+  <font color="#880000">int</font> <font color="#008800">GetSize()</font> const { return <font color="#000088">active_size</font>; }
+  <font color="#880000">cString</font> <font color="#008800">AsString()</font> const;
+};
 </pre>
 
 <p>
@@ -373,7 +378,9 @@
 Finally, three static methods are included to provide access to the
 three pre-defined instructions.
 
-<br><hr>
-Project hosted by:<br>
-<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=46761&type=2" width="125" height="37" border="0" alt="SourceForge.net"/></a>
-    
\ No newline at end of file
+
+<hr />
+<p><a href="index.html">Return to the Index</a></p>
+
+</body>
+</html>

Deleted: development/documentation/code_init_file.html
===================================================================
--- development/documentation/code_init_file.html	2006-08-30 20:08:33 UTC (rev 909)
+++ development/documentation/code_init_file.html	2006-08-30 21:03:41 UTC (rev 910)
@@ -1,333 +0,0 @@
-<html>
-<title>The cFile, cInitFile, and cGenesis classes</title>
-<body
- bgcolor="#FFFFFF"
- text="#000000"
- link="#0000AA"
- alink="#0000FF"
- vlink="#000044">
-
-<h2 align=center>The cFile, cInitFile, and cGenesis classes</h2>
-
-<p>
-All configuration methods in Avida involve reading information from a
-file.  When we examined events, we didn't have to worry about dealing with
-the file because all of that source code was automatically generated
-for us.  It is not critical to fully understand the file system if you are
-not going to directly use it, but it will aid you in putting other objects
-into perspective.
-
-<p>
-The <font color="#880000">cFile</font> class is a base class that handles
-opening a file, closing it, and reading from it one line at a time.
-The <font color="#880000">cInitFile</font> class <b>extends</b> cFile (that
-is, it is derived from cFile) adding special functions to load the
-file into memory, remove comments from it, and search through it for
-keywords.  Finally, the <font color="#880000">cGenesis</font> class further
-extends cInitFile, including new functions that assume each line of the file
-has the format "KEYWORD VALUE" to allow the programmer to pass in a keyword
-and get back a value of the appropriate form.
-
-<p>
-All three of these classes are defined in the files "<tt>file.hh</tt>" and
-"<tt>file.cc</tt>", located in the directory
-"<tt>current/source/tools/</tt>".  See also the
-cDataFile class, which is more focused on writing to a file than reading from
-it.  Here, we'll step through each cFile-based class in order.
-
-<p>
-<h3>The <font color="#880000">cFile</font> class</h3>
-
-<p>
-This is the fundamental file loading class.  Here is a mildly edited
-version of its class declaration:
-
-<pre>
-  class <font color="#880000">cFile</font> {
-  protected:
-    <font color="#880000">fstream</font> <font color="#000088">fp</font>;        <font color="#886600">// An input stream associated with this file.</font>
-    <font color="#880000">cString</font> <font color="#000088">filename</font>;  <font color="#886600">// The name of the file we're working with.</font>
-    <font color="#880000">bool</font> <font color="#000088">is_open</font>;      <font color="#886600">// Have we successfully opened this file?</font>
-    <font color="#880000">bool</font> <font color="#000088">verbose</font>;      <font color="#886600">// Should file be verbose about warnings to users?</font>
-  public:
-    <font color="#008800">cFile</font>(<font color="#880000">cString</font> <font color="#000088">_fname</font>) : <font color="#000088">filename</font>(""), <font color="#000088">is_open</font>(false) { <font color="#008800">Open</font>(<font color="#000088">_fname</font>); }
-    <font color="#008800">~cFile</font>() { if (<font color="#000088">is_open</font> == true) <font color="#000088">fp</font>.<font color="#008800">close</font>(); <font color="#000088">filename</font> = ""; }
-  
-    <font color="#886600">// Manipulators</font>
-    <font color="#880000">bool</font> <font color="#008800">Open</font>(<font color="#880000">cString</font> <font color="#000088">_fname</font>, <font color="#880000">int</font> <font color="#000088">mode</font>=(<font color="#008800">ios</font>::<font color="#000088">in</font>|<font color="#008800">ios</font>::<font color="#000088">nocreate</font>));
-    <font color="#880000">bool</font> <font color="#008800">Close</font>();
-  
-    <font color="#880000">bool</font> <font color="#008800">ReadLine</font>(<font color="#880000">cString</font> & <font color="#000088">in_string</font>);
-  
-    <font color="#886600">// Tests</font>
-    <font color="#880000">bool</font> <font color="#008800">IsOpen</font>() const { return <font color="#000088">is_open</font>; }
-    <font color="#880000">bool</font> <font color="#008800">Good</font>() const { return (<font color="#000088">fp</font>.<font color="#008800">good</font>()); }
-    <font color="#880000">bool</font> <font color="#008800">Eof</font>() const { return (<font color="#000088">fp</font>.<font color="#008800">eof</font>()); }
-
-    <font color="#886600">// Accessors</font>
-    void <font color="#008800">SetVerbose</font>(<font color="#880000">bool</font> <font color="#000088">_v</font>=true) { <font color="#000088">verbose</font> = <font color="#000088">_v</font>; }
-    const <font color="#880000">cString</font> & <font color="#008800">GetFilename</font>() const { return <font color="#000088">filename</font>; }
-  };
-</pre>
-
-<p>
-To use this class, you create a cFile object and pass in a filename.  This
-will automatically run <font color="#008800">Open()</font> on the file.  At
-any point thereafter you have the option to <font
-color="#008800">Close()</font> the file and open a new one.  The
-<font color="#008800">IsOpen()</font> method allows you to test if a file is
-currently open, and the <font color="#008800">Good()</font> method tests if
-there are any problems with the file (i.e., it was deleted out from under the
-user.)
-
-<p>
-You can obtain one line at a time from an open file by using the
-<font color="#008800">ReadLine()</font> method.  When you call this method,
-you must give it a string that the method will modify.  The method attempts
-to copy the next line in the file into that string, and then the
-method returns <tt>true</tt> or <tt>false</tt> indicating if the copy was
-successful.  Failure (a return value of <tt>false</tt>) typically indicates
-that the user is at the end of the file, or something about the file has
-failed.
-
-<p>
-As an example of what a method description looks like, here is the
-code body for the Open() method:
-
-<p>
-<pre>
-  <font color="#880000">bool</font> <font color="#880000">cFile</font>::<font color="#008800">Open</font>(<font color="#880000">cString</font> <font color="#000088">_fname</font>, <font color="#880000">int</font> <font color="#000088">flags</font>)
-  {
-    if ( <font color="#008800">IsOpen</font>() ) <font color="#008800">Close</font>();   <font color="#886600">// If a file is already open, close it first.</font>
-    <font color="#000088">fp</font>.<font color="#008800">open</font>(<font color="#000088">_fname</font>(), <font color="#000088">flags</font>);  <font color="#886600">// Open the new file.</font>
-  
-    <font color="#886600">// Test if there was an error, and if so, try again!</font>
-    <font color="#880000">int</font> <font color="#000088">err_id</font> = <font color="#000088">fp</font>.<font color="#008800">fail</font>();
-    if( <font color="#000088">err_id</font> != 0 ){
-      <font color="#000088">fp</font>.<font color="#008800">clear</font>();
-      <font color="#000088">fp</font>.<font color="#008800">open</font>(<font color="#000088">_fname</font>(), <font color="#000088">flags</font>);
-    }
-
-    <font color="#886600">// If there is still an error, determine its type and report it.</font>
-    <font color="#000088">err_id</font> = <font color="#000088">fp</font>.<font color="#008800">fail</font>();
-    if ( <font color="#000088">err_id</font> != 0 ){
-      <font color="#880000">cString</font> <font color="#000088">error_desc</font> = "?? Unknown Error??";
-  
-      <font color="#886600">// See if we can determine a more exact error type.</font>
-      if (<font color="#000088">err_id</font> == EACCES) <font color="#000088">error_desc</font> = "Access denied";
-      else if (<font color="#000088">err_id</font> == EINVAL) <font color="#000088">error_desc</font> = "Invalid open flag or access mode";
-      else if (<font color="#000088">err_id</font> == ENOENT) <font color="#000088">error_desc</font> = "File or path not found";
-
-      <font color="#886600">// Print the error.</font>
-      <font color="#000088">cerr</font> << "Unable to open file '" << <font color="#000088">_fname</font>
-           << "' : " << <font color="#000088">error_desc</font> << endl;
-      return false;
-    }
-
-    <font color="#000088">filename</font> = <font color="#000088">_fname</font>;
-    <font color="#000088">is_open</font> = true;
-
-    <font color="#886600">// Return true only if there were no problems...</font>
-    return( <font color="#000088">fp</font>.<font color="#008800">good</font>() && !<font color="#000088">fp</font>.<font color="#008800">fail</font>() );
-  }
-</pre>
-
-<p>
-To specify a method (when not actively running it on an object of the
-appropriate class, as when we're defining it), the format used is
-"cClassName::MethodName()".  While this method opens the file, it checks each
-step of the way for potential problems.  If there is a problem, it tries to
-fix it and, failing that, simply reports it to the user.  My goal in
-including this method here is merely to give you an idea of what such a
-method looks like.
-
-<h3>The <font color="#880000">cInitFile</font> class</h3>
-
-<p>
-The cFile class alone allows a user to open a file and collect information
-from it one line at a time, but that's it.  There are no helpful
-functions that enable us to accomplish specific goals.  The cInitFile class,
-however, builds on top of cFile, and gives us methods that will be useful
-for a variety of initialization files.
-
-<p>
-Here is an edited version of its declaration:
-
-<p>
-<pre>
-  class <font color="#880000">cInitFile</font> : public <font color="#880000">cFile</font> {
-  private:
-    <font color="#880000">cStringList</font> <font color="#000088">line_list</font>;
-  public:
-    <font color="#008800">cInitFile</font>(<font color="#880000">cString</font> <font color="#000088">in_filename</font>);
-    <font color="#008800">~cInitFile</font>();
-  
-    void <font color="#008800">Load</font>();      <font color="#886600">// Load the file into memory so we can manipulate it.</font>
-    void <font color="#008800">Compress</font>();  <font color="#886600">// Remove all Comments and Whitespace.</font>
-  
-    void <font color="#008800">AddLine</font>(<font color="#880000">cString</font> & <font color="#000088">in_string</font>);  <font color="#886600">// Add a line to beginning of memory.</font>
-    <font color="#880000">cString</font> <font color="#008800">RemoveLine</font>();               <font color="#886600">// Remove first line from memory.</font>
-    <font color="#880000">cString</font> <font color="#008800">GetLine</font>(<font color="#880000">int</font> <font color="#000088">line_num</font>=0);    <font color="#886600">// Get specified line from memory.</font>
-
-    <font color="#880000">int</font> <font color="#008800">GetNumLines</font>() const { return <font color="#000088">line_list</font>.<font color="#008800">GetSize</font>(); }
-
-    <font color="#886600">// Find a keyword in the specified column. Stop at first occurrence and
-    // set in_string to the full line it was found in.</font>
-    <font color="#880000">bool</font> <font color="#008800">Find</font>(<font color="#880000">cString</font> & <font color="#000088">in_string</font>, const <font color="#880000">cString</font> & <font color="#000088">keyword</font>, <font color="#880000">int</font> <font color="#000088">col</font>) const;
-  
-    <font color="#886600">// Find an entry the keyword in first column.  Return the *remainder* of
-    // the line.  If not found, just return the default value given.</font>
-    <font color="#880000">cString</font> <font color="#008800">ReadString</font>(const <font color="#880000">cString</font> & <font color="#000088">keyword</font>, <font color="#880000">cString</font> <font color="#000088">def</font>="") const;
-  };
-</pre>
-
-<p>
-The cInitFile class has a <font color="#880000">cStringList</font> data
-member called <font color="#000088">line_list</font> that can contain a
-collection of "strings", in this case lines loaded from the file in question.
-The <font color="#008800">Load()</font> method is the one that copies all of
-the lines from the file into line_list, and then the
-<font color="#008800">Compress()</font> method will remove all comments
-(in this case, anything after a <tt>#</tt> on a line), compress all
-sequential spaces and tabs down to a single space, and completely remove any
-lines that then have nothing left on them.  The
-<font color="#008800">AddLine()</font> and
-<font color="#008800">RemoveLine()</font> methods allow you to directly
-change the contents of memory, while, <font color="#008800">GetLine()</font>
-allows you to retrieve a line at a specified position.
-The next method in this group is <font color="#008800">GetNumLines()</font>,
-which is exactly what it sounds -- it will return the number of lines
-currently in memory.
-
-
-<p>
-Finally, we have a pair of methods that allow us to search through the memory
-in a more useful manner.  The <font color="#008800">Find()</font> method
-seeks out a keyword in a specific column from the loaded file.  It 
-returns <tt>true</tt> or <tt>false</tt> depending on if that keyword
-was found, and it will fill out the input variable
-<font color="#000088">in_string</font> with the contents of the full line
-that the keyword was found in.  The other method,
-<font color="#008800">ReadString()</font>, is only a slight variation on
-Find().  It takes a keyword, searches for it as the first word on any line
-in the file, and then returns the remainder of the line.  If the keyword was
-nowhere to be found in the file, it will instead return a default value
-specified by the user.  Below is the definition of these two functions,
-as found in <tt>file.cc</tt>.
-
-<p>
-<pre>
-  <font color="#880000">bool</font> <font color="#880000">cInitFile</font>::<font color="#008800">Find</font>(<font color="#880000">cString</font> & <font color="#000088">in_string</font>, const <font color="#880000">cString</font> & <font color="#000088">keyword</font>,
-                       <font color="#880000">int</font> <font color="#000088">col</font>) const
-  {
-    <font color="#886600">// Loop through all of the lines until we find our keyword.</font>
-    <font color="#880000">cStringIterator</font> <font color="#000088">list_it</font>(<font color="#000088">line_list</font>);
-    while ( <font color="#000088">list_it</font>.<font color="#008800">AtEnd</font>() == false ) {
-      <font color="#000088">list_it</font>.<font color="#008800">Next</font>();
-      <font color="#880000">cString</font> <font color="#000088">cur_string</font> = <font color="#000088">list_it</font>.<font color="#008800">Get</font>();
-      if (<font color="#000088">cur_string</font>.<font color="#008800">GetWord</font>(<font color="#000088">col</font>) == <font color="#000088">keyword</font>) {
-        <font color="#000088">in_string</font> = <font color="#000088">cur_string</font>;
-        return true;
-      }
-    }
-
-    return false;    <font color="#886600">// Not Found...</font>
-  }
-
-
-  <font color="#880000">cString</font> <font color="#880000">cInitFile</font>::<font color="#008800">ReadString</font>(const <font color="#880000">cString</font> & <font color="#000088">name</font>, <font color="#880000">cString</font> <font color="#000088">def</font>) const
-  {
-    <font color="#886600">// See if we definitely can't find the keyword.</font>
-    if (<font color="#000088">name</font> == "" || <font color="#008800">IsOpen</font>() == false) return <font color="#000088">def</font>;
-
-    <font color="#886600">// Search for the keyword.</font>
-    <font color="#880000">cString</font> <font color="#000088">cur_line</font>;
-    if ( <font color="#008800">Find</font>(<font color="#000088">cur_line</font>, <font color="#000088">name</font>, 0) == false ) {
-      if (<font color="#000088">verbose</font> == true) {
-        <font color="#000088">cerr</font> &lt;&lt; "Warning: " &lt;&lt; <font color="#000088">name</font> &lt;&lt; " not in \"" &lt;&lt; <font color="#008800">GetFilename</font>()
-             &lt;&lt; "\", defaulting to: " &lt;&lt; <font color="#000088">def</font> &lt;&lt; endl;
-      }
-      return <font color="#000088">def</font>;
-    }
-
-    <font color="#886600">// Pop off the keyword, and return the remainder of the line.</font>
-    <font color="#000088">cur_line</font>.<font color="#008800">PopWord</font>();
-    return <font color="#000088">cur_line</font>;
-  }
-
-</pre>
-
-
-<p>
-This ReadString() method is one of the main ones that we use when
-dealing with the genesis file.  In order to find the value of a specific
-setting in genesis, we can run ReadString() with the name of that setting as
-a keyword, and its value will be returned.  We can specify a default
-for everything in case the user does not fill out genesis fully.  This will
-all be explained in more detail in the next document.
-
-
-<h3>The <font color="#880000">cGenesis</font> class</h3>
-
-<p>
-The cGenesis class extends cInitFile to add additional functionality that is 
-specific to reading in the genesis file.  It does not contain 
-new data, but it does have new methods.  Here is a simplified version of the
-class declaration:
-
-<pre>
-  class <font color="#880000">cGenesis</font> : public <font color="#880000">cInitFile</font> {
-  public:
-    <font color="#008800">cGenesis</font>(const <font color="#880000">cString</font> & <font color="#000088">_fname</font>);
-    <font color="#008800">~cGenesis</font>();
-
-    <font color="#886600">// This Open command will run Open() from cInitFile, but then it will
-    // also automatically Load() and Compress() the contents.</font>
-    <font color="#880000">int</font> <font color="#008800">Open</font>(<font color="#880000">cString</font> <font color="#000088">_fname</font>, <font color="#880000">int</font> <font color="#000088">mode</font>=(<font color="#880000">ios</font>::<font color="#000088">in</font>|<font color="#880000">ios</font>::<font color="#000088">nocreate</font>));
-
-    <font color="#886600">// Functions to add more data to a loaded genesis file (they use AddLine())</font>
-    void <font color="#008800">AddInput</font>(const <font color="#880000">cString</font> & <font color="#000088">in_name</font>, <font color="#880000">int</font> <font color="#000088">in_value</font>);
-    void <font color="#008800">AddInput</font>(const <font color="#880000">cString</font> & <font color="#000088">in_name</font>, const <font color="#880000">cString</font> & <font color="#000088">in_value</font>);
-
-    <font color="#886600">// Functions to read in integer or floating point values set in genesis.</font>
-    <font color="#880000">int</font> <font color="#008800">ReadInt</font>(const <font color="#880000">cString</font> & <font color="#000088">name</font>, <font color="#880000">int</font> <font color="#000088">base</font>=0, <font color="#880000">bool</font> <font color="#000088">warn</font>=true) const;
-    <font color="#880000">double</font> <font color="#008800">ReadFloat</font>(const <font color="#880000">cString</font> & <font color="#000088">name</font>, <font color="#880000">float</font> <font color="#000088">base</font>=0.0, <font color="#880000">bool</font> <font color="#000088">warn</font>=true) const;
-};
-</pre>
-
-<p>
-In this class, the <font color="#008800">Open()</font> method overloads the
-one from cInitFile such that it will automatically also call
-<font color="#880000">cInitFile</font>::<font color="#008800">Load()</font>
-and
-<font color="#880000">cInitFile</font>::<font color="#008800">Compress()</font>
-inside of it.
-
-<p>
-The two <font color="#008800">AddInput</font>() methods are used to add new
-values to the memory image of the genesis file that will take precedence over
-any loaded directly from the file.  This is made use of when the user
-activates Avida with a command line option that has higher priority than a
-genesis setting.  Note
-that even though both of these methods go by the identical name, C++ knows
-which one you are intending to call by the variables passed into
-it.  In this case, either an integer or a string will be used as the
-second argument.
-
-<p>
-Finally, the <font color="#008800">ReadInt</font>() and
-<font color="#008800">ReadFloat</font>() methods are used to obtain settings
-from the genesis file that are in integer or floating point form respectively.
-All these really do are to call
-<font color="#880000">cInitFile</font>::<font color="#008800">ReadString</font>()
-and then convert the resulting string into the desired type.
-
-<p>
-So how do we use this cGenesis class to load in and make use of
-the initialization file by the same name?  For that, you'll need to read
-about the cConfig class in the next document.
-
-<br><hr>
-Project hosted by:<br>
-<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=46761&type=2" width="125" height="37" border="0" alt="SourceForge.net"/></a>
-    
\ No newline at end of file

Modified: development/documentation/index.html
===================================================================
--- development/documentation/index.html	2006-08-30 20:08:33 UTC (rev 909)
+++ development/documentation/index.html	2006-08-30 21:03:41 UTC (rev 910)
@@ -44,16 +44,18 @@
 <p>
 <a href="code_c++_intro.html">A Conceptual Introduction to C++ in Avida</a>
 <br /><a href="code_death_birth.html">Guide to the Death/Birth Cycle</a>
-<br /><a href="code_init_file.html">Guide to Initialization Files</a>
 <br /><a href="code_life_cycle.html">Guide to an Avidan Life Cycle</a>
+<br /><a href="code_genome.html">The Building Blocks of the Virtual CPU</a>
+<br /><a href="code_environment.html">The Environment Source Code</a>
 </p>
 <p>
-<a href="code_instruction.html">Implementing New Instructions</a>
-<br /><a href="code_environment.html">The Environment Source Code</a>
+<a href="code_standards.html">Coding Standards</a>
+<br /><a href="code_instruction.html">Instruction Implemention Checklist</a>
+<br /><a href="code_task.html">Environment Task Implementation Checklist</a>
 </p>
 
 <div>
-Revised 2006-08-28 DMB
+Revised 2006-08-30 DMB
 </div>
 
 </body>

Modified: development/source/main/cGenome.h
===================================================================
--- development/source/main/cGenome.h	2006-08-30 20:08:33 UTC (rev 909)
+++ development/source/main/cGenome.h	2006-08-30 21:03:41 UTC (rev 910)
@@ -42,13 +42,13 @@
   cGenome(const cString& in_string);
   virtual ~cGenome();
 
-  virtual void operator=(const cGenome & other_genome);
-  virtual bool operator==(const cGenome & other_genome) const;
-  virtual bool operator!=(const cGenome & other_genome) const { return !(this->operator==(other_genome)); }
-  virtual bool operator<(const cGenome & other_genome) const { return AsString() < other_genome.AsString(); }
+  virtual void operator=(const cGenome& other_genome);
+  virtual bool operator==(const cGenome& other_genome) const;
+  virtual bool operator!=(const cGenome& other_genome) const { return !(this->operator==(other_genome)); }
+  virtual bool operator<(const cGenome& other_genome) const { return AsString() < other_genome.AsString(); }
 
-  cInstruction & operator[](int index) { assert(index >= 0 && index < active_size);  return genome[index]; }
-  const cInstruction & operator[](int index) const { assert(index >= 0 && index < active_size);  return genome[index]; }
+  cInstruction& operator[](int index) { assert(index >= 0 && index < active_size);  return genome[index]; }
+  const cInstruction& operator[](int index) const { assert(index >= 0 && index < active_size);  return genome[index]; }
 
   virtual void Copy(int to, int from);
 

Modified: development/source/main/cInstruction.cc
===================================================================
--- development/source/main/cInstruction.cc	2006-08-30 20:08:33 UTC (rev 909)
+++ development/source/main/cInstruction.cc	2006-08-30 21:03:41 UTC (rev 910)
@@ -13,18 +13,18 @@
 
 char cInstruction::GetSymbol() const
 {
-  if (operand < 26) return operand + 'a';
-  if (operand < 52) return operand - 26 + 'A';
-  if (operand < 62) return operand - 52 + '0';
-  if (operand == 255) return '_';
+  if (m_operand < 26) return m_operand + 'a';
+  if (m_operand < 52) return m_operand - 26 + 'A';
+  if (m_operand < 62) return m_operand - 52 + '0';
+  if (m_operand == 255) return '_';
   return  '?';
 }
 
 void cInstruction::SetSymbol(char symbol)
 {
-  if (symbol >= 'a' && symbol <= 'z') operand = symbol - 'a';
-  else if (symbol >= 'A' && symbol <= 'Z') operand = symbol - 'A' + 26;
-  else if (symbol >= '0' && symbol <= '9') operand = symbol - '0' + 52;
-  else operand = 254;
+  if (symbol >= 'a' && symbol <= 'z') m_operand = symbol - 'a';
+  else if (symbol >= 'A' && symbol <= 'Z') m_operand = symbol - 'A' + 26;
+  else if (symbol >= '0' && symbol <= '9') m_operand = symbol - '0' + 52;
+  else m_operand = 254;
 }
 

Modified: development/source/main/cInstruction.h
===================================================================
--- development/source/main/cInstruction.h	2006-08-30 20:08:33 UTC (rev 909)
+++ development/source/main/cInstruction.h	2006-08-30 21:03:41 UTC (rev 910)
@@ -20,23 +20,23 @@
 class cInstruction
 {
 private:
-  unsigned char operand;
+  unsigned char m_operand;
 
 public:
   // Constructors and Destructor...
-  cInstruction() { operand = 0; }
-  cInstruction(const cInstruction& _inst) { *this = _inst; }
+  cInstruction() : m_operand(0) { ; }
+  cInstruction(const cInstruction& inst) { *this = inst; }
   explicit cInstruction(int in_op) { SetOp(in_op); }
   ~cInstruction() { ; }
   
   // Accessors...
-  int GetOp() const { return (int) operand; }
-  void SetOp(int in_op) { assert(in_op < 256); operand = in_op; }
+  int GetOp() const { return static_cast<int>(m_operand); }
+  void SetOp(int in_op) { assert(in_op < 256); m_operand = in_op; }
 
   // Operators...
-  void operator=(const cInstruction & inst) { if (this != &inst) operand = inst.operand; }
-  bool operator==(const cInstruction & inst) const { return (operand == inst.operand); }
-  bool operator!=(const cInstruction & inst) const { return !(operator==(inst)); }
+  void operator=(const cInstruction& inst) { if (this != &inst) m_operand = inst.m_operand; }
+  bool operator==(const cInstruction& inst) const { return (m_operand == inst.m_operand); }
+  bool operator!=(const cInstruction& inst) const { return !(operator==(inst)); }
 
   // Some extra methods to convert too and from alpha-numeric symbols...
   char GetSymbol() const;




More information about the Avida-cvs mailing list