1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #ifndef __PREFIX_MAX__KEYGENERATOR_
27 #define __PREFIX_MAX__KEYGENERATOR_
29 //------------------------------------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------------------------------------
42 * Class that manages the creation of std::string keys of multiple objects independently, identified each by a unique name.
43 * Format of the key is: <prefixOfTheKeyThing> <maxOfTheKeyThing>
45 class PrefixMaxKeyGenerator{
46 //------------------------------------------------------------------------------------------------------------
47 // Constructors & Destructors
48 //------------------------------------------------------------------------------------------------------------
52 * Creates the prefix+max key generator
54 PrefixMaxKeyGenerator();
57 * Destroys the outline manager
59 ~PrefixMaxKeyGenerator();
61 //------------------------------------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------------------------------------
66 * Adds a key thing to the keyThings building the respective KeyThing (new keyThing).
67 * @param theName Is the name of the new keyThing to include. If the name is not unique, returns false.
68 * @param thePrefix Is the prefix of the new keyThing for the key generation correponding to the new keyThing
69 * @param theMax Is the maximum value for the key generation correponding to the new keyThing
70 * @return Returns true if the keyThing could be added of not.
72 bool addKeyThing( std::string theName, std::string thePrefix, int theMax=0 );
76 * @param theName Is the name of the keyThing to remove.
78 void removeKeyThing( std::string theName );
81 * Indicates if a key thing existis in the generator
82 * @param theName Is the name of the keyThing to search.
83 * @return Returns true if the keyThing exists in the keyThings.
85 bool existsKeyThing( std::string theName );
88 * Updates the maximum value of a key thing if necesary (posibleMax>theMaxOfKeyThing). If the key thing doesn't exist nothing is done.
89 * @param theName Is the name of the keyThing to update.
90 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update.
92 void updateMaxTo( std::string theName, int posibleMax );
95 * Generates a (std::string) key for a given keyThing. If the key thing doesn't exist nothing is done and returns false.
96 * @param theName Is the name of the keyThing to search.
97 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
98 * @return theKey Returns true if the key was generated successfully. (If theName is an existent keyThing)
100 bool generateKeyOf( std::string theName , std::string &theInputString );
103 * 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.
104 * @param theName Is the name of the keyThing to search.
105 * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update.
106 * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
107 * @return Returns true if the key was generated successfully. (If theName is an existent keyThing)
109 bool generateKeyOf( std::string theName, int posibleMax, std::string &theInputString );
112 * Gets the prefix of a specific keyThing identified with the name in the parameter, if the key thing doesn't exists return false.
113 * @param theName Is the name of the keyThing to search the prefix.
114 * @param theInputString Is string to load the prefix of the searched keyThing.
115 * @return isStringOutputReal Returns if the loaded string in theInputString is real (i.e if the -theName- keyThing exists)
117 bool getPrefixOf(std::string theName, std::string &theInputString);
120 * Gets the max value of a specific keyThing identified with the name in the parameter. If the key thing doesn't exists returns -1.
121 * @param theName Is the name of the keyThing to search the maximum.
122 * @return theMax Returns the maxumum value for key generation at the keyThing. Returns -1 if not finded keyThing.
124 int getCurrentMaxOf(std::string theName);
127 * Gets the total of keyThings managed
128 * @return Retuns the total of keyThing managed
130 int getTotalThingsNumber();
133 * Clears the generator deleating the existring keyThings
137 //------------------------------------------------------------------------------------------------------------
139 //------------------------------------------------------------------------------------------------------------
141 //------------------------------------------------------------------------------------------------------------
143 //------------------------------------------------------------------------------------------------------------
148 * Represents the number of things that are currently managing
150 int numberOfKeyThings;
153 * Represents the map or table in which the key-things are saved
155 std::map<std::string,KeyThing> keyThings;