The Fib multimedia system
Fib is a system for storing multimedia data (like images or films).
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cFibDatabase.h
Go to the documentation of this file.
1 /**
2  * @class cFibDatabase
3  * file name: cFibDatabase.h
4  * @author Betti Oesterholz
5  * @date 25.11.2011
6  * @mail webmaster@BioKom.info
7  *
8  * System: C++
9  *
10  * This class represents Fib database.
11  * Copyright (C) @c LGPL3 2011 Betti Oesterholz
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License (LGPL) as
15  * published by the Free Software Foundation, either version 3 of the
16  * License, or any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  *
26  *
27  * This class represents Fib database. It gives you access to the Fib
28  * database objects.
29  * It will load the Fib database objects from a Fib database folder, if
30  * they are needed.
31  *
32  */
33 /*
34 History:
35 25.11.2011 Oesterholz created
36 */
37 
38 #ifndef ___C_FIB_DATABASE_H__
39 #define ___C_FIB_DATABASE_H__
40 
41 
42 #include "version.h"
43 
44 #include "fibDatatyps.h"
45 
46 #include "cRoot.h"
47 #include "cFolder.h"
48 
49 #include <string>
50 #include <list>
51 #include <map>
52 
53 
54 namespace fib{
55 
56 class cFibDatabaseDeleter;
57 
59 
60 friend class cFibDatabaseDeleter;
61 
62 private:
63 
64  /**
65  * The instance for the Fib database
66  */
68 
69  /**
70  * The path to the actual loaded database.
71  */
72  static std::string szDatabasePath;
73 
74  /**
75  * A map with the loaded Fib database objects.
76  * map entries:
77  * key: the identifer of the database object
78  * value: the loaded database object for the identifier
79  */
80  static std::map< longFib, cRoot * > mapLoadedDatabaseObjects;
81 
82  /**
83  * The set with the identifiers for all database objects.
84  * map entries:
85  * key: the identifer of the database object
86  * value: the name of the file for the object in the database folder
87  */
88  static std::map< longFib, std::string > mapDatabaseIdentifiers;
89 
90  /**
91  * The list with the identifiers for all database objects.
92  * This data structure is yust for the faster evaluation of:
93  * @see cRoot::getAllDatabaseObjectIdentifiers()
94  */
95  static std::list< longFib > liDatabaseIdentifiers;
96 
97  /**
98  * constructor
99  */
100  cFibDatabase();
101 
102 protected:
103 
104  /**
105  * This class is for deleting the database when the programm ends.
106  */
108 
109 public:
110 
111 
112  /**
113  * destructor
114  */
115  virtual ~cFibDatabase();
116 
117  /**
118  * @return a instance of the database object
119  */
120  static cFibDatabase * getInstance();
121 
122  /**
123  * This method returns the identifiers of all database objects, in the
124  * actual database.
125  *
126  * @return the identifiers of all database objects
127  */
128  std::list< longFib > getAllDatabaseObjectIdentifiers() const;
129 
130  /**
131  * This method returns the database Fib object for the identifer, if it
132  * exists.
133  *
134  * @see loadFibObject()
135  * @see mapLoadedDatabaseObjects
136  * @see setDatabaseIdentifiers
137  * @param lIdentifer the identifer of the Fib object to return
138  * @return the Fib object for the identifer lIdentifer or NULL if non
139  * such exists
140  */
141  cRoot * getFibObject( const longFib lIdentifer );
142 
143  /**
144  * This method loads the Fib object for the identifier.
145  * If you load Fib objects some time befor you want it
146  * (call getFibObject() for them) this could speed up the process.
147  * This method won't load Fib objects that are allready loaded.
148  *
149  * @see getFibObject()
150  * @see reloadDatabase()
151  * @see mapLoadedDatabaseObjects
152  * @see setDatabaseIdentifiers
153  * @param lIdentifer the identifer of the Fib object to load
154  */
155  void loadFibObject( const longFib lIdentifer );
156 
157  /**
158  * This method frees the Fib object for the identifier.
159  * You could free some memory in this way.
160  *
161  * @see getFibObject()
162  * @see loadFibObject()
163  * @see reloadDatabase()
164  * @see mapLoadedDatabaseObjects
165  * @see setDatabaseIdentifiers
166  * @param lIdentifer the identifer of the Fib object to load
167  */
168  void freeFibObject( const longFib lIdentifer );
169 
170  /**
171  * @return A map with the loaded Fib database objects.
172  * map entries:
173  * key: the identifer of the database object
174  * value: the loaded database object for the identifier
175  * @see mapLoadedDatabaseObjects
176  */
177  std::map< longFib, cRoot * > getLoadedDatabaseObjects();
178 
179 
180  /**
181  * @see szDatabasePath
182  * @return a string to the actual set database path, the string is empty
183  * if no database path is set
184  */
185  static std::string getDatabasePath();
186 
187  /**
188  * This function sets the Fib database path to the given path if possible.
189  *
190  * @see szDatabasePath
191  * @param szInDatabasePath the path to the folder with the Fib database
192  * objects
193  * @return true if the given Fib database path exists and was set, else
194  * false and the database path is not changed
195  */
196  static bool setDatabasePath( const char * szInDatabasePath );
197 
198  /**
199  * This function sets the Fib database path to the given path if posible.
200  *
201  * @see szDatabasePath
202  * @param szInDatabasePath the path to the folder with the Fib database
203  * objects
204  * @return true if the given Fib database path exists and was set, else
205  * false and the database path is not changed
206  */
207  static bool setDatabasePath( const std::string szInDatabasePath );
208 
209  /**
210  * This function search standard Fib database paths to find a valid Fib
211  * database and sets the first found Fib database path if one was found.
212  *
213  * @see szDatabasePath
214  * @see szStandardDatabaseFolder
215  * @return true if a Fib database (path) was found and was set, else
216  * false and the database path is not changed
217  */
218  static bool searchForDatabasePath();
219 
220  /**
221  * This method reloads all Fib database objects identifiers from the set
222  * database path.
223  * No database objects will be loaded after the reload.
224  *
225  * @see szDatabasePath
226  * @see mapLoadedDatabaseObjects
227  * @return true if the database objects identifiers could be reloded
228  * (the database path exists), else false
229  */
230  bool reloadDatabase();
231 
232 private:
233 
234  /**
235  * This method loads the database folder data.
236  * (Attention: No mutex variables are used in this method.)
237  *
238  * @see liDatabaseIdentifiers
239  * @see mapDatabaseIdentifiers
240  * @param folder the database folder from which to load the data
241  * @return true if the data was loaded, else false
242  */
243  static bool loadListContainedDbObjects( cFolder & folder );
244 
245 
246 #ifdef FEATURE_FIB_DB_USE_TREADS
247 
248  /**
249  * This method is for running in a seperate tread.
250  * It will loade the Fib object for the given identifier.
251  *
252  * @see run()
253  * @see start()
254  * @see stop()
255  * @param inputArg a longFib number for the Fib database object to load
256  */
257  static void * treadloadFibObject( void * inputArg );
258 
259 #endif //FEATURE_FIB_DB_USE_TREADS
260 
261 
262 };//end class cFibDatabase
263 }//end namespace fib
264 
265 #endif //___C_FIB_DATABASE_H__
266 
267 
268 
269 
270 
271