OptionFile.h

Go to the documentation of this file.
00001 /**
00002 \file    OptionFile.h 
00003 \brief   A class for handling option files. \n
00004          ';' delimits a comment to follow. \n
00005          The general format is: \n
00006          field, comment = value ; comment \n
00007          e.g. \n
00008          ; A data value will follow this comment \n
00009          DataValue, (some comment about it) = 88 ; another comment here \n
00010 
00011 \author  Glenn D. MacGougan (GDM)
00012 \date    2007-11-28
00013 \since   2006-12-07
00014 
00015 \b "LICENSE INFORMATION" \n
00016 Copyright (c) 2007, refer to 'author' doxygen tags \n
00017 All rights reserved. \n
00018 
00019 Redistribution and use in source and binary forms, with or without
00020 modification, are permitted provided the following conditions are met: \n
00021 
00022 - Redistributions of source code must retain the above copyright
00023   notice, this list of conditions and the following disclaimer. \n
00024 - Redistributions in binary form must reproduce the above copyright
00025   notice, this list of conditions and the following disclaimer in the
00026   documentation and/or other materials provided with the distribution. \n
00027 - The name(s) of the contributor(s) may not be used to endorse or promote 
00028   products derived from this software without specific prior written 
00029   permission. \n
00030 
00031 THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS 
00032 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
00033 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00034 DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00035 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00036 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
00037 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00038 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00039 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00040 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00041 SUCH DAMAGE.
00042 */
00043 
00044 #ifndef _OPTIONFILE_H_
00045 #define _OPTIONFILE_H_
00046 
00047 #include <string> // using std::string
00048 
00049 ///  \brief   A class for handling option files. 
00050 ///           ';' delimits a comment to follow. \n
00051 ///           The general format is: \n
00052 ///           field, comment = value ; comment \n
00053 ///
00054 class OptionFile
00055 {
00056 protected: // Encapsulated Types
00057 
00058   typedef struct
00059   {
00060     std::string Field;
00061     std::string Comment;
00062     std::string Value;
00063     std::string PostValueComment;
00064   } stOption;
00065 
00066 
00067 public: // Lifecycle
00068 
00069   /// \brief    OptionFile destructor
00070   virtual ~OptionFile(); 
00071 
00072   /// \brief    The default constructor.
00073   OptionFile();
00074 
00075   /// \brief    The disabled copy constructor.
00076   OptionFile( OptionFile& rhs ) {} ;
00077 
00078 
00079 public: 
00080 
00081   /// \brief    Reads in the options
00082   /// \return   true if successful, false otherwise
00083   bool ReadOptionFile( const std::string OptionFilePath );
00084 
00085   /// \brief    Get data from a field
00086   /// \return   true if successful, false otherwise.
00087   bool GetValue( const std::string Field, std::string &Value );
00088 
00089   /// \brief    Get data from a field
00090   /// \return   true if successful, false otherwise.    
00091   bool GetValue( const std::string Field, double &value );
00092 
00093   /// \brief    Get data from a field
00094   /// \return   true if successful, false otherwise.    
00095   bool GetValue( const std::string Field, float  &value );
00096 
00097   /// \brief    Get data from a field
00098   /// \return   true if successful, false otherwise.
00099   bool GetValue( const std::string Field, short  &value );
00100 
00101   /// \brief    Get data from a field
00102   /// \return   true if successful, false otherwise.    
00103   bool GetValue( const std::string Field, unsigned short &value );
00104 
00105   /// \brief    Get data from a field
00106   /// \return   true if successful, false otherwise.    
00107   bool GetValue( const std::string Field, int &value );
00108 
00109   /// \brief    Get data from a field
00110   /// \return   true if successful, false otherwise.    
00111   bool GetValue( const std::string Field, unsigned int &value );
00112 
00113   /// \brief    Get data from a field
00114   /// \return   true if successful, false otherwise.    
00115   bool GetValue( const std::string Field, bool &value );
00116 
00117   /// \brief    Get an array of integers up to a maximum number of items.
00118   /// \return   true if successful, false otherwise.    
00119   bool GetValueArray( 
00120     const std::string Field,      //!< The field identifier
00121     int *intArray,           //!< The pointer to the integer array.
00122     const unsigned maxItems, //!< The maximum number of elements in the array.
00123     unsigned &nrItems        //!< The number of valid items read into the array.
00124     );
00125 
00126   /// \brief    Get an array of double up to a maximum number of items.
00127   /// \return   true if successful, false otherwise.    
00128   bool GetValueArray( 
00129     const std::string Field,      //!< The field identifier
00130     double *dArray,          //!< The pointer to the integer array.
00131     const unsigned maxItems, //!< The maximum number of elements in the array.
00132     unsigned &nrItems        //!< The number of valid items read into the array.
00133     );
00134 
00135   /// \brief    Get a double value in degress from a Degree Minutes Seconds value
00136   bool GetDMSValue( const std::string Field, double &dms );
00137 
00138   /// \brief    Get the comment for the field specified.
00139   /// \return   true if successful, false otherwise.    
00140   bool GetComment( const std::string Field, std::string &Comment );
00141 
00142   /// \brief    Get the comment for the field specified present after the VALUE 
00143   ///           field. i.e. FIELD, COMMENT = VALUE ; POST-VALUE-COMMENT    
00144   /// \return   true if successful, false otherwise.        
00145   bool GetPostValueComment( const std::string Field, std::string &PostValueComment );
00146 
00147   /// \brief    Get the number of options available.
00148   /// \returns  The number of options.
00149   unsigned GetNumberOfOptions() { return m_nrOptions; }
00150 
00151 public: // Assignment
00152 
00153   /// \brief    Disabled operator= overload
00154   const OptionFile& operator=( const OptionFile& src ) {};
00155 
00156 
00157 protected: // Internal Implementation
00158 
00159   /// \return   true if file exists
00160   bool DoesFileExist( const std::string& OptionFilePath );
00161 
00162   /// \return   true if the find was successful, and the data was set
00163   bool FindField( 
00164     const std::string &Field, 
00165     std::string &Comment,
00166     std::string &Value,
00167     std::string &PostValueComment );
00168 
00169 protected: // Member Variables
00170 
00171   /// The array of options.
00172   stOption *m_Options;
00173 
00174   /// The number of valid options.
00175   unsigned m_nrOptions;
00176 
00177   /// The path to the option file.
00178   std::string m_OptionFilePathUsed;
00179 
00180 };
00181 
00182 
00183 #endif // _OPTIONFILE_H_
SourceForge.net Logo