2 //----------------------------------------------------------------------------------------------------------------
3 // Class definition include
4 //----------------------------------------------------------------------------------------------------------------
5 #include "PrefixMaxKeyGenerator.h"
7 //----------------------------------------------------------------------------------------------------------------
8 // Class implementation
9 //----------------------------------------------------------------------------------------------------------------
10 /** @file PrefixMaxKeyGenerator.cxx */
12 //------------------------------------------------------------------------------------------------------------
13 // Constructors & Destructors
14 //------------------------------------------------------------------------------------------------------------
17 * Creates the prefix+max key generator
19 PrefixMaxKeyGenerator :: PrefixMaxKeyGenerator()
21 numberOfKeyThings = 0;
25 * Destroys the outline manager
27 PrefixMaxKeyGenerator :: ~PrefixMaxKeyGenerator()
32 //------------------------------------------------------------------------------------------------------------
34 //------------------------------------------------------------------------------------------------------------
38 * Adds a key thing to the keyThings building the respective KeyThing (new keyThing).
39 * @param theName Is the name of the new keyThing to include. If the name is not unique, returns false.
40 * @param thePrefix Is the prefix of the new keyThing for the key generation correponding to the new keyThing
41 * @param theMax Is the maximum value for the key generation correponding to the new keyThing
42 * @return Returns true if the keyThing could be added of not.
44 bool PrefixMaxKeyGenerator :: addKeyThing( std::string theName, std::string thePrefix, int theMax )
46 KeyThing * kThing = new KeyThing(thePrefix, theMax);
47 int before = keyThings.size();
48 keyThings.insert(std::pair < std::string, KeyThing >( theName, *kThing ));
49 int after = keyThings.size();
50 return after > before;
55 * @param theName Is the name of the keyThing to remove.
57 void PrefixMaxKeyGenerator :: removeKeyThing( std::string theName )
59 keyThings.erase(theName);
64 * Indicates if a key thing existis in the generator
65 * @param theName Is the name of the keyThing to search.
66 * @return Returns true if the keyThing exists in the keyThings.
68 bool PrefixMaxKeyGenerator :: existsKeyThing( std::string theName )
70 return keyThings.find(theName) != keyThings.end();
74 * Updates the maximum value of a key thing if necesary (posibleMax>theMaxOfKeyThing). If the key thing doesn't exist nothing is done.
75 * @param theName Is the name of the keyThing to update.
76 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update.
78 void PrefixMaxKeyGenerator :: updateMaxTo( std::string theName, int posibleMax )
80 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
81 if ( iterP != keyThings.end() )
83 int max = (iterP->second).getValue();
84 if ( max < posibleMax )
85 (iterP->second).setValue(posibleMax);
90 * Generates a (std::string) key for a given keyThing. If the key thing doesn't exist nothing is done and returns false.
91 * @param theName Is the name of the keyThing to search.
92 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
93 * @return theKey Returns true if the key was generated successfully. (If theName is an existent keyThing)
95 bool PrefixMaxKeyGenerator :: generateKeyOf( std::string theName, std::string &theInputString )
98 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
99 if ( iterP != keyThings.end() )
101 KeyThing kthing = (iterP->second);
102 int max = kthing.getValue();
103 std::ostringstream genKey;
104 genKey<<kthing.getPrefix() << " " << max;
105 theInputString = genKey.str();
112 * Generates a (std::string) key for a given keyThing and updates the max value of it if necesary. If the key thing doesn't exist nothing is done.
113 * @param theName Is the name of the keyThing to search.
114 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update.
115 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
116 * @return Returns true if the key was generated successfully. (If theName is an existent keyThing)
118 bool PrefixMaxKeyGenerator :: generateKeyOf( std::string theName, int posibleMax, std::string &theInputString )
121 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
122 if ( iterP != keyThings.end() )
124 KeyThing kthing = (iterP->second);
125 int max = kthing.getValue();
127 if ( max < posibleMax )
129 kthing.setValue(posibleMax);
133 std::ostringstream genKey;
134 genKey<<kthing.getPrefix() << " " << kthing.getValue();
135 theInputString = genKey.str();
142 * Gets the prefix of a specific keyThing identified with the name in the parameter, if the key thing doesn't exists return false.
143 * @param theName Is the name of the keyThing to search the prefix.
144 * @param theInputString Is string to load the prefix of the searched keyThing.
145 * @return isStringOutputReal Returns if the loaded string in theInputString is real (i.e if the -theName- keyThing exists)
147 bool PrefixMaxKeyGenerator :: getPrefixOf( std::string theName, std::string &theInputString )
150 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
151 if ( iterP != keyThings.end() )
153 KeyThing kthing = (iterP->second);
154 theInputString = kthing.getPrefix();
161 * Gets the max value of a specific keyThing identified with the name in the parameter. If the key thing doesn't exists returns -1.
162 * @param theName Is the name of the keyThing to search the maximum.
163 * @return theMax Returns the maxumum value for key generation at the keyThing. Returns -1 if not finded keyThing.
165 int PrefixMaxKeyGenerator :: getCurrentMaxOf( std::string theName )
167 std::map<std::string, KeyThing >::iterator iterP = keyThings.find(theName);
168 if ( iterP != keyThings.end() )
170 KeyThing kthing = (iterP->second);
171 return kthing.getValue();
177 * Gets the total of keyThings managed
178 * @return Retuns the total of keyThing managed
180 int PrefixMaxKeyGenerator :: getTotalThingsNumber()
182 return keyThings.size();
186 * Clears the generator deleating the existring keyThings
188 void PrefixMaxKeyGenerator :: clear()
190 std::map<std::string, KeyThing >::iterator iter = keyThings.begin();
191 while( iter != keyThings.end() )
193 keyThings.erase(iter);
196 numberOfKeyThings = 0;