Source: lycad_chargen/Modifier.h
|
|
|
|
/***************************************************************************
Modifier.h - description
-------------------
begin : Fri May 12 2000
copyright : (C) 2000 by Sheldon Lee Wen
email : sheldonl@linuxstart.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//**** Header for Modifier Class
#ifndef MODIFIER_H
#define MODIFIER_H
#include
#include
#include
#include "modifiereventlistener.h"
class ScopePair
{
public:
ScopePair();
ScopePair(int ind, bool val);
ScopePair(ScopePair ©);
~ScopePair();
void setValue(bool val);
void setIndex(int ind);
void setScope(bool val);
int getIndex() const; // returns 0 if index is not integer
bool getValue() const;
protected:
friend class Modifier;
/** This controls the index type. It works with integers but it's meant to
be extended to other index types if necessary */
enum IND_TYPE {IND_UNDEF, IND_INTEGER};
IND_TYPE type;
/** numeric type identifier for a scope */
int index;
/** value determines whether a modifier is in scope or not */
bool value;
};
class Modifier : public modifierListener{
public:
Modifier(int Imagnitude, int Iscope, bool IInScope);
~Modifier();
/** Set the magnitude of the modifier */
int setValue(int newValue);
/** Returns the value of magnitude */
int getValue() const { return magnitude; }
/** Sets a scope ExistingScope to be in or out of scope */
bool setScope(int ExistingScope, bool newScopeValue);
/** Returns whether the scope ExistingScope is in scope or not.
If the scope ExistingScope does not exist in the modifier return false */
bool getScope(int ExistingScope);
/** adds a scope to the modifier. Return false if the scope already exists. */
bool addScope(int IScope, bool IInScope);
/** adds a scope to the modifier using a scopepair. Return false if the scope already exists. */
bool addScope(ScopePair *newPair);
/** adds a scope to the modifier. Return false if the scope already exists. */
bool removeScope(int IScope, bool IInScope);
/** adds a scope to the modifier using a scopepair. Return false if the scope already exists. */
bool removeScope(ScopePair *newPair);
/** call updateScope() and return InScope to see if modifier is in any scope. */
bool inScope();
/** clear all scopes. */
void clear();
bool containsKey(int key);
int size() { return curSize;} // how many elements in table?
void iBegin() { if (data != NULL) { iter = data; } }
void iEnd() { if (data != NULL) { iter = data + sz - 1;} } // set iterator to the last element
ScopePair *getNext();
ScopePair *getPrev();
/** operator + */
int operator+(Modifier &rhs );
/** operator + */
int operator+(const int &rhs );
private:
/** Handle an event */
virtual void handleModifierEvent(modifierEvent *evt);
/** The magnitude of the modifier */
int magnitude;
/** InScope is true if any of the modifiers scopes are active. It is false otherwise */
bool InScope;
/** data contains a hash map of scope pairs. This map is implemented w/ an array. */
ScopePair *data;
// Stuff to handle the ScopePair list
/** size of the hash map. It is 10 by default. */
int sz;
/** number of entries currently in the data map */
int curSize;
/** max entries stored in table before it is rehashed. */
int load;
/** set percent full to 75% to avoid too many collisions */
static const float PERCENT_FULL = .75;
/** iterator pointer for traversing through map */
ScopePair *iter;
/** Hash function for the map */
int hash(int ind);
/** This is called if the map needs more space */
void rehash();
ScopePair *getNextPair(); // used in rehash
void updateScope();
};
#endif
Generated by: sheldonl on cr595811-a on Fri Nov 30 10:24:34 2001, using kdoc 2.0a53. |