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