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

  1. /*
  2.  * Module.h - class definition for L-System modules.
  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 Module_H
  19. # define Module_H
  20.  
  21. #include <iostream.h>
  22. #include "list.h"
  23. #include "Expression.h"
  24. #include "Name.h"
  25.  
  26. declareList(ExpressionList, ExpressionPtr);
  27. declareList(ValueList, ValuePtr);
  28.  
  29. //___________________________________________________________ Formals
  30. //
  31. // common storage access used for the formal parameters of all the
  32. // production.  Example:
  33. //
  34. //   A(l,w) -> ...  : parameter l is assigned to Formals(0) and
  35. //                    parameter w to Formals(1)
  36. // 
  37. // Now it's possible to simply assign the actual parameters of a 
  38. // module to the Formals-array and the binding is done
  39.  
  40. Value* Formals(int);
  41.  
  42. //___________________________________________________________ ProdModule
  43. //
  44. // ProdModule's are used in productions, where we need expressions
  45. //  as arguments
  46.  
  47. class ProdModule
  48. {
  49. friend class Module;
  50. public:
  51.   ProdModule(const Name&, ExpressionList*);
  52.   ~ProdModule();
  53.  
  54.   friend ostream& operator<<(ostream&, const ProdModule&);
  55.  
  56. private:
  57.   Name name;
  58.   // hashvalue is associated with the name and the number 
  59.   // of arguments
  60.   int  hashValue;
  61.   ExpressionList* parameters;
  62. };
  63.  
  64. typedef ProdModule* ProdModulePtr;
  65. declareList(ProdModuleList, ProdModulePtr);
  66.  
  67. //___________________________________________________________ Module
  68. //
  69. // The resulting module string of an L-System consists of modules
  70. //  with constant arguments. Because there are a lot of them 
  71. //  allocated, it makes sense to make a difference between the
  72. //  modules of a production (class ProdModule) and the modules of
  73. //  the resulting string (=> better space and speed efficiency)
  74.  
  75. class Module
  76. {
  77. public:
  78.   Module(ProdModule*);
  79.   ~Module();
  80.  
  81.   const Name& name() const;
  82.   int hashValue() const;
  83.   int argCount() const;
  84.   const Value* arg(int);
  85.   void bind();
  86.   friend ostream& operator<<(ostream&, const Module&);
  87.  
  88. private:
  89.   Name _name;
  90.   int  _hashValue;
  91.   ValueList* parameters;
  92. };
  93.  
  94. typedef Module* ModulePtr;
  95. declareList(ModuleList, ModulePtr);
  96.  
  97. inline const Name& Module::name() const { 
  98.   return _name; 
  99. }
  100.  
  101. inline int Module::hashValue() const {
  102.   return _hashValue; 
  103. }
  104.  
  105. inline int Module::argCount() const {
  106.   return ((parameters) ? (parameters->count())
  107.                    : 0);
  108. }
  109.  
  110. inline const Value* Module::arg(int i) {
  111.   return parameters->item(i);
  112. }
  113.  
  114. #endif // Module_H
  115.