Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cdb.h

Go to the documentation of this file.
00001 // ************************************************************************ 00002 // 00003 // $Id: cdb.h,v 1.26 2006/09/01 02:20:54 cparedes Exp $ 00004 // 00005 // Copyright (c) 2000 by Klemen Zagar 00006 // 00007 // GROUP = Configuration Database 00008 // AUTHOR --- Klemen Zagar 00009 // 00010 // ************************************************************************ 00011 00012 #ifndef __cdb__CDB_h__ 00013 #define __cdb__CDB_h__ 00014 00015 #include "cdbField.h" 00016 00017 #include <map> 00018 #include <set> 00019 00020 #include "acsutil.h" 00021 #include "cdbExport.h" 00022 #include "ace/Singleton.h" 00023 00024 namespace cdb { 00025 class cdb_EXPORT Table; 00026 00027 // 00028 // DESCRIPTION: A record in a configuration database. 00029 // 00030 // A record stores a plethora of fields, each of them identified by a name. 00031 // The fields are stored in memory as a STL map, which guarantees fast 00032 // O(log N) 00033 // 00034 typedef std::map<String, Field> MapStringToField; 00035 typedef std::set<String> SetOfStrings; 00036 typedef Table* (*TableFactory)(int, char**, CORBA::ORB_ptr); 00037 00038 class cdb_EXPORT Record : protected MapStringToField 00039 { 00040 friend class Table; 00041 00042 Record(const Record&); 00043 Record &operator=(const Record&); 00044 00045 public: 00046 00047 00048 typedef MapStringToField::const_iterator const_iterator; 00049 const_iterator begin() const { return MapStringToField::begin(); } 00050 const_iterator end() const { return MapStringToField::end(); } 00051 const_iterator find(const String &str) const 00052 { return MapStringToField::find(str); } 00053 00054 void Clear(); 00055 00056 Record(const String &strRecord = "", Table *pTable = 0); 00057 ~Record(); 00058 00059 void SetOrigin(const String &strRecord, Table *pTable); 00060 00061 void CommitOnClose(Boolean b) { m_bCommitOnClose = b; }; 00062 Boolean Commit(); 00063 00064 // 00065 // 00066 const Field& operator[](const String &strName) const; 00067 00068 // 00069 // DESCRIPTION: 00070 // Get a field from the record. If it doesn't exist, use a default 00071 // value. 00072 // 00073 // PARAMETERS: 00074 // strName Name of the field. 00075 // fldDefault Default value which is returned if the field does not 00076 // exist yet. 00077 // 00078 // RETURN VALUE: 00079 // Returns the requested field or default value if it does not exist. 00080 // 00081 const Field& GetField(const String &strName, 00082 const Field &fldDefault) const; 00083 00084 // 00085 // DESCRIPTION: 00086 // Set a value of the field. 00087 // 00088 Boolean SetField(const String &strName, 00089 const Field &fldValue, 00090 Boolean bCreate = TRUE); 00091 00092 00093 00094 Boolean RemoveField(const String &strName); 00095 00096 const SetOfStrings::const_iterator GetFirstDirty() const 00097 { return m_setDirty.begin(); } 00098 const SetOfStrings::const_iterator GetLastDirty() const 00099 { return m_setDirty.end(); } 00100 00101 SetOfStrings &Dirty() { return m_setDirty; } 00102 const SetOfStrings &Dirty() const { return m_setDirty; } 00103 00104 MapStringToField &Map() { return *this; } 00105 const MapStringToField &Map() const { return *this; } 00106 00107 protected: 00108 iterator begin() { return MapStringToField::begin(); } 00109 iterator end() { return MapStringToField::end(); } 00110 00111 private: 00112 00113 Table *m_pTable; 00114 String m_strRecord; 00115 00116 Boolean m_bCommitOnClose; 00117 00118 SetOfStrings m_setDirty; 00119 }; 00120 00121 // 00122 // Separator between name components of the record, so that the name can 00123 // imply a hierarchy. 00124 // 00125 // Alternatives: 00126 // / 00127 // : VLT CCS database 00128 // \ Windows 00129 // 00130 00131 #define CDB_HIERARCHY_SEPARATOR ':' 00132 00133 #define CDB_RECORD_READABLE 1 00134 #define CDB_RECORD_WRITABLE 2 00135 #define CDB_RECORD_REMOVABLE 4 00136 00137 // 00138 // DESCRIPTION: A table in the configuration database. 00139 // 00140 class cdb_EXPORT Table 00141 { 00142 int m_nRefCount; 00143 Boolean m_bWriteLock; 00144 public: 00145 int _add_ref(void) { return ++m_nRefCount; } 00146 int _rem_ref(void) { return --m_nRefCount; } 00147 00148 typedef std::pair<String, Field> NamedField; 00149 typedef std::vector<Field> NamedFieldArray; 00150 00151 Table(); 00152 virtual ~Table(); 00153 00154 virtual Boolean isInitialized() = 0; 00155 00156 00157 // 00158 // DESCRIPTION: Read/write lock the table. 00159 // 00160 // Before using a table, a read/write lock must be put in place to: 00161 // 00162 // 1. Prevent the table from being deleted while still in use. 00163 // 2. Prevent several processes from simultaneously modifying the 00164 // table. 00165 // 00166 // To gain an exclusive write lock, set bExclusiveWrite to a TRUE 00167 // value. Such an operation might block, waiting for the current 00168 // exclusive write lock to be released. To prevent blocking in such 00169 // cases, set bNonBlocking to TRUE as well. 00170 // 00171 // EXAMPLE: 00172 // 00173 // SomeTable tbl; 00174 // tbl.Lock(TRUE, FALSE); 00175 // // ... 00176 // tbl.Unlock(TRUE); // don't forget to unlock! 00177 // 00178 Boolean Lock(Boolean bExclusiveWrite = 0); 00179 00180 Boolean Unlock(Boolean bExclusiveWrite = 0); 00181 00182 // 00183 // DESCRIPTION: Create a record in the table. 00184 // 00185 // Create an empty record in the table. 00186 // 00187 // PARAMETERS: 00188 // strRecordName - The name by which the newly created record 00189 // will be identified. 00190 // 00191 // RETURN VALUE: Returns TRUE if the record can be used, and FALSE if the 00192 // creation had failed. 00193 // 00194 virtual Boolean CreateRecord(const String &strRecordName, 00195 Boolean bTruncate = FALSE) = 0; 00196 00197 // 00198 // Returns TRUE if the record already exists. 00199 // 00200 virtual ULong GetRecordState(const String &strRecordName) = 0; 00201 00202 virtual Boolean GetField(const String &strRecordName, 00203 const String &strFieldName, 00204 Field &fld) = 0; 00205 virtual Boolean SetField(const String &strRecordName, 00206 const String &strFieldName, 00207 const Field &fld, 00208 Boolean bCreate = TRUE) = 0; 00209 virtual Boolean RemoveField(const String &strRecordName, 00210 const String &strFieldName) = 0; 00211 00212 // 00213 // DESCRIPTION: Get a record from the database. 00214 // 00215 // PARAMETERS: 00216 // strRecordName - The name of the record to retrieve from the database. 00217 // rec - Reference of the record to fill-in. 00218 virtual Boolean GetRecord(const String &strRecordName, 00219 Record &rec, 00220 Boolean bCreate = FALSE, 00221 Boolean bAppend = FALSE) = 0; 00222 virtual Boolean SetRecord(const String &strRecordName, 00223 const Record &rec, 00224 Boolean bCreate = TRUE, 00225 Boolean bAll = TRUE) = 0; 00226 virtual Boolean RemoveRecord(const String &strRecordName) = 0; 00227 00228 // ---------------------------------------------------------------------- 00229 // GROUP = Navigation 00230 // ---------------------------------------------------------------------- 00231 00232 // 00233 // DESCRIPTION: Get the name of the root record. 00234 // 00235 // PARAMETERS: 00236 // strRoot - Reference of the string where the root record's name will 00237 // be placed. This name can be later used with other methods 00238 // of the table. 00239 // 00240 // RETURN VALUE: 00241 // FALSE if the table does not have any support for hierarchical 00242 // ordering of its records, TRUE otherwise. 00243 // 00244 virtual Boolean GetRoot(String &strRoot) 00245 { strRoot = CDB_HIERARCHY_SEPARATOR; return TRUE; } 00246 00247 // 00248 // DESCRIPTION: Get all child-records of a given record. 00249 // 00250 // PARAMETERS: 00251 // strRecordName 00252 // 00253 virtual Boolean GetChildren(const String &strRecordName, 00254 StringArray &astrChildren) = 0; 00255 00256 virtual Boolean GetParent(const String &strRecordName, 00257 String &strParent); 00258 }; 00259 00260 typedef struct _tagTableEntry 00261 { 00262 String name; 00263 Table* table; 00264 } TableEntry; 00265 00266 class TableStorage 00267 { 00268 public: 00269 Table* find(const char* name ); 00270 Table* first(void); 00271 Boolean bind(const char* name, Table* table ); 00272 Boolean unbind( Table* table ); 00273 const char* getDefault( void ); 00274 void setDefault( const char* name ); 00275 00276 // registered types 00277 Boolean bindType(const char* name, TableFactory pTf ); 00278 TableFactory findType(const char* name); 00279 00280 protected: 00281 TableStorage(); 00282 ~TableStorage(); 00283 00284 typedef std::map<String, TableFactory> DBTypes; 00285 00286 std::vector<TableEntry> m_dbMap; 00287 DBTypes m_dbTypes; 00288 ACE_CString m_defaultTable; 00289 friend class ACE_Singleton<TableStorage, ACE_Null_Mutex>; 00290 }; 00291 00292 cdb_EXPORT Table* getDatabase( int argc = 0, char** argv = NULL, CORBA::ORB_ptr orb = CORBA::ORB::_nil(), const char* defaultTable= NULL, int forceNew = 0 ); 00293 cdb_EXPORT void destroyDatabase( Table* table ); 00294 cdb_EXPORT void registerTable( const char* name, TableFactory pTf ); 00295 00296 #include "cdb.i" 00297 00298 }; 00299 00300 00301 00302 #endif // __cdb__CDB_h__ 00303 00304 // ************************************************************************ 00305 // 00306 // REVISION HISTORY: 00307 // 00308 // $Log: cdb.h,v $ 00309 // Revision 1.26 2006/09/01 02:20:54 cparedes 00310 // small change, NAMESPACE_BEGIN / NAMESPACE_END / NAMESPACE_USE macross to clean up a little the cpp code 00311 // 00312 // Revision 1.25 2003/07/09 08:07:35 bjeram 00313 // ported to gcc 3.2 00314 // 00315 // Revision 1.24 2003/01/28 16:43:49 vltsccm 00316 // gchiozzi: patch for cdb module to create lib/endorsed directory, since CVS cannot restore empty directories 00317 // 00318 // Revision 1.23 2003/01/24 10:44:02 vltsccm 00319 // cdb1.23 00320 // 00321 // Revision 1.22 2003/01/20 15:12:18 vltsccm 00322 // cdb1.22 00323 // 00324 // Revision 1.21 2003/01/20 10:45:52 vltsccm 00325 // cdb1.21 00326 // 00327 // Revision 1.20 2002/12/05 16:03:57 vltsccm 00328 // cdb1.20 00329 // 00330 // Revision 1.19 2002/11/25 16:04:48 vltsccm 00331 // cdb1.19 00332 // 00333 // Revision 1.18 2002/11/13 14:53:03 vltsccm 00334 // cdb1.18 00335 // 00336 // Revision 1.17 2002/11/13 10:22:29 vltsccm 00337 // cdb1.17 00338 // 00339 // Revision 1.16 2002/11/06 08:37:03 vltsccm 00340 // cdb1.16 00341 // 00342 // Revision 1.15.1.23 2002/11/05 16:05:12 vltsccm 00343 // cdb1.15.1.23 00344 // 00345 // Revision 1.15.1.22 2002/11/05 13:46:30 vltsccm 00346 // cdb1.15.1.22 00347 // 00348 // Revision 1.15.1.21 2002/11/05 10:41:13 vltsccm 00349 // cdb1.15.1.21 00350 // 00351 // Revision 1.15.1.20 2002/11/01 12:49:01 vltsccm 00352 // cdb1.15.1.20 00353 // 00354 // Revision 1.15.1.19 2002/10/30 07:56:43 vltsccm 00355 // cdb1.15.1.19 00356 // 00357 // Revision 1.15.1.18 2002/10/25 12:44:22 vltsccm 00358 // cdb1.15.1.18 00359 // 00360 // Revision 1.15.1.17 2002/10/24 13:08:43 vltsccm 00361 // cdb1.15.1.17 00362 // 00363 // Revision 1.15.1.16 2002/10/16 11:43:44 vltsccm 00364 // cdb1.15.1.16 00365 // 00366 // Revision 1.15.1.15 2002/10/14 22:26:08 vltsccm 00367 // cdb1.15.1.15 00368 // 00369 // Revision 1.15.1.14 2002/10/14 12:18:31 vltsccm 00370 // cdb1.15.1.14 00371 // 00372 // Revision 1.15.1.13 2002/10/04 16:20:22 vltsccm 00373 // cdb1.15.1.13 00374 // 00375 // Revision 1.15.1.12 2002/10/02 12:54:13 vltsccm 00376 // cdb1.15.1.12 00377 // 00378 // Revision 1.15.1.11 2002/10/01 10:33:24 vltsccm 00379 // cdb1.15.1.11 00380 // 00381 // Revision 1.15.1.10 2002/09/30 13:56:50 vltsccm 00382 // cdb1.15.1.10 00383 // 00384 // Revision 1.15.1.9 2002/09/26 14:13:09 vltsccm 00385 // cdb1.15.1.9 00386 // 00387 // Revision 1.15.1.8 2002/09/26 07:45:45 vltsccm 00388 // cdb1.15.1.8 00389 // 00390 // Revision 1.15.1.7 2002/09/17 16:19:20 vltsccm 00391 // cdb1.15.1.7 00392 // 00393 // Revision 1.15.1.6 2002/09/17 11:15:46 vltsccm 00394 // cdb1.15.1.6 00395 // 00396 // Revision 1.15.1.5 2002/09/02 09:37:05 vltsccm 00397 // cdb1.15.1.5 00398 // 00399 // Revision 1.15.1.4 2002/08/09 09:35:22 vltsccm 00400 // cdb1.15.1.4 00401 // 00402 // Revision 1.15.1.3 2002/07/24 07:29:09 vltsccm 00403 // cdb1.15.1.3 00404 // 00405 // Revision 1.15.1.2 2002/07/12 09:58:15 vltsccm 00406 // cdb1.15.1.2 00407 // 00408 // Revision 1.15+.1.1 2002/07/09 09:40:08 vltsccm 00409 // cdb1.15.1 00410 // 00411 // Revision 1.15 2002/02/05 17:50:07 vltsccm 00412 // cdb1.15 00413 // 00414 // Revision 1.14 2002/01/14 21:14:17 vltsccm 00415 // cdb1.14 00416 // 00417 // Revision 1.13 2001/10/19 09:56:21 vltsccm 00418 // cdb1.13 00419 // 00420 // Revision 1.12 2001/09/18 10:07:11 vltsccm 00421 // cdb1.12 00422 // 00423 // Revision 1.11 2001/07/12 07:48:25 vltsccm 00424 // cdb1.11 00425 // 00426 // Revision 1.10 2001/07/11 09:16:09 vltsccm 00427 // cdb1.10 00428 // 00429 // Revision 1.6 2000/12/07 18:00:40 vltsccm 00430 // cdb1.6 00431 // 00432 // Revision 1.5 2000/11/17 13:14:57 vltsccm 00433 // cdb1.5 00434 // 00435 // Revision 1.4 2000/10/20 13:51:19 vltsccm 00436 // cdb1.4 00437 // 00438 // Revision 1.3 2000/10/20 13:51:19 vltsccm 00439 // cdb1.3 00440 // 00441 // Revision 1.2 2000/10/20 13:51:18 vltsccm 00442 // cdb1.2 00443 // 00444 // Revision 1.1 2000/10/20 13:51:18 vltsccm 00445 // cdb1.1 00446 // 00447 // Revision 1.0 2000/10/20 13:51:18 vltsccm 00448 // cdb1.0 00449 // 00450 // Revision 1.3 2000/10/13 16:03:01 vltsccm 00451 // cdb1.3 00452 // 00453 // Revision 1.2 2000/09/13 14:49:28 vltsccm 00454 // cdb1.2 00455 // 00456 // Revision 1.1 2000/09/06 15:42:10 vltsccm 00457 // cdb1.1 00458 // 00459 // Revision 1.1 2000/06/13 07:26:24 kzagar 00460 // CDB, initial commit. Documentation not yet finished. 00461 // 00462 // ************************************************************************

Generated on Thu Apr 30 02:30:50 2009 for ACS C++ API by doxygen 1.3.8