KeyRing Class Reference

#include <KeyRing.h>

List of all members.

Classes

class  FloatArray
class  IntArray
class  KValue
class  StringValue

Public Member Functions

 KeyRing ()
 KeyRing (char *buffer)
 ~KeyRing ()
void dump ()
KvpErrorCode error ()
string errorString ()
string errorString (KvpErrorCode code)
void addKey (string key, int value)
void addKey (const string key, const int *values, int size)
void addKey (string key, float value)
void addKey (string key, string value)
int intKey (string key)
float floatKey (string key)
string stringKey (string key)
int intArray (const string key, int *array, int maxLength)
void write (int stream=1)

Private Types

typedef map< string, KValue * > KvMap

Private Attributes

KvMap myMap
int keyCount

Detailed Description

Definition at line 8 of file KeyRing.h.


Member Typedef Documentation

typedef map<string,KValue*> KeyRing::KvMap [private]

Definition at line 57 of file KeyRing.h.


Constructor & Destructor Documentation

KeyRing::KeyRing (  ) 

Definition at line 6 of file KeyRing.cc.

References keyCount.

00007 {
00008    keyCount = 0 ;
00009 }

KeyRing::KeyRing ( char *  buffer  ) 

Definition at line 11 of file KeyRing.cc.

References addKey(), keyCount, KT_FLOAT, KT_INT, KT_INVALID, KT_STRING, kvpGetEntry(), kvpGetFloat(), kvpGetIntArray(), kvpParse(), and size.

00012 {
00013    char* key ;
00014    KeyType type ;
00015    int* ivalues ;
00016    float fval ;
00017    char* csval ;
00018    int size ;
00019 
00020    keyCount = kvpParse (buffer) ;
00021    for (int entry = 0 ; entry < keyCount ; entry++) {
00022       kvpGetEntry (entry, &key, &type, &size, &csval) ;
00023       switch (type) {
00024       case KT_INT:
00025          ivalues = new int[size] ;
00026          kvpGetIntArray (key, ivalues, &size) ;
00027          addKey (key, ivalues, size) ;
00028          delete [] ivalues ;
00029          break ;
00030       case KT_FLOAT:
00031          fval = kvpGetFloat (key, 0) ;
00032          addKey (key, fval) ;
00033          break ;
00034       case KT_STRING:
00035          addKey (key, csval) ;
00036          break ;
00037       case KT_INVALID:
00038          // Ignore it
00039          break;
00040       }
00041    }
00042 }

KeyRing::~KeyRing (  ) 

Definition at line 44 of file KeyRing.cc.

References myMap.

00045 {
00046    for (KvMap::iterator kvIter = myMap.begin () ; kvIter != myMap.end () ;
00047         kvIter++) {
00048       delete (*kvIter).second ;
00049    }
00050 
00051 }


Member Function Documentation

void KeyRing::addKey ( string  key,
string  value 
)

Definition at line 65 of file KeyRing.cc.

References myMap.

00066 {
00067    myMap.insert (KvMap::value_type (key, new StringValue (value))) ;
00068 }

void KeyRing::addKey ( string  key,
float  value 
)

Definition at line 61 of file KeyRing.cc.

References myMap.

00062 {
00063    myMap.insert (KvMap::value_type (key, new FloatArray (&value, 1))) ;
00064 }

void KeyRing::addKey ( const string  key,
const int *  values,
int  size 
)

Definition at line 57 of file KeyRing.cc.

References myMap.

00058 {
00059    myMap.insert (KvMap::value_type (key, new IntArray (values, size))) ;
00060 }

void KeyRing::addKey ( string  key,
int  value 
)

Definition at line 53 of file KeyRing.cc.

References myMap.

Referenced by KeyRing(), and main().

00054 {
00055    myMap.insert (KvMap::value_type (key, new IntArray (&value, 1))) ;
00056 }

void KeyRing::dump (  ) 

Definition at line 70 of file KeyRing.cc.

References KT_FLOAT, KT_INT, KT_INVALID, KT_STRING, myMap, KeyRing::KValue::size(), KeyRing::IntArray::value(), KeyRing::StringValue::value(), and KeyRing::FloatArray::value().

Referenced by main().

00071 {
00072    IntArray* iarray ;
00073    FloatArray* farray ;
00074    StringValue* sval ;
00075    int* ivals ;
00076    float* fvals ;
00077 
00078    for (KvMap::iterator kvIter = myMap.begin () ; kvIter != myMap.end () ;
00079         kvIter++) {
00080       cout << "key : <" << (*kvIter).first << ">,  type : " ;
00081       switch ((*kvIter).second->type()) {
00082       case KT_INT:
00083          iarray = (IntArray*) (*kvIter).second ;
00084          cout << "int,  value :" ;
00085          ivals = iarray->value() ;
00086          for (int element = 0 ; element < iarray->size () ; element++) {
00087             cout << " " << ivals[element] ;
00088          }
00089          cout << endl ;
00090          break ;
00091       case KT_FLOAT:
00092          farray = (FloatArray*) (*kvIter).second ;
00093          cout << "float,  value : " ;
00094          fvals = farray->value() ;
00095          for (int element = 0 ; element < farray->size () ; element++) {
00096             cout << " " << fvals[element] ;
00097          }
00098          cout << endl ;
00099          break ;
00100       case KT_STRING:
00101          sval = (StringValue*) (*kvIter).second ;
00102          cout << "string,  value : <" << sval->value() << ">\n" ;
00103          break ;
00104       case KT_INVALID:
00105          // Ignore it
00106          break;
00107       }
00108    }
00109 }

KvpErrorCode KeyRing::error (  )  [inline]

Definition at line 67 of file KeyRing.h.

References kvpError().

00067 { return (kvpError()) ;} ;

string KeyRing::errorString ( KvpErrorCode  code  )  [inline]

Definition at line 69 of file KeyRing.h.

References kvpErrorString().

00069 { return (kvpErrorString(code)) ;} ;

string KeyRing::errorString (  )  [inline]

Definition at line 68 of file KeyRing.h.

References kvpError(), and kvpErrorString().

00068 { return (kvpErrorString(kvpError())) ;} ;

float KeyRing::floatKey ( string  key  ) 

Definition at line 148 of file KeyRing.cc.

References KT_FLOAT, myMap, and KeyRing::FloatArray::value().

Referenced by main().

00149 {
00150    KvMap::iterator kvIter = myMap.find (key) ; 
00151    if (kvIter != myMap.end ()) {
00152       if ((*kvIter).second->type() == KT_FLOAT) {
00153          FloatArray* vptr = (FloatArray*) (*kvIter).second ;
00154          return (vptr->value()[0]) ;
00155       }
00156       else {
00157          return (HUGE) ;
00158       }
00159    }
00160    else {
00161       return (HUGE) ;
00162    }
00163 }

int KeyRing::intArray ( const string  key,
int *  array,
int  maxLength 
)

Definition at line 128 of file KeyRing.cc.

References KT_INT, myMap, KeyRing::KValue::size(), and KeyRing::IntArray::value().

Referenced by main().

00129 {
00130    KvMap::iterator kvIter = myMap.find (key) ; 
00131    if (kvIter != myMap.end ()) {
00132       if ((*kvIter).second->type() == KT_INT) {
00133          IntArray* vptr = (IntArray*) (*kvIter).second ;
00134          int length = vptr->size () ;
00135          if (length > maxLength) {
00136             length = maxLength ;
00137          }
00138          int* vals = vptr->value() ;
00139          for (int element = 0 ; element < length ; element++) {
00140             array[element] = vals[element] ;
00141          }
00142          return (length) ;
00143       }
00144    }
00145    return (0) ;
00146 }

int KeyRing::intKey ( string  key  ) 

Definition at line 111 of file KeyRing.cc.

References KT_INT, myMap, and KeyRing::IntArray::value().

Referenced by main().

00112 {
00113    KvMap::iterator kvIter = myMap.find (key) ; 
00114    if (kvIter != myMap.end ()) {
00115       if ((*kvIter).second->type() == KT_INT) {
00116          IntArray* vptr = (IntArray*) (*kvIter).second ;
00117          return (vptr->value()[0]) ;
00118       }
00119       else {
00120          return (-2) ;
00121       }
00122    }
00123    else {
00124       return (-1) ;
00125    }
00126 }

string KeyRing::stringKey ( string  key  ) 

Definition at line 164 of file KeyRing.cc.

References KT_STRING, myMap, and KeyRing::StringValue::value().

Referenced by main().

00165 {
00166    KvMap::iterator kvIter = myMap.find (key) ; 
00167    if (kvIter != myMap.end ()) {
00168       if ((*kvIter).second->type() == KT_STRING) {
00169          StringValue* vptr = (StringValue*) (*kvIter).second ;
00170          return (vptr->value()) ;
00171       }
00172       else {
00173          return (0) ;
00174       }
00175    }
00176    else {
00177       return (0) ;
00178    }
00179 }

void KeyRing::write ( int  stream = 1  ) 

Definition at line 181 of file KeyRing.cc.

References KT_FLOAT, KT_INT, KT_INVALID, KT_STRING, kvpReset(), kvpSetFloatArray(), kvpSetIntArray(), kvpSetString(), kvpWrite(), myMap, KeyRing::KValue::size(), KeyRing::IntArray::value(), KeyRing::StringValue::value(), and KeyRing::FloatArray::value().

Referenced by main().

00182 {
00183    kvpReset () ;
00184    IntArray* ival ;
00185    FloatArray* fval ;
00186    StringValue* sval ;
00187    for (KvMap::iterator kvIter = myMap.begin () ; kvIter != myMap.end () ;
00188         kvIter++) {
00189       switch ((*kvIter).second->type()) {
00190       case KT_INT:
00191          ival = (IntArray*) (*kvIter).second ;
00192          kvpSetIntArray ((*kvIter).first.c_str(),
00193                          ival->value(), ival->size()) ;
00194          break ;
00195       case KT_FLOAT:
00196          fval = (FloatArray*) (*kvIter).second ;
00197          kvpSetFloatArray ((*kvIter).first.c_str(),
00198                            fval->value(), fval->size()) ;
00199          break ;
00200       case KT_STRING:
00201          sval = (StringValue*) (*kvIter).second ;
00202          kvpSetString ((*kvIter).first.c_str(), sval->value().c_str()) ;
00203          break ;
00204       case KT_INVALID:
00205          // Ignore it
00206          break;
00207       }
00208    }
00209    kvpWrite (stream) ;
00210 }


Member Data Documentation

int KeyRing::keyCount [private]

Definition at line 59 of file KeyRing.h.

Referenced by KeyRing().

KvMap KeyRing::myMap [private]

Definition at line 58 of file KeyRing.h.

Referenced by addKey(), dump(), floatKey(), intArray(), intKey(), stringKey(), write(), and ~KeyRing().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1