/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
properties.h
*/
#ifndef _PROPERTIES_H
#define _PROPERTIES_H
#include <assert.h>
#include "nameable.h"
#include "streamable.h"
#include "io.h"
#include "hash.h"
//#define NDEBUG
enum property_type
{
PROP_UNKNOWN =0,
PROP_INT, PROP_BOOL, PROP_STRING
};
#define DEFAULT_PROPERTIES_FILE "../etc/mudpp.pro"
class Property;
typedef union
{
int i;
bool b;
String * s;
} prop_val;
typedef const char * (*notifyFun) (const Property *);
class Property : public Nameable, virtual public Streamable
{
private:
property_type type;
prop_val value;
notifyFun nfun;
bool runtime;
public:
Property() :
type(PROP_UNKNOWN), nfun(0), runtime(true)
{
value.s = 0;
}
~Property()
{
if ( (type == PROP_STRING) && (value.s) )
delete value.s;
}
Property & operator= ( const Property & );
int readFrom( StaticInput & );
int writeTo( Output &) const;
const char * asText() const;
property_type getType() const { return type; };
const char * getTypeName() const;
void setType( property_type t ) { type = t; }
notifyFun getFun() const { return nfun; }
void setFun( notifyFun f ) { nfun = f; }
const char * notify() const { return (nfun ? (*nfun)(this) : 0); }
const char * parseValue( const char * );
const char * parseValue( const String & str ) { return parseValue(str.chars()); }
void setRuntime( bool n ) { runtime = n ;}
bool getRuntime() const { return runtime; }
prop_val getValue() const { return value; }
int getInt() const { return value.i; }
bool getBool() const { return value.b; }
const String & getString() const { return *(value.s); }
};
extern HashTable< Property > properties;
void lookup_property( Property ** holder, const char * name,
property_type type, const char * defl,
notifyFun fun , bool runtime);
// See doc/properties.doc for useage hints
inline void UseProperty( Property ** holder, const char * name,
property_type type, const char * defl,
notifyFun fun = NULL, bool runtime = true )
{
if ( *holder )
{
assert( (*holder)->getName() == name );
assert( (*holder)->getType() == type );
assert( (*holder)->getFun() == fun );
return;
}
else
lookup_property( holder, name, type, defl, fun, runtime);
}
void loadProperties( StaticInput &, String & );
void saveProperties( Output & );
const char * nf_gtz( const Property *);
const char * nf_gez( const Property *);
#endif