home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / graphics / graphtal.lha / Graphtal / Module.h < prev    next >
C/C++ Source or Header  |  1992-11-17  |  3KB  |  116 lines

  1. /*
  2.  * Module.h - class definition for L-System modules.
  3.  *
  4.  * Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
  5.  *                     University of Berne, Switzerland
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified, and redistributed
  9.  * provided that this copyright notice is preserved on all copies.
  10.  *
  11.  * You may not distribute this software, in whole or in part, as part of
  12.  * any commercial product without the express consent of the authors.
  13.  *
  14.  * There is no warranty or other guarantee of fitness of this software
  15.  * for any purpose.  It is provided solely "as is".
  16.  *
  17.  */
  18.  
  19. #ifndef Module_H
  20. # define Module_H
  21.  
  22. #include <iostream.h>
  23. #include "list.h"
  24. #include "Expression.h"
  25. #include "Name.h"
  26.  
  27. declareList(ExpressionList, ExpressionPtr);
  28. declareList(ValueList, ValuePtr);
  29.  
  30. //___________________________________________________________ Formals
  31. //
  32. // common storage access used for the formal parameters of all the
  33. // production.  Example:
  34. //
  35. //   A(l,w) -> ...  : parameter l is assigned to Formals(0) and
  36. //                    parameter w to Formals(1)
  37. // 
  38. // Now it's possible to simply assign the actual parameters of a 
  39. // module to the Formals-array and the binding is done
  40.  
  41. Value* Formals(int);
  42.  
  43. //___________________________________________________________ ProdModule
  44. //
  45. // ProdModule's are used in productions, where we need expressions
  46. //  as arguments
  47.  
  48. class ProdModule
  49. {
  50. friend class Module;
  51. public:
  52.   ProdModule(const Name&, ExpressionList*);
  53.   ~ProdModule();
  54.  
  55.   friend ostream& operator<<(ostream&, const ProdModule&);
  56.  
  57. private:
  58.   Name name;
  59.   // hashvalue is associated with the name and the number 
  60.   // of arguments
  61.   int  hashValue;
  62.   ExpressionList* parameters;
  63. };
  64.  
  65. typedef ProdModule* ProdModulePtr;
  66. declareList(ProdModuleList, ProdModulePtr);
  67.  
  68. //___________________________________________________________ Module
  69. //
  70. // The resulting module string of an L-System consists of modules
  71. //  with constant arguments. Because there are a lot of them 
  72. //  allocated, it makes sense to make a difference between the
  73. //  modules of a production (class ProdModule) and the modules of
  74. //  the resulting string (=> better space and speed efficiency)
  75.  
  76. class Module
  77. {
  78. public:
  79.   Module(ProdModule*);
  80.   ~Module();
  81.  
  82.   const Name& name() const;
  83.   int hashValue() const;
  84.   int argCount() const;
  85.   const Value* arg(int);
  86.   void bind();
  87.   friend ostream& operator<<(ostream&, const Module&);
  88.  
  89. private:
  90.   Name _name;
  91.   int  _hashValue;
  92.   ValueList* parameters;
  93. };
  94.  
  95. typedef Module* ModulePtr;
  96. declareList(ModuleList, ModulePtr);
  97.  
  98. inline const Name& Module::name() const { 
  99.   return _name; 
  100. }
  101.  
  102. inline int Module::hashValue() const {
  103.   return _hashValue; 
  104. }
  105.  
  106. inline int Module::argCount() const {
  107.   return ((parameters) ? (parameters->count())
  108.                    : 0);
  109. }
  110.  
  111. inline const Value* Module::arg(int i) {
  112.   return parameters->item(i);
  113. }
  114.  
  115. #endif // Module_H
  116.