PrefixMaxKeyGenerator.cxx

Go to the documentation of this file.
00001 
00002 //----------------------------------------------------------------------------------------------------------------
00003 // Class definition include
00004 //----------------------------------------------------------------------------------------------------------------
00005 #include "PrefixMaxKeyGenerator.h"
00006 
00007 //----------------------------------------------------------------------------------------------------------------
00008 // Class implementation
00009 //----------------------------------------------------------------------------------------------------------------
00012 //------------------------------------------------------------------------------------------------------------
00013 // Constructors & Destructors
00014 //------------------------------------------------------------------------------------------------------------
00015 
00016         /*
00017         * Creates the prefix+max key generator
00018         */
00019         PrefixMaxKeyGenerator :: PrefixMaxKeyGenerator()
00020         {
00021                 numberOfKeyThings = 0;          
00022         }
00023 
00024         /*
00025         * Destroys the outline manager
00026         */
00027         PrefixMaxKeyGenerator :: ~PrefixMaxKeyGenerator()
00028         {
00029                 clear();
00030         }
00031 
00032 //------------------------------------------------------------------------------------------------------------
00033 // Public Methods
00034 //------------------------------------------------------------------------------------------------------------
00035 
00036         
00037         /*
00038         * Adds a key thing to the keyThings building the respective KeyThing (new keyThing). 
00039         * @param theName Is the name of the new keyThing to include. If the name is not unique, returns false.
00040         * @param thePrefix Is the prefix of the new keyThing for the key generation correponding to the new keyThing
00041         * @param theMax Is the maximum value for the key generation correponding to the new keyThing
00042         * @return Returns true if the keyThing could be added of not.
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         * Remove a key thing  
00055         * @param theName Is the name of the keyThing to remove. 
00056         */
00057         void PrefixMaxKeyGenerator :: removeKeyThing( std::string theName )
00058         {
00059                 keyThings.erase(theName);               
00060         }
00061 
00062 
00063         /*
00064         * Indicates if a key thing existis in the generator
00065         * @param theName Is the name of the keyThing to search. 
00066         * @return Returns true if the keyThing exists in the keyThings.
00067         */
00068         bool PrefixMaxKeyGenerator :: existsKeyThing( std::string theName )
00069         {
00070                 return keyThings.find(theName) != keyThings.end();              
00071         }
00072 
00073         /*
00074         * Updates the maximum value of a key thing if necesary (posibleMax>theMaxOfKeyThing). If the key thing doesn't exist nothing is done.
00075         * @param theName Is the name of the keyThing to update.         
00076         * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 
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         * Generates a (std::string) key for a given keyThing. If the key thing doesn't exist nothing is done and returns false.
00091         * @param theName Is the name of the keyThing to search. 
00092         * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
00093         * @return theKey Returns true if the key was generated successfully. (If theName is an existent keyThing)
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         * 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. 
00113         * @param theName Is the name of the keyThing to search. 
00114         * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 
00115         * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
00116         * @return Returns true if the key was generated successfully. (If theName is an existent keyThing)
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         * Gets the prefix of a specific keyThing identified with the name in the parameter, if the key thing doesn't exists return false.
00143         * @param theName Is the name of the keyThing to search the prefix. 
00144         * @param theInputString Is string to load the prefix of the searched keyThing.
00145         * @return isStringOutputReal Returns if the loaded string in theInputString is real (i.e if the -theName- keyThing exists)
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         * Gets the max value of a specific keyThing identified with the name in the parameter. If the key thing doesn't exists returns -1.
00162         * @param theName Is the name of the keyThing to search the maximum.     
00163         * @return theMax Returns the maxumum value for key generation at the keyThing. Returns -1 if not finded keyThing.
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         * Gets the total of keyThings managed
00178         * @return Retuns the total of keyThing managed
00179         */
00180         int PrefixMaxKeyGenerator :: getTotalThingsNumber()
00181         {
00182                 return keyThings.size();
00183         }
00184 
00185         /*
00186         * Clears the generator deleating the existring keyThings
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         }

Generated on Wed Jun 27 23:28:33 2012 for creaContours_lib by  doxygen 1.5.7.1