home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
oct93
/
graphics
/
graphtal.lha
/
Graphtal
/
LSystem.h
< prev
next >
Wrap
C/C++ Source or Header
|
1992-11-20
|
3KB
|
135 lines
/*
* LSystem.h - class definitions for classes ProductionSlot, Table
* and LSystem.
*
* Copyright (C) 1992, Christoph Streit (streit@iam.unibe.ch)
* University of Berne, Switzerland
* 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 LSystem_H
# define LSystem_H
#include "rcString.h"
#include "list.h"
#include "Hash.h"
#include "Production.h"
#include "Module.h"
//___________________________________________________________ Table Hashing
unsigned int modHash(const char*, long);
//___________________________________________________________ ProductionSlot
//
// a ProductionSlot is the basic element of a Table and is the 'home' of
// the productions with the same module name and the same number of
// arguments
class ProductionSlot
{
friend class Table;
public:
ProductionSlot(Production*);
~ProductionSlot();
void append(Production*);
int match(Production*) const;
int match(Module*) const;
private:
Name name; // module name
int argCount; // number of arguments
ProductionList* productions; // productions associated with the
// ProductionSlot
};
//___________________________________________________________ Table
//
// A Table consists of a list of productions which are stored in
// a hashed array to achieve fast module-production matching
const int HASH_ARRAY_SIZE = 503;
class Table
{
public:
Table(const Name&, ProductionList*);
~Table();
const Name& name() const;
ModuleList* execute(ModuleList*, int);
friend ostream& operator<<(ostream&, const Table&);
private:
Name _name; // table name
ProductionList* productions; // the productions stored in the table
ProductionSlot* pslots[HASH_ARRAY_SIZE];
ModuleList* result;
void rexecute(Module*, int);
ModuleList* apply(Module*);
};
typedef Table* TablePtr;
declareList(TableList, TablePtr);
inline const Name& Table::name() const {
return _name;
}
//___________________________________________________________ LSystem
//
// A L-System consists of a derivation list, an axiom and
// productions which are grouped in tables.
// The derivation list gives the order of tables to be applied
// to the axiom (= the initial module string)
struct DerivationItem
{
DerivationItem(Table* t, int s)
: table(t), steps(s) {}
Table* table;
int steps;
};
ostream& operator<<(ostream&, const DerivationItem&);
typedef DerivationItem* DerivationItemPtr;
declareList(DerivationList, DerivationItemPtr);
class LSystem
{
public:
LSystem(const Name&, TableList*, ProdModuleList*, DerivationList*);
~LSystem();
ModuleList* execute();
rcString getName() const;
friend ostream& operator<<(ostream&, const LSystem&);
private:
Name name; // the name of the l-system
TableList* tables; // tables of the l-system
ProdModuleList* axiom; // the axiom
DerivationList* derivation; // list of tables to be applied
};
inline rcString LSystem::getName() const {
return rcString((const char*)name);
}
#endif // LSystem_H