PrefixMaxKeyGenerator.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005 #include "PrefixMaxKeyGenerator.h"
00006
00007
00008
00009
00012
00013
00014
00015
00016
00017
00018
00019 PrefixMaxKeyGenerator :: PrefixMaxKeyGenerator()
00020 {
00021 numberOfKeyThings = 0;
00022 }
00023
00024
00025
00026
00027 PrefixMaxKeyGenerator :: ~PrefixMaxKeyGenerator()
00028 {
00029 clear();
00030 }
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 bool PrefixMaxKeyGenerator :: addKeyThing( std::string theName, std::string thePrefix, int theMax )
00045 {
00046 KeyThing * kThing = new KeyThing(thePrefix, theMax);
00047 int before = keyThings.size();
00048 keyThings.insert(std::pair < std::string, KeyThing >( theName, *kThing ));
00049 int after = keyThings.size();
00050 return after > before;
00051 }
00052
00053
00054
00055
00056
00057 void PrefixMaxKeyGenerator :: removeKeyThing( std::string theName )
00058 {
00059 keyThings.erase(theName);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 bool PrefixMaxKeyGenerator :: existsKeyThing( std::string theName )
00069 {
00070 return keyThings.find(theName) != keyThings.end();
00071 }
00072
00073
00074
00075
00076
00077
00078 void PrefixMaxKeyGenerator :: updateMaxTo( std::string theName, int posibleMax )
00079 {
00080 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
00081 if ( iterP != keyThings.end() )
00082 {
00083 int max = (iterP->second).getValue();
00084 if ( max < posibleMax )
00085 (iterP->second).setValue(posibleMax);
00086 }
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 bool PrefixMaxKeyGenerator :: generateKeyOf( std::string theName, std::string &theInputString )
00096 {
00097 theInputString = "";
00098 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
00099 if ( iterP != keyThings.end() )
00100 {
00101 KeyThing kthing = (iterP->second);
00102 int max = kthing.getValue();
00103 std::ostringstream genKey;
00104 genKey<<kthing.getPrefix() << " " << max;
00105 theInputString = genKey.str();
00106 return true;
00107 }
00108 return false;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 bool PrefixMaxKeyGenerator :: generateKeyOf( std::string theName, int posibleMax, std::string &theInputString )
00119 {
00120 theInputString = "";
00121 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
00122 if ( iterP != keyThings.end() )
00123 {
00124 KeyThing kthing = (iterP->second);
00125 int max = kthing.getValue();
00126
00127 if ( max < posibleMax )
00128 {
00129 kthing.setValue(posibleMax);
00130 }
00131
00132
00133 std::ostringstream genKey;
00134 genKey<<kthing.getPrefix() << " " << kthing.getValue();
00135 theInputString = genKey.str();
00136 return true;
00137 }
00138 return false;
00139 }
00140
00141
00142
00143
00144
00145
00146
00147 bool PrefixMaxKeyGenerator :: getPrefixOf( std::string theName, std::string &theInputString )
00148 {
00149 theInputString = "";
00150 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
00151 if ( iterP != keyThings.end() )
00152 {
00153 KeyThing kthing = (iterP->second);
00154 theInputString = kthing.getPrefix();
00155 return true;
00156 }
00157 return false;
00158 }
00159
00160
00161
00162
00163
00164
00165 int PrefixMaxKeyGenerator :: getCurrentMaxOf( std::string theName )
00166 {
00167 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
00168 if ( iterP != keyThings.end() )
00169 {
00170 KeyThing kthing = (iterP->second);
00171 return kthing.getValue();
00172 }
00173 return -1;
00174 }
00175
00176
00177
00178
00179
00180 int PrefixMaxKeyGenerator :: getTotalThingsNumber()
00181 {
00182 return keyThings.size();
00183 }
00184
00185
00186
00187
00188 void PrefixMaxKeyGenerator :: clear()
00189 {
00190 std::map<std::string, KeyThing >::iterator iter = keyThings.begin();
00191 while( iter != keyThings.end() )
00192 {
00193 keyThings.erase(iter);
00194 }
00195 keyThings.clear();
00196 numberOfKeyThings = 0;
00197 }