126 lines
2.3 KiB
C++
126 lines
2.3 KiB
C++
#ifndef __vars_h__
|
|
#define __vars_h__
|
|
|
|
|
|
#pragma interface
|
|
|
|
|
|
#include <map>
|
|
#include <string>
|
|
|
|
|
|
using std::string;
|
|
using std::map;
|
|
|
|
/*
|
|
struct hash_str
|
|
{
|
|
inline size_t string_hf(const string& str)
|
|
{ return hash(str.c_str()); }
|
|
};
|
|
|
|
struct MyHASHER : public hash<const char*>{
|
|
size_t operator(string a_string){
|
|
return (*this)( a_string.c_str() );
|
|
}
|
|
}
|
|
|
|
|
|
struct eqstr
|
|
{
|
|
bool operator()(const char* s1, const char* s2) const
|
|
{
|
|
return strcmp(s1, s2) == 0;
|
|
}
|
|
};
|
|
|
|
*/
|
|
|
|
class varstring : public string
|
|
{
|
|
public:
|
|
varstring();
|
|
varstring( const varstring &c );
|
|
varstring( const string &c );
|
|
varstring( const char* c, int len);
|
|
varstring( const char *c );
|
|
|
|
long Long() const;
|
|
double Double();
|
|
varstring& operator=( const char* c );
|
|
void operator=( long l );
|
|
void operator=( const string c );
|
|
varstring& operator=( const varstring &c );
|
|
operator long(); // type conversion
|
|
operator const char*(); // type conversion
|
|
|
|
bool valid() const;
|
|
void set_valid( bool validated = true );
|
|
|
|
bool db() const;
|
|
void set_db( bool validated = true );
|
|
|
|
bool binary() const;
|
|
void set_binary( bool binary = true );
|
|
|
|
friend class CVars;
|
|
|
|
private:
|
|
bool validated;
|
|
bool db_var; // is this variable to be used in DB updates
|
|
bool binary_var;
|
|
};
|
|
|
|
/*
|
|
class string_key : public string
|
|
{
|
|
public:
|
|
string_key& operator=( const char* c );
|
|
void operator=( long l );
|
|
void operator=( const string c );
|
|
|
|
string_key();
|
|
string_key( const char *c );
|
|
|
|
bool valid() const;
|
|
void set_valid( bool validated = true );
|
|
|
|
private:
|
|
bool validated;
|
|
};
|
|
*/
|
|
|
|
|
|
typedef
|
|
// hash_map<const char*, char*, hash<const char*>, eqstr>
|
|
// map< string_key, varstring >
|
|
map< const string, varstring >
|
|
CVars1;
|
|
|
|
|
|
|
|
class CVars : public CVars1
|
|
{
|
|
public:
|
|
CVars() : CVars1() {};
|
|
|
|
CVars& operator<<( char const *name ); // schedule for db processing
|
|
CVars& operator>>( char const *name ); // ignore db processing for this variable
|
|
|
|
void ClearDB();
|
|
|
|
long serialize( unsigned char *&buf ); // this will serialize the data into buf and return the resulting size
|
|
// it is the responsibility of the caller to free the buffer with free()
|
|
int deserialize( unsigned char *buf, long buf_sz ); // this will initialize the current instance by de-serializing the data from buf
|
|
// returns number of elements de-serialized
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|