home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / productn.h < prev    next >
C/C++ Source or Header  |  1992-10-19  |  3KB  |  112 lines

  1. /*
  2.  * Production.h - class definition for L-System productions.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  */
  17.  
  18. #ifndef Production_H
  19. # define Production_H
  20.  
  21. #include "Globals.h"
  22. #include "list.h"
  23. #include "Module.h"
  24. #include "Name.h"
  25.  
  26. //___________________________________________________________ Predecessor
  27.  
  28. struct Predecessor
  29. {
  30.   Predecessor(const Name&, NameList*);
  31.   ~Predecessor();
  32.  
  33.   Name name; 
  34.   NameList* formalParam; // we need the names of the formal parameters
  35.                          // for the << operator
  36. };
  37.  
  38. //___________________________________________________________ Successor
  39.  
  40. class Successor
  41. {
  42. public:
  43.   Successor(double, ProdModuleList*);
  44.   ~Successor();
  45.  
  46.   double& probability();
  47.   ModuleList* clone();
  48.   friend ostream& operator<<(ostream&, Successor&);
  49.  
  50. private:
  51.   double _probability;
  52.   ProdModuleList* modules;
  53. };
  54.  
  55. typedef Successor* SuccessorPtr;
  56. declareList(SuccessorList, SuccessorPtr);
  57.  
  58. inline double& Successor::probability() {
  59.   return _probability;
  60. }
  61.  
  62. //___________________________________________________________ Production
  63. //
  64. // A production of an L-System has tree parts: the predecessor, the
  65. //  condition and a successor list. 
  66.  
  67. class Production
  68. {
  69. public:
  70.   Production(Predecessor*, Expression*, SuccessorList*);
  71.   ~Production();
  72.  
  73.   int hashValue();
  74.   int argCount() const;
  75.   const Name& name() const;
  76.  
  77.   int cumulateProbability();
  78.   int evalCondition();
  79.   ModuleList* cloneSuccessor();
  80.  
  81.   friend ostream& operator<<(ostream&, Production&);
  82.  
  83. private:
  84.   Name _name;     // copy of the predecessor name
  85.   int arg_count;
  86.   int stochastic; // more than one successor => Yes: choose by random
  87.  
  88.   Predecessor* predecessor;
  89.   Expression* condition;
  90.   SuccessorList* successors;
  91. };
  92.  
  93. typedef Production* ProductionPtr;
  94. declareList(ProductionList, ProductionPtr);
  95.  
  96. inline int Production::argCount() const { 
  97.   return arg_count; 
  98. }
  99.  
  100. inline const Name& Production::name() const {
  101.   return _name; 
  102. }
  103.  
  104. inline int Production::evalCondition() {
  105.   if (condition)
  106.     return (real(condition->evaluate()) ? 1 : 0);
  107.   else
  108.     return 1;
  109. }
  110.  
  111. #endif // Production_H
  112.