ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Classes | Public Types | Public Member Functions | List of all members
sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER > Class Template Reference

#include <calibration.hpp>

Classes

class  Converter
 
struct  Entry
 
class  FileWriter
 
class  OutputWriter
 
class  StreamWriter
 
class  StringWriter
 

Public Types

typedef SI_CHAR SI_CHAR_T
 
typedef std::multimap< Entry, const SI_CHAR *, typename Entry::KeyOrderTKeyVal
 
typedef std::map< Entry, TKeyVal, typename Entry::KeyOrderTSection
 
typedef std::list< EntryTNamesDepend
 

Public Member Functions

 CSimpleIniTempl (bool a_bIsUtf8=false, bool a_bMultiKey=false, bool a_bMultiLine=false)
 
 ~CSimpleIniTempl ()
 
void Reset ()
 
bool IsEmpty () const
 
SI_Error LoadFile (const char *a_pszFile)
 
SI_Error LoadFile (const SI_WCHAR_T *a_pwszFile)
 
SI_Error LoadFile (FILE *a_fpFile)
 
SI_Error LoadData (std::istream &a_istream)
 
SI_Error LoadData (const std::string &a_strData)
 
SI_Error LoadData (const char *a_pData, size_t a_uDataLen)
 
SI_Error SaveFile (const char *a_pszFile, bool a_bAddSignature=true) const
 
SI_Error SaveFile (const SI_WCHAR_T *a_pwszFile, bool a_bAddSignature=true) const
 
SI_Error SaveFile (FILE *a_pFile, bool a_bAddSignature=false) const
 
SI_Error Save (OutputWriter &a_oOutput, bool a_bAddSignature=false) const
 
SI_Error Save (std::ostream &a_ostream, bool a_bAddSignature=false) const
 
SI_Error Save (std::string &a_sBuffer, bool a_bAddSignature=false) const
 
void GetAllSections (TNamesDepend &a_names) const
 
bool GetAllKeys (const SI_CHAR *a_pSection, TNamesDepend &a_names) const
 
bool GetAllValues (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, TNamesDepend &a_values) const
 
int GetSectionSize (const SI_CHAR *a_pSection) const
 
const TKeyValGetSection (const SI_CHAR *a_pSection) const
 
const SI_CHAR * GetValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pDefault=NULL, bool *a_pHasMultiple=NULL) const
 
long GetLongValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, long a_nDefault=0, bool *a_pHasMultiple=NULL) const
 
double GetDoubleValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, double a_nDefault=0, bool *a_pHasMultiple=NULL) const
 
bool GetBoolValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bDefault=false, bool *a_pHasMultiple=NULL) const
 
SI_Error SetValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false)
 
SI_Error SetLongValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, long a_nValue, const SI_CHAR *a_pComment=NULL, bool a_bUseHex=false, bool a_bForceReplace=false)
 
SI_Error SetDoubleValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, double a_nValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false)
 
SI_Error SetBoolValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bValue, const SI_CHAR *a_pComment=NULL, bool a_bForceReplace=false)
 
bool Delete (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, bool a_bRemoveEmpty=false)
 
bool DeleteValue (const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pValue, bool a_bRemoveEmpty=false)
 
Converter GetConverter () const
 
Settings
void SetUnicode (bool a_bIsUtf8=true)
 
bool IsUnicode () const
 
void SetMultiKey (bool a_bAllowMultiKey=true)
 
bool IsMultiKey () const
 
void SetMultiLine (bool a_bAllowMultiLine=true)
 
bool IsMultiLine () const
 
void SetSpaces (bool a_bSpaces=true)
 
bool UsingSpaces () const
 

Detailed Description

template<class SI_CHAR, class SI_STRLESS, class SI_CONVERTER>
class sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >

Definition at line 127 of file calibration.hpp.

Member Typedef Documentation

◆ SI_CHAR_T

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
typedef SI_CHAR sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SI_CHAR_T

Definition at line 129 of file calibration.hpp.

◆ TKeyVal

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
typedef std::multimap<Entry, const SI_CHAR *, typename Entry::KeyOrder> sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::TKeyVal

map keys to values

Definition at line 194 of file calibration.hpp.

◆ TNamesDepend

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
typedef std::list<Entry> sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::TNamesDepend

set of dependent string pointers. Note that these pointers are dependent on memory owned by CSimpleIni.

Definition at line 202 of file calibration.hpp.

◆ TSection

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
typedef std::map<Entry, TKeyVal, typename Entry::KeyOrder> sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::TSection

map sections to key/value map

Definition at line 197 of file calibration.hpp.

Constructor & Destructor Documentation

◆ CSimpleIniTempl()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::CSimpleIniTempl ( bool  a_bIsUtf8 = false,
bool  a_bMultiKey = false,
bool  a_bMultiLine = false 
)

Default constructor.

Parameters
a_bIsUtf8See the method SetUnicode() for details.
a_bMultiKeySee the method SetMultiKey() for details.
a_bMultiLineSee the method SetMultiLine() for details.

Definition at line 1144 of file calibration.hpp.

1149 : m_pData(0)
1150 , m_uDataLen(0)
1151 , m_pFileComment(NULL)
1152 , m_bStoreIsUtf8(a_bIsUtf8)
1153 , m_bAllowMultiKey(a_bAllowMultiKey)
1154 , m_bAllowMultiLine(a_bAllowMultiLine)
1155 , m_bSpaces(true)
1156 , m_nOrder(0) {
1157 }

◆ ~CSimpleIniTempl()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::~CSimpleIniTempl

Destructor

Definition at line 1160 of file calibration.hpp.

1160  {
1161  Reset();
1162 }

Member Function Documentation

◆ Delete()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Delete ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
bool  a_bRemoveEmpty = false 
)

Delete an entire section, or a key from a section. Note that the data returned by GetSection is invalid and must not be used after anything has been deleted from that section using this method. Note when multiple keys is enabled, this will delete all keys with that name; to selectively delete individual key/values, use DeleteValue.

Parameters
a_pSectionSection to delete key from, or if a_pKey is NULL, the section to remove.
a_pKeyKey to remove from the section. Set to NULL to remove the entire section.
a_bRemoveEmptyIf the section is empty after this key has been deleted, should the empty section be removed?
Returns
true Key or section was deleted.
false Key or section was not found.

Definition at line 2384 of file calibration.hpp.

2388  {
2389  return DeleteValue(a_pSection, a_pKey, NULL, a_bRemoveEmpty);
2390 }
bool DeleteValue(const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pValue, bool a_bRemoveEmpty=false)

◆ DeleteValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::DeleteValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
const SI_CHAR *  a_pValue,
bool  a_bRemoveEmpty = false 
)

Delete an entire section, or a key from a section. If value is provided, only remove keys with the value. Note that the data returned by GetSection is invalid and must not be used after anything has been deleted from that section using this method. Note when multiple keys is enabled, all keys with the value will be deleted.

Parameters
a_pSectionSection to delete key from, or if a_pKey is NULL, the section to remove.
a_pKeyKey to remove from the section. Set to NULL to remove the entire section.
a_pValueValue of key to remove from the section. Set to NULL to remove all keys.
a_bRemoveEmptyIf the section is empty after this key has been deleted, should the empty section be removed?
Returns
true Key/value or section was deleted.
false Key/value or section was not found.

Definition at line 2394 of file calibration.hpp.

2399  {
2400  if (!a_pSection) {
2401  return false;
2402  }
2403 
2404  typename TSection::iterator iSection = m_data.find(a_pSection);
2405  if (iSection == m_data.end()) {
2406  return false;
2407  }
2408 
2409  // remove a single key if we have a keyname
2410  if (a_pKey) {
2411  typename TKeyVal::iterator iKeyVal = iSection->second.find(a_pKey);
2412  if (iKeyVal == iSection->second.end()) {
2413  return false;
2414  }
2415 
2416  const static SI_STRLESS isLess = SI_STRLESS();
2417 
2418  // remove any copied strings and then the key
2419  typename TKeyVal::iterator iDelete;
2420  bool bDeleted = false;
2421  do {
2422  iDelete = iKeyVal++;
2423 
2424  if (a_pValue == NULL ||
2425  (isLess(a_pValue, iDelete->second) == false &&
2426  isLess(iDelete->second, a_pValue) == false)) {
2427  DeleteString(iDelete->first.pItem);
2428  DeleteString(iDelete->second);
2429  iSection->second.erase(iDelete);
2430  bDeleted = true;
2431  }
2432  } while (iKeyVal != iSection->second.end()
2433  && !IsLess(a_pKey, iKeyVal->first.pItem));
2434 
2435  if (!bDeleted) {
2436  return false;
2437  }
2438 
2439  // done now if the section is not empty or we are not pruning away
2440  // the empty sections. Otherwise let it fall through into the section
2441  // deletion code
2442  if (!a_bRemoveEmpty || !iSection->second.empty()) {
2443  return true;
2444  }
2445  } else {
2446  // delete all copied strings from this section. The actual
2447  // entries will be removed when the section is removed.
2448  typename TKeyVal::iterator iKeyVal = iSection->second.begin();
2449  for (; iKeyVal != iSection->second.end(); ++iKeyVal) {
2450  DeleteString(iKeyVal->first.pItem);
2451  DeleteString(iKeyVal->second);
2452  }
2453  }
2454 
2455  // delete the section itself
2456  DeleteString(iSection->first.pItem);
2457  m_data.erase(iSection);
2458 
2459  return true;
2460 }

◆ GetAllKeys()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetAllKeys ( const SI_CHAR *  a_pSection,
TNamesDepend a_names 
) const

Retrieve all unique key names in a section. The sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example. Only unique key names are returned.

NOTE! This structure contains only pointers to strings. The actual string data is stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset() while these strings are in use!

Parameters
a_pSectionSection to request data for
a_namesList that will receive all of the key names. See note above!
Returns
true Section was found.
false Matching section was not found.

Definition at line 2143 of file calibration.hpp.

2146  {
2147  a_names.clear();
2148 
2149  if (!a_pSection) {
2150  return false;
2151  }
2152 
2153  typename TSection::const_iterator iSection = m_data.find(a_pSection);
2154  if (iSection == m_data.end()) {
2155  return false;
2156  }
2157 
2158  const TKeyVal & section = iSection->second;
2159  const SI_CHAR * pLastKey = NULL;
2160  typename TKeyVal::const_iterator iKeyVal = section.begin();
2161  for (int n = 0; iKeyVal != section.end(); ++iKeyVal, ++n) {
2162  if (!pLastKey || IsLess(pLastKey, iKeyVal->first.pItem)) {
2163  a_names.push_back(iKeyVal->first);
2164  pLastKey = iKeyVal->first.pItem;
2165  }
2166  }
2167 
2168  return true;
2169 }
std::multimap< Entry, const SI_CHAR *, typename Entry::KeyOrder > TKeyVal

◆ GetAllSections()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetAllSections ( TNamesDepend a_names) const

Retrieve all section names. The list is returned as an STL vector of names and can be iterated or searched as necessary. Note that the sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example.

NOTE! This structure contains only pointers to strings. The actual string data is stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset() while these pointers are in use!

Parameters
a_namesVector that will receive all of the section names. See note above!

Definition at line 2131 of file calibration.hpp.

2133  {
2134  a_names.clear();
2135  typename TSection::const_iterator i = m_data.begin();
2136  for (int n = 0; i != m_data.end(); ++i, ++n) {
2137  a_names.push_back(i->first);
2138  }
2139 }

◆ GetAllValues()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetAllValues ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
TNamesDepend a_values 
) const

Retrieve all values for a specific key. This method can be used when multiple keys are both enabled and disabled. Note that the sort order of the returned strings is NOT DEFINED. You can sort the names into the load order if desired. Search this file for ".sort" for an example.

NOTE! The returned values are pointers to string data stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset while you are using this pointer!

Parameters
a_pSectionSection to search
a_pKeyKey to search for
a_valuesList to return if the key is not found
Returns
true Key was found.
false Matching section/key was not found.

Definition at line 2049 of file calibration.hpp.

2053  {
2054  a_values.clear();
2055 
2056  if (!a_pSection || !a_pKey) {
2057  return false;
2058  }
2059  typename TSection::const_iterator iSection = m_data.find(a_pSection);
2060  if (iSection == m_data.end()) {
2061  return false;
2062  }
2063  typename TKeyVal::const_iterator iKeyVal = iSection->second.find(a_pKey);
2064  if (iKeyVal == iSection->second.end()) {
2065  return false;
2066  }
2067 
2068  // insert all values for this key
2069  a_values.push_back(Entry(iKeyVal->second, iKeyVal->first.pComment, iKeyVal->first.nOrder));
2070  if (m_bAllowMultiKey) {
2071  ++iKeyVal;
2072  while (iKeyVal != iSection->second.end() && !IsLess(a_pKey, iKeyVal->first.pItem)) {
2073  a_values.push_back(Entry(iKeyVal->second, iKeyVal->first.pComment, iKeyVal->first.nOrder));
2074  ++iKeyVal;
2075  }
2076  }
2077 
2078  return true;
2079 }

◆ GetBoolValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetBoolValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
bool  a_bDefault = false,
bool *  a_pHasMultiple = NULL 
) const

Retrieve a boolean value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.

Strings starting with "t", "y", "on" or "1" are returned as logically true. Strings starting with "f", "n", "of" or "0" are returned as logically false. For all other values the default is returned. Character comparisons are case-insensitive.

Parameters
a_pSectionSection to search
a_pKeyKey to search for
a_bDefaultValue to return if the key is not found
a_pHasMultipleOptionally receive notification of if there are multiple entries for this key.
Returns
a_nDefault Key was not found in the section
other Value of the key

Definition at line 1990 of file calibration.hpp.

1995  {
1996  // return the default if we don't have a value
1997  const SI_CHAR * pszValue = GetValue(a_pSection, a_pKey, NULL, a_pHasMultiple);
1998  if (!pszValue || !*pszValue) return a_bDefault;
1999 
2000  // we only look at the minimum number of characters
2001  switch (pszValue[0]) {
2002  case 't': case 'T': // true
2003  case 'y': case 'Y': // yes
2004  case '1': // 1 (one)
2005  return true;
2006 
2007  case 'f': case 'F': // false
2008  case 'n': case 'N': // no
2009  case '0': // 0 (zero)
2010  return false;
2011 
2012  case 'o': case 'O':
2013  if (pszValue[1] == 'n' || pszValue[1] == 'N') return true; // on
2014  if (pszValue[1] == 'f' || pszValue[1] == 'F') return false; // off
2015  break;
2016  }
2017 
2018  // no recognized value, return the default
2019  return a_bDefault;
2020 }
const SI_CHAR * GetValue(const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, const SI_CHAR *a_pDefault=NULL, bool *a_pHasMultiple=NULL) const

◆ GetConverter()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
Converter sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetConverter ( ) const
inline

Return a conversion object to convert text to the same encoding as is used by the Save(), SaveFile() and SaveString() functions. Use this to prepare the strings that you wish to append or prepend to the output INI data.

Definition at line 991 of file calibration.hpp.

991  {
992  return Converter(m_bStoreIsUtf8);
993  }

◆ GetDoubleValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
double sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetDoubleValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
double  a_nDefault = 0,
bool *  a_pHasMultiple = NULL 
) const

Retrieve a numeric value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.

Parameters
a_pSectionSection to search
a_pKeyKey to search for
a_nDefaultValue to return if the key is not found
a_pHasMultipleOptionally receive notification of if there are multiple entries for this key.
Returns
a_nDefault Key was not found in the section
other Value of the key

Definition at line 1930 of file calibration.hpp.

1935  {
1936  // return the default if we don't have a value
1937  const SI_CHAR * pszValue = GetValue(a_pSection, a_pKey, NULL, a_pHasMultiple);
1938  if (!pszValue || !*pszValue) return a_nDefault;
1939 
1940  // convert to UTF-8/MBCS which for a numeric value will be the same as ASCII
1941  char szValue[64] = {0};
1942  SI_CONVERTER c(m_bStoreIsUtf8);
1943  if (!c.ConvertToStore(pszValue, szValue, sizeof (szValue))) {
1944  return a_nDefault;
1945  }
1946 
1947  char * pszSuffix = NULL;
1948  double nValue = strtod(szValue, &pszSuffix);
1949 
1950  // any invalid strings will return the default value
1951  if (!pszSuffix || *pszSuffix) {
1952  return a_nDefault;
1953  }
1954 
1955  return nValue;
1956 }

◆ GetLongValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
long sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetLongValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
long  a_nDefault = 0,
bool *  a_pHasMultiple = NULL 
) const

Retrieve a numeric value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.

Parameters
a_pSectionSection to search
a_pKeyKey to search for
a_nDefaultValue to return if the key is not found
a_pHasMultipleOptionally receive notification of if there are multiple entries for this key.
Returns
a_nDefault Key was not found in the section
other Value of the key

Definition at line 1862 of file calibration.hpp.

1867  {
1868  // return the default if we don't have a value
1869  const SI_CHAR * pszValue = GetValue(a_pSection, a_pKey, NULL, a_pHasMultiple);
1870  if (!pszValue || !*pszValue) return a_nDefault;
1871 
1872  // convert to UTF-8/MBCS which for a numeric value will be the same as ASCII
1873  char szValue[64] = {0};
1874  SI_CONVERTER c(m_bStoreIsUtf8);
1875  if (!c.ConvertToStore(pszValue, szValue, sizeof (szValue))) {
1876  return a_nDefault;
1877  }
1878 
1879  // handle the value as hex if prefaced with "0x"
1880  long nValue = a_nDefault;
1881  char * pszSuffix = szValue;
1882  if (szValue[0] == '0' && (szValue[1] == 'x' || szValue[1] == 'X')) {
1883  if (!szValue[2]) return a_nDefault;
1884  nValue = strtol(&szValue[2], &pszSuffix, 16);
1885  } else {
1886  nValue = strtol(szValue, &pszSuffix, 10);
1887  }
1888 
1889  // any invalid strings will return the default value
1890  if (*pszSuffix) {
1891  return a_nDefault;
1892  }
1893 
1894  return nValue;
1895 }

◆ GetSection()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
const CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::TKeyVal * sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetSection ( const SI_CHAR *  a_pSection) const

Retrieve all key and value pairs for a section. The data is returned as a pointer to an STL map and can be iterated or searched as desired. Note that multiple entries for the same key may exist when multiple keys have been enabled.

NOTE! This structure contains only pointers to strings. The actual string data is stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset() while these strings are in use!

Parameters
a_pSectionName of the section to return
Returns
boolean Was a section matching the supplied name found.

Definition at line 2117 of file calibration.hpp.

2119  {
2120  if (a_pSection) {
2121  typename TSection::const_iterator i = m_data.find(a_pSection);
2122  if (i != m_data.end()) {
2123  return &(i->second);
2124  }
2125  }
2126  return 0;
2127 }

◆ GetSectionSize()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
int sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetSectionSize ( const SI_CHAR *  a_pSection) const

Query the number of keys in a specific section. Note that if multiple keys are enabled, then this value may be different to the number of keys returned by GetAllKeys.

Parameters
a_pSectionSection to request data for
Returns
-1 Section does not exist in the file
>=0 Number of keys in the section

Definition at line 2083 of file calibration.hpp.

2085  {
2086  if (!a_pSection) {
2087  return -1;
2088  }
2089 
2090  typename TSection::const_iterator iSection = m_data.find(a_pSection);
2091  if (iSection == m_data.end()) {
2092  return -1;
2093  }
2094  const TKeyVal & section = iSection->second;
2095 
2096  // if multi-key isn't permitted then the section size is
2097  // the number of keys that we have.
2098  if (!m_bAllowMultiKey || section.empty()) {
2099  return (int) section.size();
2100  }
2101 
2102  // otherwise we need to count them
2103  int nCount = 0;
2104  const SI_CHAR * pLastKey = NULL;
2105  typename TKeyVal::const_iterator iKeyVal = section.begin();
2106  for (int n = 0; iKeyVal != section.end(); ++iKeyVal, ++n) {
2107  if (!pLastKey || IsLess(pLastKey, iKeyVal->first.pItem)) {
2108  ++nCount;
2109  pLastKey = iKeyVal->first.pItem;
2110  }
2111  }
2112  return nCount;
2113 }

◆ GetValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
const SI_CHAR * sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::GetValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
const SI_CHAR *  a_pDefault = NULL,
bool *  a_pHasMultiple = NULL 
) const

Retrieve the value for a specific key. If multiple keys are enabled (see SetMultiKey) then only the first value associated with that key will be returned, see GetAllValues for getting all values with multikey.

NOTE! The returned value is a pointer to string data stored in memory owned by CSimpleIni. Ensure that the CSimpleIni object is not destroyed or Reset while you are using this pointer!

Parameters
a_pSectionSection to search
a_pKeyKey to search for
a_pDefaultValue to return if the key is not found
a_pHasMultipleOptionally receive notification of if there are multiple entries for this key.
Returns
a_pDefault Key was not found in the section
other Value of the key

Definition at line 1826 of file calibration.hpp.

1831  {
1832  if (a_pHasMultiple) {
1833  *a_pHasMultiple = false;
1834  }
1835  if (!a_pSection || !a_pKey) {
1836  return a_pDefault;
1837  }
1838  typename TSection::const_iterator iSection = m_data.find(a_pSection);
1839  if (iSection == m_data.end()) {
1840  return a_pDefault;
1841  }
1842  typename TKeyVal::const_iterator iKeyVal = iSection->second.find(a_pKey);
1843  if (iKeyVal == iSection->second.end()) {
1844  return a_pDefault;
1845  }
1846 
1847  // check for multiple entries with the same key
1848  if (m_bAllowMultiKey && a_pHasMultiple) {
1849  typename TKeyVal::const_iterator iTemp = iKeyVal;
1850  if (++iTemp != iSection->second.end()) {
1851  if (!IsLess(a_pKey, iTemp->first.pItem)) {
1852  *a_pHasMultiple = true;
1853  }
1854  }
1855  }
1856 
1857  return iKeyVal->second;
1858 }

Referenced by sl_oc::tools::ConfManager::getValue().

◆ IsEmpty()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::IsEmpty ( ) const
inline

Has any data been loaded

Definition at line 334 of file calibration.hpp.

334  {
335  return m_data.empty();
336  }

◆ IsMultiKey()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::IsMultiKey ( ) const
inline

Get the storage format of the INI data.

Definition at line 387 of file calibration.hpp.

387  {
388  return m_bAllowMultiKey;
389  }

◆ IsMultiLine()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::IsMultiLine ( ) const
inline

Query the status of multi-line data

Definition at line 403 of file calibration.hpp.

403  {
404  return m_bAllowMultiLine;
405  }

◆ IsUnicode()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::IsUnicode ( ) const
inline

Get the storage format of the INI data.

Definition at line 360 of file calibration.hpp.

360  {
361  return m_bStoreIsUtf8;
362  }

◆ LoadData() [1/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadData ( const char *  a_pData,
size_t  a_uDataLen 
)

Load INI file data direct from memory

Parameters
a_pDataData to be loaded
a_uDataLenLength of the data in bytes
Returns
SI_Error See error definitions

Definition at line 1272 of file calibration.hpp.

1275  {
1276  SI_CONVERTER converter(m_bStoreIsUtf8);
1277 
1278  if (a_uDataLen == 0) {
1279  return SI_OK;
1280  }
1281 
1282  // consume the UTF-8 BOM if it exists
1283  if (m_bStoreIsUtf8 && a_uDataLen >= 3) {
1284  if (memcmp(a_pData, SI_UTF8_SIGNATURE, 3) == 0) {
1285  a_pData += 3;
1286  a_uDataLen -= 3;
1287  }
1288  }
1289 
1290  // determine the length of the converted data
1291  size_t uLen = converter.SizeFromStore(a_pData, a_uDataLen);
1292  if (uLen == (size_t) (-1)) {
1293  return SI_FAIL;
1294  }
1295 
1296  // allocate memory for the data, ensure that there is a NULL
1297  // terminator wherever the converted data ends
1298  SI_CHAR * pData = new(std::nothrow) SI_CHAR[uLen + 1];
1299  if (!pData) {
1300  return SI_NOMEM;
1301  }
1302  memset(pData, 0, sizeof (SI_CHAR)*(uLen + 1));
1303 
1304  // convert the data
1305  if (!converter.ConvertFromStore(a_pData, a_uDataLen, pData, uLen)) {
1306  delete[] pData;
1307  return SI_FAIL;
1308  }
1309 
1310  // parse it
1311  const static SI_CHAR empty = 0;
1312  SI_CHAR * pWork = pData;
1313  const SI_CHAR * pSection = &empty;
1314  const SI_CHAR * pItem = NULL;
1315  const SI_CHAR * pVal = NULL;
1316  const SI_CHAR * pComment = NULL;
1317 
1318  // We copy the strings if we are loading data into this class when we
1319  // already have stored some.
1320  bool bCopyStrings = (m_pData != NULL);
1321 
1322  // find a file comment if it exists, this is a comment that starts at the
1323  // beginning of the file and continues until the first blank line.
1324  SI_Error rc = FindFileComment(pWork, bCopyStrings);
1325  if (rc < 0) return rc;
1326 
1327  // add every entry in the file to the data table
1328  while (FindEntry(pWork, pSection, pItem, pVal, pComment)) {
1329  rc = AddEntry(pSection, pItem, pVal, pComment, false, bCopyStrings);
1330  if (rc < 0) return rc;
1331  }
1332 
1333  // store these strings if we didn't copy them
1334  if (bCopyStrings) {
1335  delete[] pData;
1336  } else {
1337  m_pData = pData;
1338  m_uDataLen = uLen + 1;
1339  }
1340 
1341  return SI_OK;
1342 }
@ SI_NOMEM
Out of memory error.
@ SI_FAIL
Generic failure.
Definition: calibration.hpp:99
@ SI_OK
No error.
Definition: calibration.hpp:94

References sl_oc::tools::SI_FAIL, sl_oc::tools::SI_NOMEM, and sl_oc::tools::SI_OK.

◆ LoadData() [2/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadData ( const std::string &  a_strData)
inline

Load INI file data direct from a std::string

Parameters
a_strDataData to be loaded
Returns
SI_Error See error definitions

Definition at line 479 of file calibration.hpp.

479  {
480  return LoadData(a_strData.c_str(), a_strData.size());
481  }
SI_Error LoadData(std::istream &a_istream)

References sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadData().

◆ LoadData() [3/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadData ( std::istream &  a_istream)

Load INI file data from an istream.

Parameters
a_istreamStream to read from
Returns
SI_Error See error definitions

Definition at line 1348 of file calibration.hpp.

1350  {
1351  std::string strData;
1352  char szBuf[512];
1353  do {
1354  a_istream.get(szBuf, sizeof (szBuf), '\0');
1355  strData.append(szBuf);
1356  } while (a_istream.good());
1357  return LoadData(strData);
1358 }

Referenced by sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadData().

◆ LoadFile() [1/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadFile ( const char *  a_pszFile)

Load an INI file from disk into memory

Parameters
a_pszFilePath of the file to be loaded. This will be passed to fopen() and so must be a valid path for the current platform.
Returns
SI_Error See error definitions

Definition at line 1188 of file calibration.hpp.

1190  {
1191  FILE * fp = NULL;
1192 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
1193  fopen_s(&fp, a_pszFile, "rb");
1194 #else // !__STDC_WANT_SECURE_LIB__
1195  fp = fopen(a_pszFile, "rb");
1196 #endif // __STDC_WANT_SECURE_LIB__
1197  if (!fp) {
1198  return SI_FILE;
1199  }
1200  SI_Error rc = LoadFile(fp);
1201  fclose(fp);
1202  return rc;
1203 }
SI_Error LoadFile(const char *a_pszFile)
@ SI_FILE
File error (see errno for detail error)

References sl_oc::tools::SI_FILE.

Referenced by sl_oc::tools::ConfManager::ConfManager().

◆ LoadFile() [2/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadFile ( const SI_WCHAR_T *  a_pwszFile)

Load an INI file from disk into memory

Parameters
a_pwszFilePath of the file to be loaded in UTF-16.
Returns
SI_Error See error definitions

Definition at line 1209 of file calibration.hpp.

1211  {
1212 #ifdef _WIN32
1213  FILE * fp = NULL;
1214 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
1215  _wfopen_s(&fp, a_pwszFile, L"rb");
1216 #else // !__STDC_WANT_SECURE_LIB__
1217  fp = _wfopen(a_pwszFile, L"rb");
1218 #endif // __STDC_WANT_SECURE_LIB__
1219  if (!fp) return SI_FILE;
1220  SI_Error rc = LoadFile(fp);
1221  fclose(fp);
1222  return rc;
1223 #else // !_WIN32 (therefore SI_CONVERT_ICU)
1224  char szFile[256];
1225  u_austrncpy(szFile, a_pwszFile, sizeof (szFile));
1226  return LoadFile(szFile);
1227 #endif // _WIN32
1228 }

References sl_oc::tools::SI_FILE.

◆ LoadFile() [3/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::LoadFile ( FILE *  a_fpFile)

Load the file from a file pointer.

Parameters
a_fpFileValid file pointer to read the file data from. The file will be read until end of file.
Returns
SI_Error See error definitions

Definition at line 1233 of file calibration.hpp.

1235  {
1236  // load the raw file data
1237  int retval = fseek(a_fpFile, 0, SEEK_END);
1238  if (retval != 0) {
1239  return SI_FILE;
1240  }
1241  long lSize = ftell(a_fpFile);
1242  if (lSize < 0) {
1243  return SI_FILE;
1244  }
1245  if (lSize == 0) {
1246  return SI_OK;
1247  }
1248 
1249  // allocate and ensure NULL terminated
1250  char * pData = new(std::nothrow) char[lSize + 1];
1251  if (!pData) {
1252  return SI_NOMEM;
1253  }
1254  pData[lSize] = 0;
1255 
1256  // load data into buffer
1257  fseek(a_fpFile, 0, SEEK_SET);
1258  size_t uRead = fread(pData, sizeof (char), lSize, a_fpFile);
1259  if (uRead != (size_t) lSize) {
1260  delete[] pData;
1261  return SI_FILE;
1262  }
1263 
1264  // convert the raw data to unicode
1265  SI_Error rc = LoadData(pData, uRead);
1266  delete[] pData;
1267  return rc;
1268 }

References sl_oc::tools::SI_FILE, sl_oc::tools::SI_NOMEM, and sl_oc::tools::SI_OK.

◆ Reset()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Reset

Deallocate all memory stored by this object

Definition at line 1166 of file calibration.hpp.

1166  {
1167  // remove all data
1168  delete[] m_pData;
1169  m_pData = NULL;
1170  m_uDataLen = 0;
1171  m_pFileComment = NULL;
1172  if (!m_data.empty()) {
1173  m_data.erase(m_data.begin(), m_data.end());
1174  }
1175 
1176  // remove all strings
1177  if (!m_strings.empty()) {
1178  typename TNamesDepend::iterator i = m_strings.begin();
1179  for (; i != m_strings.end(); ++i) {
1180  delete[] const_cast<SI_CHAR*> (i->pItem);
1181  }
1182  m_strings.erase(m_strings.begin(), m_strings.end());
1183  }
1184 }

◆ Save() [1/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save ( OutputWriter a_oOutput,
bool  a_bAddSignature = false 
) const

Save the INI data. The data will be written to the output device in a format appropriate to the current data, selected by:

SI_CHAR FORMAT
char same format as when loaded (MBCS or UTF-8)
wchar_t UTF-8
other UTF-8

Note that comments from the original data is preserved as per the documentation on comments. The order of the sections and values from the original file will be preserved.

Any data prepended or appended to the output device must use the the same format (MBCS or UTF-8). You may use the GetConverter() method to convert text to the correct format regardless of the output format being used by SimpleIni.

To add a BOM to UTF-8 data, write it out manually at the very beginning like is done in SaveFile when a_bUseBOM is true.

Parameters
a_oOutputOutput writer to write the data to.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this value is ignored. Do not set this to true if anything has already been written to the OutputWriter.
Returns
SI_Error See error definitions

Definition at line 2229 of file calibration.hpp.

2232  {
2233  Converter convert(m_bStoreIsUtf8);
2234 
2235  // add the UTF-8 signature if it is desired
2236  if (m_bStoreIsUtf8 && a_bAddSignature) {
2237  a_oOutput.Write(SI_UTF8_SIGNATURE);
2238  }
2239 
2240  // get all of the sections sorted in load order
2241  TNamesDepend oSections;
2242  GetAllSections(oSections);
2243 #if defined(_MSC_VER) && _MSC_VER <= 1200
2244  oSections.sort();
2245 #elif defined(__BORLANDC__)
2246  oSections.sort(Entry::LoadOrder());
2247 #else
2248  oSections.sort(typename Entry::LoadOrder());
2249 #endif
2250 
2251  // write the file comment if we have one
2252  bool bNeedNewLine = false;
2253  if (m_pFileComment) {
2254  if (!OutputMultiLineText(a_oOutput, convert, m_pFileComment)) {
2255  return SI_FAIL;
2256  }
2257  bNeedNewLine = true;
2258  }
2259 
2260  // iterate through our sections and output the data
2261  typename TNamesDepend::const_iterator iSection = oSections.begin();
2262  for (; iSection != oSections.end(); ++iSection) {
2263  // write out the comment if there is one
2264  if (iSection->pComment) {
2265  if (bNeedNewLine) {
2266  a_oOutput.Write(SI_NEWLINE_A);
2267  a_oOutput.Write(SI_NEWLINE_A);
2268  }
2269  if (!OutputMultiLineText(a_oOutput, convert, iSection->pComment)) {
2270  return SI_FAIL;
2271  }
2272  bNeedNewLine = false;
2273  }
2274 
2275  if (bNeedNewLine) {
2276  a_oOutput.Write(SI_NEWLINE_A);
2277  a_oOutput.Write(SI_NEWLINE_A);
2278  bNeedNewLine = false;
2279  }
2280 
2281  // write the section (unless there is no section name)
2282  if (*iSection->pItem) {
2283  if (!convert.ConvertToStore(iSection->pItem)) {
2284  return SI_FAIL;
2285  }
2286  a_oOutput.Write("[");
2287  a_oOutput.Write(convert.Data());
2288  a_oOutput.Write("]");
2289  a_oOutput.Write(SI_NEWLINE_A);
2290  }
2291 
2292  // get all of the keys sorted in load order
2293  TNamesDepend oKeys;
2294  GetAllKeys(iSection->pItem, oKeys);
2295 #if defined(_MSC_VER) && _MSC_VER <= 1200
2296  oKeys.sort();
2297 #elif defined(__BORLANDC__)
2298  oKeys.sort(Entry::LoadOrder());
2299 #else
2300  oKeys.sort(typename Entry::LoadOrder());
2301 #endif
2302 
2303  // write all keys and values
2304  typename TNamesDepend::const_iterator iKey = oKeys.begin();
2305  for (; iKey != oKeys.end(); ++iKey) {
2306  // get all values for this key
2307  TNamesDepend oValues;
2308  GetAllValues(iSection->pItem, iKey->pItem, oValues);
2309 
2310  typename TNamesDepend::const_iterator iValue = oValues.begin();
2311  for (; iValue != oValues.end(); ++iValue) {
2312  // write out the comment if there is one
2313  if (iValue->pComment) {
2314  a_oOutput.Write(SI_NEWLINE_A);
2315  if (!OutputMultiLineText(a_oOutput, convert, iValue->pComment)) {
2316  return SI_FAIL;
2317  }
2318  }
2319 
2320  // write the key
2321  if (!convert.ConvertToStore(iKey->pItem)) {
2322  return SI_FAIL;
2323  }
2324  a_oOutput.Write(convert.Data());
2325 
2326  // write the value
2327  if (!convert.ConvertToStore(iValue->pItem)) {
2328  return SI_FAIL;
2329  }
2330  a_oOutput.Write(m_bSpaces ? " = " : "=");
2331  if (m_bAllowMultiLine && IsMultiLineData(iValue->pItem)) {
2332  // multi-line data needs to be processed specially to ensure
2333  // that we use the correct newline format for the current system
2334  a_oOutput.Write("<<<END_OF_TEXT" SI_NEWLINE_A);
2335  if (!OutputMultiLineText(a_oOutput, convert, iValue->pItem)) {
2336  return SI_FAIL;
2337  }
2338  a_oOutput.Write("END_OF_TEXT");
2339  } else {
2340  a_oOutput.Write(convert.Data());
2341  }
2342  a_oOutput.Write(SI_NEWLINE_A);
2343  }
2344  }
2345 
2346  bNeedNewLine = true;
2347  }
2348 
2349  return SI_OK;
2350 }
bool GetAllValues(const SI_CHAR *a_pSection, const SI_CHAR *a_pKey, TNamesDepend &a_values) const
void GetAllSections(TNamesDepend &a_names) const
std::list< Entry > TNamesDepend
bool GetAllKeys(const SI_CHAR *a_pSection, TNamesDepend &a_names) const

References sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Converter::ConvertToStore(), sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Converter::Data(), sl_oc::tools::SI_FAIL, sl_oc::tools::SI_OK, and sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::OutputWriter::Write().

Referenced by sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save().

◆ Save() [2/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save ( std::ostream &  a_ostream,
bool  a_bAddSignature = false 
) const
inline

Save the INI data to an ostream. See Save() for details.

Parameters
a_ostreamString to have the INI data appended to.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this value is ignored. Do not set this to true if anything has already been written to the stream.
Returns
SI_Error See error definitions

Definition at line 596 of file calibration.hpp.

599  {
600  StreamWriter writer(a_ostream);
601  return Save(writer, a_bAddSignature);
602  }
SI_Error Save(OutputWriter &a_oOutput, bool a_bAddSignature=false) const

References sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save().

◆ Save() [3/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save ( std::string &  a_sBuffer,
bool  a_bAddSignature = false 
) const
inline

Append the INI data to a string. See Save() for details.

Parameters
a_sBufferString to have the INI data appended to.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this value is ignored. Do not set this to true if anything has already been written to the string.
Returns
SI_Error See error definitions

Definition at line 616 of file calibration.hpp.

619  {
620  StringWriter writer(a_sBuffer);
621  return Save(writer, a_bAddSignature);
622  }

References sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::Save().

◆ SaveFile() [1/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SaveFile ( const char *  a_pszFile,
bool  a_bAddSignature = true 
) const

Save an INI file from memory to disk

Parameters
a_pszFilePath of the file to be saved. This will be passed to fopen() and so must be a valid path for the current platform.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this parameter is ignored.
Returns
SI_Error See error definitions

Definition at line 2174 of file calibration.hpp.

2177  {
2178  FILE * fp = NULL;
2179 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
2180  fopen_s(&fp, a_pszFile, "wb");
2181 #else // !__STDC_WANT_SECURE_LIB__
2182  fp = fopen(a_pszFile, "wb");
2183 #endif // __STDC_WANT_SECURE_LIB__
2184  if (!fp) return SI_FILE;
2185  SI_Error rc = SaveFile(fp, a_bAddSignature);
2186  fclose(fp);
2187  return rc;
2188 }
SI_Error SaveFile(const char *a_pszFile, bool a_bAddSignature=true) const

References sl_oc::tools::SI_FILE.

◆ SaveFile() [2/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SaveFile ( const SI_WCHAR_T *  a_pwszFile,
bool  a_bAddSignature = true 
) const

Save an INI file from memory to disk

Parameters
a_pwszFilePath of the file to be saved in UTF-16.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this parameter is ignored.
Returns
SI_Error See error definitions

Definition at line 2194 of file calibration.hpp.

2197  {
2198 #ifdef _WIN32
2199  FILE * fp = NULL;
2200 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
2201  _wfopen_s(&fp, a_pwszFile, L"wb");
2202 #else // !__STDC_WANT_SECURE_LIB__
2203  fp = _wfopen(a_pwszFile, L"wb");
2204 #endif // __STDC_WANT_SECURE_LIB__
2205  if (!fp) return SI_FILE;
2206  SI_Error rc = SaveFile(fp, a_bAddSignature);
2207  fclose(fp);
2208  return rc;
2209 #else // !_WIN32 (therefore SI_CONVERT_ICU)
2210  char szFile[256];
2211  u_austrncpy(szFile, a_pwszFile, sizeof (szFile));
2212  return SaveFile(szFile, a_bAddSignature);
2213 #endif // _WIN32
2214 }

References sl_oc::tools::SI_FILE.

◆ SaveFile() [3/3]

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SaveFile ( FILE *  a_pFile,
bool  a_bAddSignature = false 
) const

Save the INI data to a file. See Save() for details.

Parameters
a_pFileHandle to a file. File should be opened for binary output.
a_bAddSignaturePrepend the UTF-8 BOM if the output data is in UTF-8 format. If it is not UTF-8 then this value is ignored. Do not set this to true if anything has already been written to the file.
Returns
SI_Error See error definitions

Definition at line 2219 of file calibration.hpp.

2222  {
2223  FileWriter writer(a_pFile);
2224  return Save(writer, a_bAddSignature);
2225 }

◆ SetBoolValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetBoolValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
bool  a_bValue,
const SI_CHAR *  a_pComment = NULL,
bool  a_bForceReplace = false 
)

Add or update a boolean value. This will always insert when multiple keys are enabled.

Parameters
a_pSectionSection to add or update
a_pKeyKey to add or update.
a_bValueValue to set.
a_pCommentComment to be associated with the key. See the notes on SetValue() for comments.
a_bForceReplaceShould all existing values in a multi-key INI file be replaced with this entry. This option has no effect if not using multi-key files. The difference between Delete/SetBoolValue and SetBoolValue with a_bForceReplace = true, is that the load order and comment will be preserved this way.
Returns
SI_Error See error definitions
SI_UPDATED Value was updated
SI_INSERTED Value was inserted

Definition at line 2024 of file calibration.hpp.

2030  {
2031  // use SetValue to create sections
2032  if (!a_pSection || !a_pKey) return SI_FAIL;
2033 
2034  // convert to an ASCII string
2035  const char * pszInput = a_bValue ? "true" : "false";
2036 
2037  // convert to output text
2038  SI_CHAR szOutput[64];
2039  SI_CONVERTER c(m_bStoreIsUtf8);
2040  c.ConvertFromStore(pszInput, strlen(pszInput) + 1,
2041  szOutput, sizeof (szOutput) / sizeof (SI_CHAR));
2042 
2043  // actually add it
2044  return AddEntry(a_pSection, a_pKey, szOutput, a_pComment, a_bForceReplace, true);
2045 }

References sl_oc::tools::SI_FAIL.

◆ SetDoubleValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetDoubleValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
double  a_nValue,
const SI_CHAR *  a_pComment = NULL,
bool  a_bForceReplace = false 
)

Add or update a double value. This will always insert when multiple keys are enabled.

Parameters
a_pSectionSection to add or update
a_pKeyKey to add or update.
a_nValueValue to set.
a_pCommentComment to be associated with the key. See the notes on SetValue() for comments.
a_bForceReplaceShould all existing values in a multi-key INI file be replaced with this entry. This option has no effect if not using multi-key files. The difference between Delete/SetDoubleValue and SetDoubleValue with a_bForceReplace = true, is that the load order and comment will be preserved this way.
Returns
SI_Error See error definitions
SI_UPDATED Value was updated
SI_INSERTED Value was inserted

Definition at line 1960 of file calibration.hpp.

1966  {
1967  // use SetValue to create sections
1968  if (!a_pSection || !a_pKey) return SI_FAIL;
1969 
1970  // convert to an ASCII string
1971  char szInput[64];
1972 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
1973  sprintf_s(szInput, "%f", a_nValue);
1974 #else // !__STDC_WANT_SECURE_LIB__
1975  sprintf(szInput, "%f", a_nValue);
1976 #endif // __STDC_WANT_SECURE_LIB__
1977 
1978  // convert to output text
1979  SI_CHAR szOutput[64];
1980  SI_CONVERTER c(m_bStoreIsUtf8);
1981  c.ConvertFromStore(szInput, strlen(szInput) + 1,
1982  szOutput, sizeof (szOutput) / sizeof (SI_CHAR));
1983 
1984  // actually add it
1985  return AddEntry(a_pSection, a_pKey, szOutput, a_pComment, a_bForceReplace, true);
1986 }

References sl_oc::tools::SI_FAIL.

◆ SetLongValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetLongValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
long  a_nValue,
const SI_CHAR *  a_pComment = NULL,
bool  a_bUseHex = false,
bool  a_bForceReplace = false 
)

Add or update a numeric value. This will always insert when multiple keys are enabled.

Parameters
a_pSectionSection to add or update
a_pKeyKey to add or update.
a_nValueValue to set.
a_pCommentComment to be associated with the key. See the notes on SetValue() for comments.
a_bUseHexBy default the value will be written to the file in decimal format. Set this to true to write it as hexadecimal.
a_bForceReplaceShould all existing values in a multi-key INI file be replaced with this entry. This option has no effect if not using multi-key files. The difference between Delete/SetLongValue and SetLongValue with a_bForceReplace = true, is that the load order and comment will be preserved this way.
Returns
SI_Error See error definitions
SI_UPDATED Value was updated
SI_INSERTED Value was inserted

Definition at line 1899 of file calibration.hpp.

1906  {
1907  // use SetValue to create sections
1908  if (!a_pSection || !a_pKey) return SI_FAIL;
1909 
1910  // convert to an ASCII string
1911  char szInput[64];
1912 #if __STDC_WANT_SECURE_LIB__ && !_WIN32_WCE
1913  sprintf_s(szInput, a_bUseHex ? "0x%lx" : "%ld", a_nValue);
1914 #else // !__STDC_WANT_SECURE_LIB__
1915  sprintf(szInput, a_bUseHex ? "0x%lx" : "%ld", a_nValue);
1916 #endif // __STDC_WANT_SECURE_LIB__
1917 
1918  // convert to output text
1919  SI_CHAR szOutput[64];
1920  SI_CONVERTER c(m_bStoreIsUtf8);
1921  c.ConvertFromStore(szInput, strlen(szInput) + 1,
1922  szOutput, sizeof (szOutput) / sizeof (SI_CHAR));
1923 
1924  // actually add it
1925  return AddEntry(a_pSection, a_pKey, szOutput, a_pComment, a_bForceReplace, true);
1926 }

References sl_oc::tools::SI_FAIL.

◆ SetMultiKey()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetMultiKey ( bool  a_bAllowMultiKey = true)
inline

Should multiple identical keys be permitted in the file. If set to false then the last value encountered will be used as the value of the key. If set to true, then all values will be available to be queried. For example, with the following input:

[section]
test=value1
test=value2

Then with SetMultiKey(true), both of the values "value1" and "value2" will be returned for the key test. If SetMultiKey(false) is used, then the value for "test" will only be "value2". This value may be changed at any time.

Parameters
a_bAllowMultiKeyAllow multi-keys in the source?

Definition at line 382 of file calibration.hpp.

382  {
383  m_bAllowMultiKey = a_bAllowMultiKey;
384  }

◆ SetMultiLine()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetMultiLine ( bool  a_bAllowMultiLine = true)
inline

Should data values be permitted to span multiple lines in the file. If set to false then the multi-line construct <<<TAG as a value will be returned as is instead of loading the data. This value may be changed at any time.

Parameters
a_bAllowMultiLineAllow multi-line values in the source?

Definition at line 398 of file calibration.hpp.

398  {
399  m_bAllowMultiLine = a_bAllowMultiLine;
400  }

◆ SetSpaces()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetSpaces ( bool  a_bSpaces = true)
inline

Should spaces be added around the equals sign when writing key/value pairs out. When true, the result will be "key = value". When false, the result will be "key=value". This value may be changed at any time.

Parameters
a_bSpacesAdd spaces around the equals sign?

Definition at line 413 of file calibration.hpp.

413  {
414  m_bSpaces = a_bSpaces;
415  }

◆ SetUnicode()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
void sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetUnicode ( bool  a_bIsUtf8 = true)
inline

Set the storage format of the INI data. This affects both the loading and saving of the INI data using all of the Load/Save API functions. This value cannot be changed after any INI data has been loaded.

If the file is not set to Unicode (UTF-8), then the data encoding is assumed to be the OS native encoding. This encoding is the system locale on Linux/Unix and the legacy MBCS encoding on Windows NT/2K/XP. If the storage format is set to Unicode then the file will be loaded as UTF-8 encoded data regardless of the native file encoding. If SI_CHAR == char then all of the char* parameters take and return UTF-8 encoded data regardless of the system locale.

Parameters
a_bIsUtf8Assume UTF-8 encoding for the source?

Definition at line 355 of file calibration.hpp.

355  {
356  if (!m_pData) m_bStoreIsUtf8 = a_bIsUtf8;
357  }

Referenced by sl_oc::tools::ConfManager::ConfManager().

◆ SetValue()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
SI_Error sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::SetValue ( const SI_CHAR *  a_pSection,
const SI_CHAR *  a_pKey,
const SI_CHAR *  a_pValue,
const SI_CHAR *  a_pComment = NULL,
bool  a_bForceReplace = false 
)
inline

Add or update a section or value. This will always insert when multiple keys are enabled.

Parameters
a_pSectionSection to add or update
a_pKeyKey to add or update. Set to NULL to create an empty section.
a_pValueValue to set. Set to NULL to create an empty section.
a_pCommentComment to be associated with the section or the key. If a_pKey is NULL then it will be associated with the section, otherwise the key. Note that a comment may be set ONLY when the section or key is first created (i.e. when this function returns the value SI_INSERTED). If you wish to create a section with a comment then you need to create the section separately to the key. The comment string must be in full comment form already (have a comment character starting every line).
a_bForceReplaceShould all existing values in a multi-key INI file be replaced with this entry. This option has no effect if not using multi-key files. The difference between Delete/SetValue and SetValue with a_bForceReplace = true, is that the load order and comment will be preserved this way.
Returns
SI_Error See error definitions
SI_UPDATED Value was updated
SI_INSERTED Value was inserted

Definition at line 836 of file calibration.hpp.

842  {
843  return AddEntry(a_pSection, a_pKey, a_pValue, a_pComment, a_bForceReplace, true);
844  }

Referenced by sl_oc::tools::ConfManager::setValue().

◆ UsingSpaces()

template<class SI_CHAR , class SI_STRLESS , class SI_CONVERTER >
bool sl_oc::tools::CSimpleIniTempl< SI_CHAR, SI_STRLESS, SI_CONVERTER >::UsingSpaces ( ) const
inline

Query the status of spaces output

Definition at line 418 of file calibration.hpp.

418  {
419  return m_bSpaces;
420  }

The documentation for this class was generated from the following file: