00001 #ifndef __PREFIX_MAX__KEYGENERATOR_ 00002 #define __PREFIX_MAX__KEYGENERATOR_ 00003 00004 //------------------------------------------------------------------------------------------------------------ 00005 // Includes 00006 //------------------------------------------------------------------------------------------------------------ 00007 #include <iostream> 00008 #include <string> 00009 #include <sstream> 00010 #include <stdio.h> 00011 #include <stdlib.h> 00012 #include <map> 00013 00014 #include "KeyThing.h" 00015 00016 /* 00017 * Class that manages the creation of std::string keys of multiple objects independently, identified each by a unique name. 00018 * Format of the key is: <prefixOfTheKeyThing> <maxOfTheKeyThing> 00019 */ 00020 class PrefixMaxKeyGenerator{ 00021 //------------------------------------------------------------------------------------------------------------ 00022 // Constructors & Destructors 00023 //------------------------------------------------------------------------------------------------------------ 00024 public: 00025 00026 /* 00027 * Creates the prefix+max key generator 00028 */ 00029 PrefixMaxKeyGenerator(); 00030 00031 /* 00032 * Destroys the outline manager 00033 */ 00034 ~PrefixMaxKeyGenerator(); 00035 00036 //------------------------------------------------------------------------------------------------------------ 00037 // Public Methods 00038 //------------------------------------------------------------------------------------------------------------ 00039 00040 /* 00041 * Adds a key thing to the keyThings building the respective KeyThing (new keyThing). 00042 * @param theName Is the name of the new keyThing to include. If the name is not unique, returns false. 00043 * @param thePrefix Is the prefix of the new keyThing for the key generation correponding to the new keyThing 00044 * @param theMax Is the maximum value for the key generation correponding to the new keyThing 00045 * @return Returns true if the keyThing could be added of not. 00046 */ 00047 bool addKeyThing( std::string theName, std::string thePrefix, int theMax=0 ); 00048 00049 /* 00050 * Remove a key thing 00051 * @param theName Is the name of the keyThing to remove. 00052 */ 00053 void removeKeyThing( std::string theName ); 00054 00055 /* 00056 * Indicates if a key thing existis in the generator 00057 * @param theName Is the name of the keyThing to search. 00058 * @return Returns true if the keyThing exists in the keyThings. 00059 */ 00060 bool existsKeyThing( std::string theName ); 00061 00062 /* 00063 * Updates the maximum value of a key thing if necesary (posibleMax>theMaxOfKeyThing). If the key thing doesn't exist nothing is done. 00064 * @param theName Is the name of the keyThing to update. 00065 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 00066 */ 00067 void updateMaxTo( std::string theName, int posibleMax ); 00068 00069 /* 00070 * Generates a (std::string) key for a given keyThing. If the key thing doesn't exist nothing is done and returns false. 00071 * @param theName Is the name of the keyThing to search. 00072 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing> 00073 * @return theKey Returns true if the key was generated successfully. (If theName is an existent keyThing) 00074 */ 00075 bool generateKeyOf( std::string theName , std::string &theInputString ); 00076 00077 /* 00078 * 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. 00079 * @param theName Is the name of the keyThing to search. 00080 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 00081 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing> 00082 * @return Returns true if the key was generated successfully. (If theName is an existent keyThing) 00083 */ 00084 bool generateKeyOf( std::string theName, int posibleMax, std::string &theInputString ); 00085 00086 /* 00087 * Gets the prefix of a specific keyThing identified with the name in the parameter, if the key thing doesn't exists return false. 00088 * @param theName Is the name of the keyThing to search the prefix. 00089 * @param theInputString Is string to load the prefix of the searched keyThing. 00090 * @return isStringOutputReal Returns if the loaded string in theInputString is real (i.e if the -theName- keyThing exists) 00091 */ 00092 bool getPrefixOf(std::string theName, std::string &theInputString); 00093 00094 /* 00095 * Gets the max value of a specific keyThing identified with the name in the parameter. If the key thing doesn't exists returns -1. 00096 * @param theName Is the name of the keyThing to search the maximum. 00097 * @return theMax Returns the maxumum value for key generation at the keyThing. Returns -1 if not finded keyThing. 00098 */ 00099 int getCurrentMaxOf(std::string theName); 00100 00101 /* 00102 * Gets the total of keyThings managed 00103 * @return Retuns the total of keyThing managed 00104 */ 00105 int getTotalThingsNumber(); 00106 00107 /* 00108 * Clears the generator deleating the existring keyThings 00109 */ 00110 void clear(); 00111 00112 //------------------------------------------------------------------------------------------------------------ 00113 // Constants 00114 //------------------------------------------------------------------------------------------------------------ 00115 00116 //------------------------------------------------------------------------------------------------------------ 00117 // Attributes 00118 //------------------------------------------------------------------------------------------------------------ 00119 00120 private: 00121 00122 /* 00123 * Represents the number of things that are currently managing 00124 */ 00125 int numberOfKeyThings; 00126 00127 /* 00128 * Represents the map or table in which the key-things are saved 00129 */ 00130 std::map<std::string,KeyThing> keyThings; 00131 }; 00132 #endif 00133