arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

Keys.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     3-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 ///Keys.cpp
00019 
00020 #include "Keys.h"
00021 
00022 ///////////////////////////////////////////////////////////////////
00023 /// Construct
00024 ///////////////////////////////////////////////////////////////////
00025 Key::Key() 
00026 : _name("unnamed"), _type(UNKNOWN),
00027   DVEC_UNUSED(gutz::vec4d(std::numeric_limits<double>::quiet_NaN())),
00028   IVEC_UNUSED(gutz::vec4i(std::numeric_limits<int>::min())),
00029   _dv(DVEC_UNUSED),
00030   _iv(IVEC_UNUSED)
00031 {
00032 
00033 }
00034 
00035 Key::Key(const std::string &name, int type, const KeyPair *subKeys, int nSubKeys) 
00036 : _name(name), _type(type), 
00037   DVEC_UNUSED(gutz::vec4d(std::numeric_limits<double>::quiet_NaN())),
00038   IVEC_UNUSED(gutz::vec4i(std::numeric_limits<int>::min())),
00039   _dv(DVEC_UNUSED),
00040   _iv(IVEC_UNUSED)
00041 {
00042    if(subKeys && nSubKeys)
00043    {
00044       for(int i=0; i<nSubKeys; ++i)
00045       {
00046          addKey(subKeys[i].kn, KeySP(new Key(subKeys[i].key)));
00047       }
00048    }
00049 }
00050 
00051 ///////////////////////////////////////////////////////////////////
00052 /// Construct
00053 ///////////////////////////////////////////////////////////////////
00054 Key::~Key() 
00055 {
00056 }
00057 
00058 ///////////////////////////////////////////////////////////////////
00059 /// get
00060 ///////////////////////////////////////////////////////////////////
00061 KeySP    Key::getKey(const GKeyType kn) const
00062 {
00063    KeySPMap::const_iterator kmi = _keys.find(kn);
00064    if(kmi == _keys.end())
00065    {
00066       derr("getKey(), key not found", kn.c_str());
00067       return KeySP(0);
00068    }
00069 
00070    return (*kmi).second;
00071 }
00072 
00073 ///////////////////////////////////////////////////////////////////
00074 /// set
00075 ///////////////////////////////////////////////////////////////////
00076 KeySP    Key::setKey(const GKeyType kn, const KeySP key)
00077 {
00078    KeySPMapIter kmi = _keys.find(kn);
00079    if(kmi == _keys.end())
00080    {
00081       derr("setKey(), key not found, cannot set", kn.c_str());
00082       return KeySP(0);
00083    }
00084    (*kmi).second = key;
00085 
00086    return (*kmi).second;
00087 }
00088 
00089 ///////////////////////////////////////////////////////////////////
00090 /// add
00091 ///////////////////////////////////////////////////////////////////
00092 KeySP    Key::addKey(const GKeyType kn, const KeySP key)
00093 {
00094    KeySPMapIter kmi = _keys.find(kn);
00095    if(kmi != _keys.end())
00096    {
00097       derr("addKey(), key already in set", kn.c_str());
00098    }
00099 
00100    _keys[kn] = key;
00101 
00102    return _keys[kn];
00103 }
00104 
00105 KeySP    Key::addKey(const KeyPair kp)
00106 { 
00107    return addKey(kp.kn, KeySP(new Key(kp.key))); 
00108 }
00109 
00110 
00111 ///////////////////////////////////////////////////////////////////
00112 /// del
00113 ///////////////////////////////////////////////////////////////////
00114 KeySP    Key::delKey(const GKeyType kn)
00115 {
00116    KeySPMapIter kmi = _keys.find(kn);
00117    if(kmi == _keys.end())
00118    {
00119       derr("delKey(), key not found ", kn.c_str());
00120       return KeySP(0);
00121    }
00122    KeySP ret = (*kmi).second;
00123    _keys.erase(kmi);
00124    return ret;
00125 }
00126 
00127 ///////////////////////////////////////////////////////////////////
00128 /// has key
00129 ///////////////////////////////////////////////////////////////////
00130 bool     Key::hasKey(const GKeyType kn) const
00131 {
00132    if(_keys.find(kn) == _keys.end()) return false;
00133    return true;
00134 }
00135 
00136 

Send questions, comments, and bug reports to:
jmk