ConfigUtils.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef CONFIGUTILS_H
00009 #define CONFIGUTILS_H
00010 
00011 #include "ace/Configuration.h"
00012 #include "dcps_export.h"
00013 #include "dds/DCPS/PoolAllocator.h"
00014 
00015 #include <sstream>
00016 #include <cstdlib>
00017 
00018 namespace OpenDDS {
00019 namespace DCPS {
00020 
00021   /// Helper types and functions for config file parsing
00022   typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ValueMap;
00023   typedef std::pair<OPENDDS_STRING, ACE_Configuration_Section_Key> SubsectionPair;
00024   typedef OPENDDS_LIST(SubsectionPair) KeyList;
00025 
00026 
00027   template <typename T>
00028   bool convertToInteger(const OPENDDS_STRING& s, T& value)
00029   {
00030 #ifdef OPENDDS_SAFETY_PROFILE
00031     char* end;
00032     const long conv = std::strtol(s.c_str(), &end, 10);
00033     if (end == s.c_str()) return false;
00034     value = static_cast<T>(conv);
00035 #else
00036     std::stringstream istr(s.c_str());
00037     if (!(istr >> value) || (istr.peek() != EOF)) return false;
00038 #endif
00039     return true;
00040   }
00041 
00042 
00043   ///     Function that pulls all the values from the
00044   ///     specified ACE Configuration Section and places them in a
00045   ///     value map based on the field name.  Returns the number of
00046   ///     values found in the section (and added to the value map).
00047   ///
00048   ///     cf     ACE_Configuration_Heap object being processed
00049   ///     key    ACE_Configuration_Section_Key object that specifies
00050   ///            the section of the .ini file to process
00051   ///     values Map of field names to values (both OPENDDS_STRING)
00052   ///            that this function will add to.
00053   ///
00054   OpenDDS_Dcps_Export int pullValues( ACE_Configuration_Heap& cf,
00055                                       const ACE_Configuration_Section_Key& key,
00056                                       ValueMap& values );
00057 
00058   ///     Function that processes the specified ACE Configuration Section
00059   ///     for subsections.  If multiple levels of subsections are found,
00060   ///     a non-zero value is returned to indicate the error.
00061   ///     All valid subsection will be placed into the supplied
00062   ///     KeyList (std::pair<> of the subsection number and
00063   ///     ACE_Configuration_Section_Key).  A return value of zero indicates
00064   ///     error-free success.
00065   ///
00066   ///
00067   ///     cf              ACE_Configuration_Heap object being processed
00068   ///     key             ACE_Configuration_Section_Key object that
00069   ///                     specifies the section of the .ini file to process
00070   ///     subsections     List of subsections found (list contains a
00071   ///                     std::pair<> of the subsection number and
00072   ///                     ACE_Configuration_Section_Key).
00073   ///
00074   OpenDDS_Dcps_Export int processSections( ACE_Configuration_Heap& cf,
00075                                            const ACE_Configuration_Section_Key& key,
00076                                            KeyList& subsections );
00077 
00078 } // namespace DCPS
00079 } // namespace OpenDDS
00080 
00081 #endif /* CONFIGUTILS_H */

Generated on Fri Feb 12 20:05:19 2016 for OpenDDS by  doxygen 1.4.7