00001
00002 #include <string>
00003 #include <map>
00004 #include "keyValuePair.h"
00005
00006 using namespace std;
00007
00008 class KeyRing {
00009 private:
00010 class KValue {
00011 protected:
00012 int mySize ;
00013 KeyType myType ;
00014 public:
00015 KeyType type () {return (myType) ;} ;
00016 int size () {return (mySize) ;} ;
00017 } ;
00018 class IntArray : public KValue {
00019 int* myValues ;
00020 public:
00021 int* value () {return (myValues) ;};
00022 IntArray (const int* values, int size) {
00023 myValues = new int[size] ;
00024 for (int element = 0 ; element < size ; element++) {
00025 myValues[element] = values[element] ;
00026 }
00027 mySize = size ;
00028 myType = KT_INT;
00029 } ;
00030 ~IntArray () {delete [] myValues ;} ;
00031 } ;
00032 class FloatArray : public KValue {
00033 float* myValues ;
00034 public:
00035 float* value () {return (myValues) ;};
00036 FloatArray (const float* values, int size) {
00037 myValues = new float[size] ;
00038 for (int element = 0 ; element < size ; element++) {
00039 myValues[element] = values[element] ;
00040 }
00041 mySize = size ;
00042 myType = KT_FLOAT;
00043 } ;
00044 ~FloatArray () {delete [] myValues ;} ;
00045 } ;
00046 class StringValue : public KValue {
00047 string myValue ;
00048 public:
00049 string value () {return (myValue) ;} ;
00050 StringValue (string value) {
00051 myValue = value ;
00052 mySize = value.size () ;
00053 myType = KT_STRING;
00054 } ;
00055 } ;
00056
00057 typedef map<string,KValue*> KvMap ;
00058 KvMap myMap ;
00059 int keyCount ;
00060 public:
00061 KeyRing () ;
00062 KeyRing (char* buffer) ;
00063 ~KeyRing () ;
00064
00065
00066 void dump () ;
00067 KvpErrorCode error () { return (kvpError()) ;} ;
00068 string errorString () { return (kvpErrorString(kvpError())) ;} ;
00069 string errorString (KvpErrorCode code) { return (kvpErrorString(code)) ;} ;
00070
00071
00072 void addKey (string key, int value) ;
00073 void addKey (const string key, const int* values, int size) ;
00074 void addKey (string key, float value) ;
00075 void addKey (string key, string value) ;
00076
00077
00078 int intKey (string key) ;
00079 float floatKey (string key) ;
00080 string stringKey (string key) ;
00081
00082 int intArray (const string key, int* array, int maxLength) ;
00083
00084
00085 void write (int stream = 1) ;
00086 } ;