3 //=============================================================================
5 * @file Configuration_Import_Export.h
7 * @author Jerry D. Odenwelder Jr. <jerry.o@mindspring.com>
8 * Chris Hafey <chris@stentorsoft.com>
10 * Classes defined in this file provide the ability to import and export
11 * ACE Configuration objects to/from disk files. The base class
12 * ACE_Config_ImpExp_Base provides the common functionality and the derived
13 * classes implement the import/export functionality for the specific format.
16 * - Add locking for thread safety.
17 * - Provide ability to read file in one format and write in another.
18 * - See todo's in each class
20 //=============================================================================
22 #ifndef ACE_CONFIGURATION_IMPORT_EXPORT_H
23 #define ACE_CONFIGURATION_IMPORT_EXPORT_H
24 #include /**/ "ace/pre.h"
26 #include "ace/Configuration.h"
27 #include "ace/SString.h"
29 #if !defined (ACE_LACKS_PRAGMA_ONCE)
31 #endif /* ACE_LACKS_PRAGMA_ONCE */
33 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
36 * @class ACE_Config_ImpExp_Base
38 * @brief Base class for file import/export configuration.
40 * This class provides base functionality for configuration objects
41 * that are persisted in files. It takes an ACE_Configuration
42 * object that it populates with the data read.
44 class ACE_Export ACE_Config_ImpExp_Base
47 /// Constructor taking the ACE_Configuration to import/export to
48 ACE_Config_ImpExp_Base (ACE_Configuration
& config
);
53 virtual ~ACE_Config_ImpExp_Base () = default;
56 * Imports the configuration database from @a filename.
57 * No existing data is removed.
59 virtual int import_config (const ACE_TCHAR
* filename
) = 0;
62 * This method exports the entire configuration database to @a filename.
63 * Once the file is opened this method calls 'export_section' passing
66 virtual int export_config (const ACE_TCHAR
* filename
) = 0;
69 ACE_Configuration
&config_
;
72 ACE_Config_ImpExp_Base (const ACE_Config_ImpExp_Base
&) = delete;
73 ACE_Config_ImpExp_Base
& operator= (const ACE_Config_ImpExp_Base
&) = delete;
77 * @class ACE_Registry_ImpExp
79 * @brief Configuration object that imports/exports data to a file formatted
80 * using the Win32 Registry file export format. This format looks like
83 * "key"=dword: numeric data in hexadecimal format
84 * "key"=hex: binary data
87 * - Add dynamic buffer when importing. currently it will not allow
88 * importing of values greater than a fixed amount (4096 bytes)
90 class ACE_Export ACE_Registry_ImpExp
: public ACE_Config_ImpExp_Base
94 ACE_Registry_ImpExp (ACE_Configuration
&);
97 virtual ~ACE_Registry_ImpExp () = default;
100 * Imports the configuration database from @a filename.
101 * No existing data is removed.
103 virtual int import_config (const ACE_TCHAR
* filename
);
106 * This method exports the entire configuration database to @a filename.
107 * Once the file is opened this method calls export_section() passing
110 virtual int export_config (const ACE_TCHAR
* filename
);
113 int export_section (const ACE_Configuration_Section_Key
& section
,
114 const ACE_TString
& path
,
117 int process_previous_line_format (ACE_TCHAR
* buffer
,
118 ACE_Configuration_Section_Key
& section
);
120 ACE_Registry_ImpExp (const ACE_Registry_ImpExp
&) = delete;
121 ACE_Registry_ImpExp
& operator= (const ACE_Registry_ImpExp
&) = delete;
125 * @class ACE_Ini_ImpExp
127 * @brief Imports the configuration database from filename as strings.
128 * Allows non-typed values. (no #, dword: hex:, etc. prefixes) and
129 * skips whitespace (tabs and spaces) as in standard .ini and .conf
130 * files. Values (to right of equal sign) can be double quote
131 * delimited to embed tabs and spaces in the string.
132 * Caller must convert string to type.
134 * This method allows for lines in the .ini or .conf file like this:
139 * Heading = "ACE - Adaptive Communication Environment"
141 * (note leading whitespace (tabs) in examples below)
144 * TraceLevel = 6 # Can comment lines like this
145 * Justification = left_justified
147 * The caller can then retrieve the string with the regular
148 * get_string_value() function and convert the string to the
152 * - Strings with embedded newlines cause the import to fail
153 * - Strings with embedded quotes " cause the import to fail
154 * - Importing/exporting for values in the root section does not work
155 * - Add dynamic buffer when importing. currently it will not allow
156 * importing of values greater than a fixed amount (4096 bytes)
158 class ACE_Export ACE_Ini_ImpExp
: public ACE_Config_ImpExp_Base
164 ACE_Ini_ImpExp (ACE_Configuration
&);
169 virtual ~ACE_Ini_ImpExp () = default;
172 * Imports the configuration database from @a filename.
173 * No existing data is removed.
175 virtual int import_config (const ACE_TCHAR
* filename
);
178 * This method exports the entire configuration database to @a filename.
179 * Once the file is opened this method calls export_section() passing
182 virtual int export_config (const ACE_TCHAR
* filename
);
186 * Method provided by derived classes in order to write one section
187 * to the file specified. Called by export_config() when exporting
188 * the entire configuration object.
190 int export_section (const ACE_Configuration_Section_Key
& section
,
191 const ACE_TString
& path
,
195 * Method to squish leading and trailing whitespaces in a string.
196 * Whitespace is defined as: spaces (' '), tabs ('\\t') or cr/lf.
197 * Returns a pointer to the first non-whitespace character in the
198 * buffer provided, or a pointer to the terminating null if the string
199 * is all whitespace. The terminating null is moved forward to the
200 * first character past the last non-whitespace.
202 ACE_TCHAR
*squish (ACE_TCHAR
*src
);
204 ACE_Ini_ImpExp (const ACE_Ini_ImpExp
&) = delete;
205 ACE_Ini_ImpExp
& operator= (const ACE_Ini_ImpExp
&) = delete;
208 ACE_END_VERSIONED_NAMESPACE_DECL
210 #include /**/ "ace/post.h"
211 #endif /* ACE_CONFIGURATION_IMPORT_EXPORT_H */