creaContours_lib
PrefixMaxKeyGenerator.h
Go to the documentation of this file.
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 # pour la Sant�)
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
8 #
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.
15 #
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
20 # liability.
21 #
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 # ------------------------------------------------------------------------ */
25 
26 #ifndef __PREFIX_MAX__KEYGENERATOR_
27 #define __PREFIX_MAX__KEYGENERATOR_
28 
29 //------------------------------------------------------------------------------------------------------------
30 // Includes
31 //------------------------------------------------------------------------------------------------------------
32 #include <iostream>
33 #include <string>
34 #include <sstream>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <map>
38 
39 #include "KeyThing.h"
40 
41 /*
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>
44 */
46 //------------------------------------------------------------------------------------------------------------
47 // Constructors & Destructors
48 //------------------------------------------------------------------------------------------------------------
49 public:
50 
51  /*
52  * Creates the prefix+max key generator
53  */
55 
56  /*
57  * Destroys the outline manager
58  */
60 
61 //------------------------------------------------------------------------------------------------------------
62 // Public Methods
63 //------------------------------------------------------------------------------------------------------------
64 
65  /*
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.
71  */
72  bool addKeyThing( std::string theName, std::string thePrefix, int theMax=0 );
73 
74  /*
75  * Remove a key thing
76  * @param theName Is the name of the keyThing to remove.
77  */
78  void removeKeyThing( std::string theName );
79 
80  /*
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.
84  */
85  bool existsKeyThing( std::string theName );
86 
87  /*
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.
91  */
92  void updateMaxTo( std::string theName, int posibleMax );
93 
94  /*
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)
99  */
100  bool generateKeyOf( std::string theName , std::string &theInputString );
101 
102  /*
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)
108  */
109  bool generateKeyOf( std::string theName, int posibleMax, std::string &theInputString );
110 
111  /*
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)
116  */
117  bool getPrefixOf(std::string theName, std::string &theInputString);
118 
119  /*
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.
123  */
124  int getCurrentMaxOf(std::string theName);
125 
126  /*
127  * Gets the total of keyThings managed
128  * @return Retuns the total of keyThing managed
129  */
130  int getTotalThingsNumber();
131 
132  /*
133  * Clears the generator deleating the existring keyThings
134  */
135  void clear();
136 
137 //------------------------------------------------------------------------------------------------------------
138 // Constants
139 //------------------------------------------------------------------------------------------------------------
140 
141 //------------------------------------------------------------------------------------------------------------
142 // Attributes
143 //------------------------------------------------------------------------------------------------------------
144 
145 private:
146 
147  /*
148  * Represents the number of things that are currently managing
149  */
151 
152  /*
153  * Represents the map or table in which the key-things are saved
154  */
155  std::map<std::string,KeyThing> keyThings;
156 };
157 #endif
158