home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / object / data.1 / tutorial.h < prev    next >
C/C++ Source or Header  |  1996-09-25  |  7KB  |  186 lines

  1.  
  2. #ifndef TUTORIAL_H
  3. #define TUTORIAL_H
  4.  
  5. #include <fstream.h>
  6.  
  7. // forward references are ignored.
  8. class Insect;
  9. class Honey;
  10.  
  11. ////////////////////////////////////////////////////////////////////////
  12. // This is a simple enum to provide a simple Boolean type.  When the ISO
  13. // C++ standard is finished, *and* most compilers implement, it we will
  14. // not have to do this any more.  Object Outline can document and hyperlink
  15. // enumerates types.  The values comments following the Bool are also 
  16. // extracted.
  17. enum Bool
  18.   {
  19.   false = 0, // This means that the value is false i.e. zero.
  20.   true       // This means that the value is true, i.e. 1.
  21.   };
  22.  
  23. /*******************************************************************************
  24.  * CLASSNAME:   Flower                                                         *
  25.  *                                                                             *
  26.  * DESCRIPTION: This class is a Flower.  The Flower gives an Insect the        *
  27.  *              Pollen object.  The Pollen in turn is used to create Honey.    *
  28.  *              If the Flower does not have any Pollen left, it will return    *
  29.  *              false when AnyPollenLeft is called. Please note how the end    *
  30.  *              user documentation has all the stars removed and the paragraph *
  31.  *              correctly word wraps.  Just to prove it, resize your screen    *
  32.  *              and watch how the paragraph still looks OK.                    *
  33.  *******************************************************************************/
  34. class Flower
  35.   {
  36.   public:
  37.     Flower() {nPollenPods = 2; }
  38.     ~Flower() {};
  39.  
  40.     Bool AnyPollenLeft() const  { if (nPollenPods != 0) return true; return false; }
  41.     void GetPollen(Insect *)    { --nPollenPods; }
  42.  
  43.   private:
  44.     // not allowed
  45.     Flower(const Flower ©me);
  46.     Flower& operator=(const Flower ©me);
  47.  
  48.     unsigned nPollenPods;
  49.   };
  50.  
  51. // CLASS: Pollen
  52. //
  53. // DESCRIPTION:  This class does not do much except show an example of the comment filtering
  54. //               in Object Outline.
  55. //
  56. // CHANGE LOG:
  57. //               1/1/1 - class first created.
  58. //               1/2/1 - class missing dtor
  59. //               1/3/1 - class description beefed up.
  60. //               Please note that this information is of no value to the users
  61. //               of Pollen and should not appear in the finial documentation.
  62. //               What we do is define "DESCRIPTION" and "CHANGE LOG" as tags in the
  63. //               Object Outline configuration file.  We then tell Object Outline
  64. //               to remove the text before "DESCRIPTION" and after "CHANGE LOG"
  65. //               This leaves only the useful description sentence left in the
  66. //               final document.
  67. class Pollen
  68.   {
  69.   public:
  70.     // creates a Pollen Object
  71.     Pollen()  { a=0; b=0; }
  72.  
  73.     // wipes out the Pollen Object.
  74.     ~Pollen() {}
  75.  
  76.     // This is some public data, please notice how Object Outline
  77.     int    a; // knows that all of this comment belongs to a
  78.               // even if it appears after the declaration.
  79.  
  80.     // This is some more public data that Object Outline correctly
  81.     int    b; // separated from a.  You write your comments the
  82.               // way you always do and let Object Outlines deal with it.
  83.   private:
  84.     // This is a private member functions, they are not documented because
  85.     // clients of Pollen should not have to know about them.
  86.     void PrivateFunction() {};
  87.   };
  88.  
  89. /*
  90. CLASSNAME:   Insect
  91.  
  92. DESCRIPTION: This class is a simple class that describes an insect.  The Insect
  93.              is a small animal that may or may not fly and can have anywhere from four
  94.              legs to several hundred.  This class provides a common protocol
  95.              for other parts of the system to get at this information.  Please
  96.              notice that Insect and BumbleBee are automatically hyperlinked.  Also
  97.              notice that the next section is automatically documented in a
  98.              fixed space font, where as this section is a free flowing
  99.              paragraph.  The end result is that the example code is appropriately
  100.              formatted and this paragraph looks good.
  101.              
  102.              example:
  103.  
  104.              void EatTheInsect(const Insect &insect)
  105.                {
  106.                if (insect.CanFly() != false)
  107.                  {
  108.                  ... eat the insect
  109.                  }
  110.                else
  111.                  {
  112.                  // it is hard to eat insects that can fly.
  113.                  }
  114.                }
  115. */
  116. class Insect
  117.   {
  118.   public:
  119.     Insect() {};
  120.     Insect(int,int,const Honey &);
  121.     virtual ~Insect()                  {}
  122.     virtual Bool CanFly() const = 0;
  123.   };
  124.  
  125. class Honey
  126.   //**
  127.   // This is the honey class.  Not all Insect classes can make it so only the
  128.   // BumbleBee is allows to create it.  Some people like to put class comments
  129.   // before the first brace.  This style is also supported by Object Outline.
  130.   //**
  131.   {
  132.   public:
  133.     Honey()  {};
  134.     ~Honey() {};
  135.  
  136.     void Display(ostream &out) const { out << "Yum, Yum, Yum!!"; }
  137.   };
  138.  
  139. // dumps the Honey Object to the ostream.
  140. inline ostream& operator<<(ostream &out,const Honey &dumpme)
  141.   {
  142.   dumpme.Display(out);
  143.   return out;
  144.   }
  145.  
  146. /****************************************************************************
  147. CLASSNAME:   BumbleBee 
  148.  
  149. DESCRIPTION: This is a class that represents a bumble bee.  Because it
  150.              inherits from the Insect it can be used everywhere an Insect
  151.              class is needed.  It also has some functionality that not all insects
  152.              have.  It can make Honey.  Note that classes with many functions
  153.              get a function summary list and that Insect is automatically linked
  154.              back to its definition.
  155. *****************************************************************************/
  156. class BumbleBee : public Insect
  157.   {
  158.   public:
  159.     BumbleBee() {};
  160.     virtual ~BumbleBee() {};
  161.  
  162.     Bool CanFly() const;
  163.  
  164.     // a small description that is discarded in favor of the longer description
  165.     // in the source file.
  166.     Honey GetHoney() const;
  167.  
  168.     void Function01() const;
  169.     void Function02() const;
  170.     void Function03() const;
  171.     void Function04() const;
  172.     void Function05() const;
  173.     void Function06() const;
  174.   protected:
  175.     void Function07() const;
  176.     void Function08() const;
  177.     void Function09() const;
  178.     void Function10() const;
  179.     void Function11() const;
  180.   };
  181.  
  182. #endif
  183.  
  184.  
  185.  
  186.