Configuration_Import_Export.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  * @file Configuration_Import_Export.h
00006  *
00007  *  Configuration_Import_Export.h,v 4.10 2005/10/28 16:14:52 ossama Exp
00008  *
00009  * @author Jerry D. Odenwelder Jr. <jerry.o@mindspring.com>
00010  *         Chris Hafey <chris@stentorsoft.com>
00011  *
00012  * Classes defined in this file provide the ability to import and export
00013  * ACE Configuration objects to/from disk files.  The base class
00014  * ACE_Config_ImpExp_Base provides the common functionality and the derived
00015  * classes implement the import/export functionality for the specific format.
00016  *
00017  * @todo
00018  *  - Add locking for thread safety.
00019  *  - Provide ability to read file in one format and write in another.
00020  *  - See todo's in each class
00021  */
00022 //=============================================================================
00023 
00024 #ifndef ACE_CONFIGURATION_IMPORT_EXPORT_H
00025 #define ACE_CONFIGURATION_IMPORT_EXPORT_H
00026 #include /**/ "ace/pre.h"
00027 
00028 #include "ace/Configuration.h"
00029 #include "ace/SString.h"
00030 
00031 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00032 # pragma once
00033 #endif /* ACE_LACKS_PRAGMA_ONCE */
00034 
00035 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00036 
00037 /**
00038  * @class ACE_Config_ImpExp_Base
00039  *
00040  * @brief Base class for file import/export configuration.
00041  *
00042  * This class provides base functionality for configuration objects
00043  * that are persisted in files.  It takes an ACE_Configuration
00044  * object that it populates with the data read.
00045  *
00046  */
00047 class ACE_Export ACE_Config_ImpExp_Base
00048 {
00049 public:
00050   /// Constructor taking the ACE_Configuration to import/export to
00051   ACE_Config_ImpExp_Base (ACE_Configuration& config);
00052 
00053   /**
00054    * Destructor
00055    */
00056   virtual ~ACE_Config_ImpExp_Base (void);
00057 
00058    /**
00059    * Imports the configuration database from @a filename.
00060    * No existing data is removed.
00061    */
00062   virtual int import_config (const ACE_TCHAR* filename) = 0;
00063 
00064   /**
00065    * This method exports the entire configuration database to @a filename.
00066    * Once the file is opened this method calls 'export_section' passing
00067    * the root section.
00068    */
00069   virtual int export_config (const ACE_TCHAR* filename) = 0;
00070 
00071 protected:
00072   ACE_Configuration &config_;
00073 
00074 private:
00075   ACE_Config_ImpExp_Base (const ACE_Config_ImpExp_Base&);
00076   ACE_Config_ImpExp_Base& operator= (const ACE_Config_ImpExp_Base&);
00077 };
00078 
00079 /**
00080  * @class ACE_Registry_ImpExp
00081  *
00082  * @brief Configuration object that imports/exports data to a file formatted
00083  *        using the Win32 Registry file export format.  This format looks like
00084  *        [Section]
00085  *        "key"="String Data"
00086  *        "key"=dword: numeric data in hexidecimal format
00087  *        "key"=hex: binary data
00088  *
00089  * @todo
00090  *  - Add dynamic buffer when importing.  currently it will not allow
00091  *    importing of values greater than a fixed ammount (4096 bytes)
00092  *
00093  */
00094 class ACE_Export ACE_Registry_ImpExp : public ACE_Config_ImpExp_Base
00095 {
00096 public:
00097   /// Construction
00098   ACE_Registry_ImpExp (ACE_Configuration&);
00099 
00100   /// Destruction.
00101   virtual ~ACE_Registry_ImpExp (void);
00102 
00103   /**
00104    * Imports the configuration database from filename.
00105    * No existing data is removed.
00106    */
00107   virtual int import_config (const ACE_TCHAR* filename);
00108 
00109   /**
00110    * This method exports the entire configuration database to @a filename.
00111    * Once the file is opened this method calls export_section() passing
00112    * the root section.
00113    */
00114   virtual int export_config (const ACE_TCHAR* filename);
00115 
00116 private:
00117   int export_section (const ACE_Configuration_Section_Key& section,
00118                       const ACE_TString& path,
00119                       FILE* out);
00120 
00121   int process_previous_line_format (ACE_TCHAR* buffer,
00122                                     ACE_Configuration_Section_Key& section);
00123 
00124   ACE_Registry_ImpExp ( const ACE_Registry_ImpExp&);
00125   ACE_Registry_ImpExp& operator= ( const ACE_Registry_ImpExp&);
00126 };
00127 
00128 /**
00129  * @class ACE_Ini_ImpExp
00130  *
00131  * @brief Imports the configuration database from filename as strings.
00132  *        Allows non-typed values. (no #, dword: hex:, etc. prefixes) and
00133  *        skips whitespace (tabs and spaces) as in standard .ini and .conf
00134  *        files. Values (to right of equal sign) can be double quote
00135  *        delimited to embed tabs and spaces in the string.
00136  *        Caller must convert string to type.
00137  *
00138  *        This method allows for lines in the .ini or .conf file like this:
00139  *
00140  *        TimeToLive     =    100
00141  *        Delay          =    FALSE
00142  *        Flags          =    FF34
00143  *        Heading        =    "ACE - Adaptive Communication Environment"
00144  *
00145  * (note leading whitespace (tabs) in examples below)
00146  *
00147  *        SeekIndex  =  14
00148  *        TraceLevel = 6      # Can comment lines like this
00149  *              Justification = left_justified
00150  *
00151  *        The caller can then retrieve the string with the regular
00152  *        <get_string_value> function and convert the string to the
00153  *        desired data type.
00154  *
00155  * @todo
00156  *  - Strings with embedded newlines cause the import to fail
00157  *  - Strings with embedded quotes " cause the import to fail
00158  *  - Importing/exporting for values in the root section does not work
00159  *  - Add dynamic buffer when importing.  currently it will not allow
00160  *    importing of values greater than a fixed ammount (4096 bytes)
00161 */
00162 class ACE_Export ACE_Ini_ImpExp  : public ACE_Config_ImpExp_Base
00163 {
00164 public:
00165   /**
00166    * Construction
00167    */
00168   ACE_Ini_ImpExp (ACE_Configuration&);
00169 
00170   /**
00171    * Destructor
00172    */
00173   virtual ~ACE_Ini_ImpExp (void);
00174 
00175   /**
00176    * Imports the configuration database from filename.
00177    * No existing data is removed.
00178    */
00179   virtual int import_config (const ACE_TCHAR* filename);
00180 
00181   /**
00182    * This method exports the entire configuration database to @a filename.
00183    * Once the file is opened this method calls export_section() passing
00184    * the root section.
00185    */
00186   virtual int export_config (const ACE_TCHAR* filename);
00187 
00188 private:
00189   /**
00190    * Method provided by derived classes in order to write one section
00191    * to the file specified.  Called by export_config() when exporting
00192    * the entire configuration object.
00193    */
00194   int export_section (const ACE_Configuration_Section_Key& section,
00195                       const ACE_TString& path,
00196                       FILE* out);
00197 
00198   /**
00199    * Method to squish leading and trailing whitespaces in a string.
00200    * Whitespace is defined as: spaces (' '), tabs ('\\t') or cr/lf.
00201    * Returns a pointer to the first non-whitespace character in the
00202    * buffer provided, or a pointer to the terminating null if the string
00203    * is all whitespace. The terminating null is moved forward to the
00204    * first character past the last non-whitespace.
00205    */
00206   ACE_TCHAR *squish (ACE_TCHAR *src);
00207 
00208   ACE_Ini_ImpExp (const ACE_Ini_ImpExp&);
00209   ACE_Ini_ImpExp& operator= (const ACE_Ini_ImpExp&);
00210 };
00211 
00212 ACE_END_VERSIONED_NAMESPACE_DECL
00213 
00214 #include /**/ "ace/post.h"
00215 #endif /* ACE_CONFIGURATION_IMPORT_EXPORT_H */

Generated on Thu Nov 9 09:41:48 2006 for ACE by doxygen 1.3.6