home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Photo CD Demo 1
/
Demo.bin
/
graphtal
/
productn.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-19
|
3KB
|
112 lines
/*
* Production.h - class definition for L-System productions.
*
* Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
* All rights reserved.
*
* This software may be freely copied, modified, and redistributed
* provided that this copyright notice is preserved on all copies.
*
* You may not distribute this software, in whole or in part, as part of
* any commercial product without the express consent of the authors.
*
* There is no warranty or other guarantee of fitness of this software
* for any purpose. It is provided solely "as is".
*
*/
#ifndef Production_H
# define Production_H
#include "Globals.h"
#include "list.h"
#include "Module.h"
#include "Name.h"
//___________________________________________________________ Predecessor
struct Predecessor
{
Predecessor(const Name&, NameList*);
~Predecessor();
Name name;
NameList* formalParam; // we need the names of the formal parameters
// for the << operator
};
//___________________________________________________________ Successor
class Successor
{
public:
Successor(double, ProdModuleList*);
~Successor();
double& probability();
ModuleList* clone();
friend ostream& operator<<(ostream&, Successor&);
private:
double _probability;
ProdModuleList* modules;
};
typedef Successor* SuccessorPtr;
declareList(SuccessorList, SuccessorPtr);
inline double& Successor::probability() {
return _probability;
}
//___________________________________________________________ Production
//
// A production of an L-System has tree parts: the predecessor, the
// condition and a successor list.
class Production
{
public:
Production(Predecessor*, Expression*, SuccessorList*);
~Production();
int hashValue();
int argCount() const;
const Name& name() const;
int cumulateProbability();
int evalCondition();
ModuleList* cloneSuccessor();
friend ostream& operator<<(ostream&, Production&);
private:
Name _name; // copy of the predecessor name
int arg_count;
int stochastic; // more than one successor => Yes: choose by random
Predecessor* predecessor;
Expression* condition;
SuccessorList* successors;
};
typedef Production* ProductionPtr;
declareList(ProductionList, ProductionPtr);
inline int Production::argCount() const {
return arg_count;
}
inline const Name& Production::name() const {
return _name;
}
inline int Production::evalCondition() {
if (condition)
return (real(condition->evaluate()) ? 1 : 0);
else
return 1;
}
#endif // Production_H