configuration.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00009 /*
00010   AUTHOR(S): Lilian Qin Lan (lan)
00011 
00012   RCS information
00013    $Name: OSB_060808 $
00014    $Revision: 1.18.2.1 $
00015 
00016   License
00017    OSB rating and billing library for communication networks
00018    Copyright (C) 2004, 2005, 2006  OSB systems
00019 
00020    This file may be distributed and/or modify under the terms of the
00021    GNU General Public License (GPL) as published by the Free Software
00022    Foundation which is provided in the file LICENSE.GPL included in the
00023    packaging of this file.
00024 
00025    The file is distributed in the hope that it will be useful, but WITHOUT
00026    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00028    for more details.
00029 
00030    Holders of a OSB Commercial License may use this file under the terms
00031    and conditions of this commercial license.
00032  */
00033 #ifndef _CONFIGURATION_H_
00034 #define _CONFIGURATION_H_
00035 
00036 // *********************************************************************
00037 // included header files
00038 // + standard includes
00039 #include <map>
00040 #include <string>
00041 
00042 // + local headers
00043 #include "osbconst.h"
00044 
00045 // *********************************************************************
00046 // class declarations
00047 namespace OSB_DB {
00048     class Session;
00049     class ConfigurationGw;
00050 }
00051 
00052 namespace OSB_LIB {
00053     class Date;
00054 }
00055 
00056 // ************************************************************************
00057 // namespace extensions
00058 namespace OSB_LIB {
00059 
00060     // *****************************************************************
00061     // class Configuration
00068     class Configuration {
00070         friend class OSB_DB::ConfigurationGw;
00071     public:
00073         enum ConfigType {
00074             ctUnknown  = '\0',          
00075             ctDate     = 'd',           
00076             ctLong     = 'l',           
00077             ctString   = 's'            
00078         };
00079 
00081         enum RetConvert {
00082             rcSuccess      = 0,         //<! Conversion OK.
00083             rcTypeMismatch = 1,         //<! Wrong #type_.
00084             rcErrConvert   = 2          //<! Error in conversion.
00085         };
00086 
00087     public:
00089         explicit Configuration(ModuleId module = mdUnknown);
00090 
00098         static ConfigType configType(char c);
00099 
00101 
00102 
00103         ModuleId module() const;
00105         const std::string& keyword() const;
00107         const std::string& value() const;
00109         ConfigType type() const;
00111         const std::string& desc() const;
00113 
00130         bool read(
00131             const OSB_DB::Session& session,
00132                   ModuleId         module,
00133             const std::string&     keyword
00134         );
00135 
00142 
00143         RetConvert convert(Date* pDest) const;
00145         RetConvert convert(long* pDest) const;
00147         RetConvert convert(std::string* pDest) const;
00149 
00150     private:
00151         ModuleId module_;
00153         std::string keyword_;
00155         std::string value_;
00157         ConfigType  type_;
00159         std::string desc_;
00160     };                                  // class Configuration
00161 
00162     // *****************************************************************
00163     // class ConfigList
00167     class ModuleConfig {
00168     public:
00170 
00171 
00175         typedef std::map<std::string, Configuration> List;
00177         typedef List::iterator Iterator;
00179         typedef List::const_iterator ConstIterator;
00181         typedef List::size_type SizeType;
00183         typedef List::key_type KeyType;
00185 
00191 
00192         const List& list() const { return list_; }
00194         SizeType size() const { return list_.size(); }
00196         ConstIterator begin() const { return list_.begin(); }
00198         ConstIterator end() const { return list_.end(); }
00200 
00212         long read(
00213             const OSB_DB::Session& session,
00214             const ModuleId         module
00215         );
00216 
00222         enum RetConvert {
00223             rcSuccess      = Configuration::rcSuccess,
00224             rcTypeMismatch = Configuration::rcTypeMismatch,
00225             rcErrConvert   = Configuration::rcErrConvert,
00226             rcNotFound     = 3
00227         };
00228 
00237 
00238         RetConvert convert(
00239                   Date*        pDest,
00240             const std::string& keyword
00241         ) const;
00243         RetConvert convert(
00244                   long*        pDest,
00245             const std::string& keyword
00246         ) const;
00248         RetConvert convert(
00249                   std::string* pDest,
00250             const std::string& keyword
00251         ) const;
00253     private:
00254         List list_;
00255     };                                  // class ModuleConfig
00256 }
00257 #endif                                  // #ifndef _CONFIGURATION_H_

Generated on Sat Sep 2 14:06:32 2006 for OSB Library by  doxygen 1.4.7