osbcfgfile.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.6 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _OSBCFGFILE_H_
00031 #define _OSBCFGFILE_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <fstream>
00037 #include <string>
00038 
00039 // + libraries
00040 
00041 // + local headers
00042 
00043 // + class declarations
00044 
00045 // ************************************************************************
00046 // namespace extensions
00047 namespace OSB_LIB {
00048 
00049 // ************************************************************************
00050 // forward declarations
00051 
00052 // ************************************************************************
00053 // type definitions
00054 
00055 // ************************************************************************
00056 // class definitions
00086     class CfgFile {
00087     public:
00089         enum Flags {
00091             withComments   = 0x01,
00093             withEmptyLines = 0x02
00094         };
00095 
00096     public:
00098         static const std::string& sectionEnd();
00099 
00105         CfgFile();
00113         explicit CfgFile(const std::string& path);
00117         ~CfgFile();
00118     private:
00120 
00121         CfgFile(const CfgFile&);
00122         CfgFile& operator=(CfgFile&);
00124 
00125     public:
00134         bool open(const std::string& p);
00136         bool isOpen();
00138         void close();
00140         const std::ifstream& stream() const;
00147         bool rewind();
00148 
00150         int flags() const;
00152         void setFlags(int flags);
00154         bool comments() const;
00156         bool emptyLines() const;
00157 
00159         const std::string& curLine() const;
00161         size_t curLineNo() const;
00162 
00170         bool nextLine(bool applyFlags = true);
00172         bool gotoLine(size_t lineNo);
00173 
00183         bool getSection(
00184                   std::string& dest,
00185             const std::string& section,
00186                   size_t*      lineNo = 0
00187         );
00196         bool getValue(
00197                   std::string& dest,
00198             const std::string& section,
00199             const std::string& key
00200         );
00201 
00224         bool seekSection(const std::string& section);
00226         bool eoSection() const;
00236         bool seekKey(
00237             const std::string& section,
00238             const std::string& key
00239         );
00240 
00256         bool addKey(
00257             const std::string& section,
00258             const std::string& key,
00259             const std::string& value
00260         );
00273         bool delKey(
00274             const std::string& section,
00275             const std::string& key
00276         );
00277 
00283         void trimValue(
00284             std::string& value
00285         );
00286 
00288         const char* path() const;
00289 
00290     private:                            // data members
00292         std::ifstream is_;
00294         std::string   curLine_;
00296         size_t        curLineNo_;
00298         Flags         flags_;
00300         std::string   path_;
00301 
00302     private:                            // utility methods
00304         void delComment(std::string& line) const;
00306         bool wsOnly(const std::string& line) const;
00318         bool copy(
00319             std::ofstream& dest,
00320             size_t         first,
00321             size_t         last = (size_t)-1
00322         );
00333         bool replace(const std::string& replacePath);
00334     };                                  // class CfgFile
00335 }                                       // namespace OSB_LIB
00336 
00337 // ************************************************************************
00338 // inline definitions
00339 namespace OSB_LIB {
00340 }                                       // namespace OSB_LIB
00341 #endif                                  // #ifndef _OSBCFGFILE_H_

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