]> Creatis software - creaContours.git/blob - lib/kernel_ManagerContour_NDimensions/PrefixMaxKeyGenerator.h
cbd730e90c653c5a56e19f2ddbb0a937c68e01e9
[creaContours.git] / lib / kernel_ManagerContour_NDimensions / PrefixMaxKeyGenerator.h
1 #ifndef __PREFIX_MAX__KEYGENERATOR_
2 #define __PREFIX_MAX__KEYGENERATOR_
3
4 //------------------------------------------------------------------------------------------------------------
5 // Includes
6 //------------------------------------------------------------------------------------------------------------
7 #include <iostream>
8 #include <string>
9 #include <sstream>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <map>
13
14 #include "KeyThing.h"
15
16 /*
17 * Class that manages the creation of std::string keys of multiple objects independently, identified each by a unique name.
18 * Format of the key is: <prefixOfTheKeyThing> <maxOfTheKeyThing>
19 */
20 class PrefixMaxKeyGenerator{
21 //------------------------------------------------------------------------------------------------------------
22 // Constructors & Destructors
23 //------------------------------------------------------------------------------------------------------------
24 public:
25
26         /*
27         * Creates the prefix+max key generator  
28         */
29         PrefixMaxKeyGenerator();
30
31         /*
32         * Destroys the outline manager
33         */
34         ~PrefixMaxKeyGenerator();
35
36 //------------------------------------------------------------------------------------------------------------
37 // Public Methods
38 //------------------------------------------------------------------------------------------------------------
39
40         /*
41         * Adds a key thing to the keyThings building the respective KeyThing (new keyThing). 
42         * @param theName Is the name of the new keyThing to include. If the name is not unique, returns false.
43         * @param thePrefix Is the prefix of the new keyThing for the key generation correponding to the new keyThing
44         * @param theMax Is the maximum value for the key generation correponding to the new keyThing
45         * @return Returns true if the keyThing could be added of not.
46         */
47         bool addKeyThing( std::string theName, std::string thePrefix, int theMax=0 );
48
49         /*
50         * Remove a key thing  
51         * @param theName Is the name of the keyThing to remove. 
52         */
53         void removeKeyThing( std::string theName );
54
55         /*
56         * Indicates if a key thing existis in the generator
57         * @param theName Is the name of the keyThing to search. 
58         * @return Returns true if the keyThing exists in the keyThings.
59         */
60         bool existsKeyThing( std::string theName );
61
62         /*
63         * Updates the maximum value of a key thing if necesary (posibleMax>theMaxOfKeyThing). If the key thing doesn't exist nothing is done.
64         * @param theName Is the name of the keyThing to update.         
65         * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 
66         */
67         void updateMaxTo( std::string theName, int posibleMax );
68
69         /*
70         * Generates a (std::string) key for a given keyThing. If the key thing doesn't exist nothing is done and returns false.
71         * @param theName Is the name of the keyThing to search. 
72         * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
73         * @return theKey Returns true if the key was generated successfully. (If theName is an existent keyThing)
74         */
75         bool generateKeyOf( std::string theName , std::string &theInputString );
76
77         /*
78         * 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. 
79         * @param theName Is the name of the keyThing to search. 
80         * @param posibleMax Is the number that corresponds to a posible max value of the keyThing to update. 
81         * @param theInputString Is string to load the generated key formed like <prefixOfTheKeyThing> <maxOfTheKeyThing>
82         * @return Returns true if the key was generated successfully. (If theName is an existent keyThing)
83         */
84         bool generateKeyOf( std::string theName,  int posibleMax, std::string &theInputString );
85
86         /*
87         * Gets the prefix of a specific keyThing identified with the name in the parameter, if the key thing doesn't exists return false.
88         * @param theName Is the name of the keyThing to search the prefix. 
89         * @param theInputString Is string to load the prefix of the searched keyThing.
90         * @return isStringOutputReal Returns if the loaded string in theInputString is real (i.e if the -theName- keyThing exists)
91         */
92         bool getPrefixOf(std::string theName, std::string &theInputString);
93
94         /*
95         * Gets the max value of a specific keyThing identified with the name in the parameter. If the key thing doesn't exists returns -1.
96         * @param theName Is the name of the keyThing to search the maximum.     
97         * @return theMax Returns the maxumum value for key generation at the keyThing. Returns -1 if not finded keyThing.
98         */
99         int getCurrentMaxOf(std::string theName);
100
101         /*
102         * Gets the total of keyThings managed
103         * @return Retuns the total of keyThing managed
104         */
105         int getTotalThingsNumber();
106
107         /*
108         * Clears the generator deleating the existring keyThings
109         */
110         void clear();
111         
112 //------------------------------------------------------------------------------------------------------------
113 // Constants
114 //------------------------------------------------------------------------------------------------------------
115
116 //------------------------------------------------------------------------------------------------------------
117 // Attributes
118 //------------------------------------------------------------------------------------------------------------
119         
120 private:        
121
122         /*
123         * Represents the number of things that are currently managing
124         */
125         int numberOfKeyThings;
126
127         /*
128         * Represents the map or table in which the key-things are saved
129         */
130         std::map<std::string,KeyThing> keyThings;
131 };
132 #endif
133