Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Configuration_Import_Export.h

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

Generated on Mon Jun 16 11:19:24 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002