From 6349bd3df12fea7417356f414e5c14b7c1b80808 Mon Sep 17 00:00:00 2001
From: yangfl <yangfl@users.noreply.github.com>
Date: Wed, 31 Jul 2019 09:48:30 +0800
Subject: [PATCH 3/4] Add C++ class to library

---
 minIni-cxx.cc | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++
 minIni.h      |  84 +++++++++++++++++++++++++++++++++++-
 2 files changed, 198 insertions(+), 2 deletions(-)
 create mode 100644 minIni-cxx.cc

diff --git a/minIni-cxx.cc b/minIni-cxx.cc
new file mode 100644
index 0000000..bed624f
--- /dev/null
+++ b/minIni-cxx.cc
@@ -0,0 +1,116 @@
+/*  minIni - Multi-Platform INI file parser, suitable for embedded systems
+ *
+ *  These routines are in part based on the article "Multiplatform .INI Files"
+ *  by Joseph J. Graf in the March 1994 issue of Dr. Dobb's Journal.
+ *
+ *  Copyright (c) CompuPhase, 2008-2020
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ *  use this file except in compliance with the License. You may obtain a copy
+ *  of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ *  License for the specific language governing permissions and limitations
+ *  under the License.
+ *
+ *  Version: $Id: minIni.c 53 2015-01-18 13:35:11Z thiadmer.riemersma@gmail.com $
+ */
+
+#if (defined _UNICODE || defined __UNICODE__ || defined UNICODE) && !defined INI_ANSIONLY
+# if !defined UNICODE   /* for Windows */
+#   define UNICODE
+# endif
+# if !defined _UNICODE  /* for C library */
+#   define _UNICODE
+# endif
+#endif
+
+#define MININI_IMPLEMENTATION 0
+#include "minIni.h"
+#if defined NDEBUG
+  #define assert(e)
+#else
+  #include <assert.h>
+#endif
+
+
+minIni::minIni(const std::string& filename) : iniFilename(filename)
+  { }
+
+bool minIni::getbool(const std::string& Section, const std::string& Key, bool DefValue) const
+  { return ini_getbool(Section.c_str(), Key.c_str(), int(DefValue), iniFilename.c_str()) != 0; }
+
+long minIni::getl(const std::string& Section, const std::string& Key, long DefValue) const
+  { return ini_getl(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
+
+int minIni::geti(const std::string& Section, const std::string& Key, int DefValue) const
+  { return static_cast<int>(this->getl(Section, Key, long(DefValue))); }
+
+std::string minIni::gets(const std::string& Section, const std::string& Key, const std::string& DefValue) const
+  {
+    char buffer[INI_BUFFERSIZE];
+    ini_gets(Section.c_str(), Key.c_str(), DefValue.c_str(), buffer, INI_BUFFERSIZE, iniFilename.c_str());
+    return buffer;
+  }
+
+std::string minIni::getsection(int idx) const
+  {
+    char buffer[INI_BUFFERSIZE];
+    ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
+    return buffer;
+  }
+
+std::string minIni::getkey(const std::string& Section, int idx) const
+  {
+    char buffer[INI_BUFFERSIZE];
+    ini_getkey(Section.c_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
+    return buffer;
+  }
+
+bool minIni::hassection(const std::string& Section) const
+  { return ini_hassection(Section.c_str(), iniFilename.c_str()) != 0; }
+
+bool minIni::haskey(const std::string& Section, const std::string& Key) const
+  { return ini_haskey(Section.c_str(), Key.c_str(), iniFilename.c_str()) != 0; }
+
+#if defined INI_REAL
+INI_REAL minIni::getf(const std::string& Section, const std::string& Key, INI_REAL DefValue) const
+  { return ini_getf(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
+#endif
+
+#if ! defined INI_READONLY
+bool minIni::put(const std::string& Section, const std::string& Key, bool Value)
+  { return ini_putbool(Section.c_str(), Key.c_str(), (int)Value, iniFilename.c_str()) != 0; }
+
+bool minIni::put(const std::string& Section, const std::string& Key, long Value)
+  { return ini_putl(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+
+bool minIni::put(const std::string& Section, const std::string& Key, int Value)
+  { return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
+
+bool minIni::put(const std::string& Section, const std::string& Key, const std::string& Value)
+  { return ini_puts(Section.c_str(), Key.c_str(), Value.c_str(), iniFilename.c_str()) != 0; }
+
+bool minIni::put(const std::string& Section, const std::string& Key, const char* Value)
+  { return ini_puts(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+
+#if defined INI_REAL
+bool minIni::put(const std::string& Section, const std::string& Key, INI_REAL Value)
+  { return ini_putf(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+#endif
+
+bool minIni::del(const std::string& Section, const std::string& Key)
+  { return ini_puts(Section.c_str(), Key.c_str(), 0, iniFilename.c_str()) != 0; }
+
+bool minIni::del(const std::string& Section)
+  { return ini_puts(Section.c_str(), 0, 0, iniFilename.c_str()) != 0; }
+#endif
+
+#if !defined INI_NOBROWSE
+bool minIni::browse(INI_CALLBACK Callback, void *UserData) const
+  { return ini_browse(Callback, UserData, iniFilename.c_str()) != 0; }
+#endif
diff --git a/minIni.h b/minIni.h
index 9a68c87..8fd728f 100644
--- a/minIni.h
+++ b/minIni.h
@@ -77,84 +77,164 @@ int  ini_browse(INI_CALLBACK Callback, void *UserData, const mTCHAR *Filename);
   #include <string>
 
   /* The C++ class in minIni.h was contributed by Steven Van Ingelgem. */
+#ifndef MININI_IMPLEMENTATION
+  #define MININI_IMPLEMENTATION 1
+#endif
   class minIni
   {
   public:
-    minIni(const std::string& filename) : iniFilename(filename)
-      { }
+    minIni(const std::string& filename)
+#if MININI_IMPLEMENTATION
+      : iniFilename(filename)
+       { }
+#else
+      ;
+#endif
 
     bool getbool(const std::string& Section, const std::string& Key, bool DefValue=false) const
+#if MININI_IMPLEMENTATION
       { return ini_getbool(Section.c_str(), Key.c_str(), int(DefValue), iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     long getl(const std::string& Section, const std::string& Key, long DefValue=0) const
+#if MININI_IMPLEMENTATION
       { return ini_getl(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
+#else
+      ;
+#endif
 
     int geti(const std::string& Section, const std::string& Key, int DefValue=0) const
+#if MININI_IMPLEMENTATION
       { return static_cast<int>(this->getl(Section, Key, long(DefValue))); }
+#else
+      ;
+#endif
 
     std::string gets(const std::string& Section, const std::string& Key, const std::string& DefValue="") const
+#if MININI_IMPLEMENTATION
       {
         char buffer[INI_BUFFERSIZE];
         ini_gets(Section.c_str(), Key.c_str(), DefValue.c_str(), buffer, INI_BUFFERSIZE, iniFilename.c_str());
         return buffer;
       }
+#else
+      ;
+#endif
 
     std::string getsection(int idx) const
+#if MININI_IMPLEMENTATION
       {
         char buffer[INI_BUFFERSIZE];
         ini_getsection(idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
         return buffer;
       }
+#else
+      ;
+#endif
 
     std::string getkey(const std::string& Section, int idx) const
+#if MININI_IMPLEMENTATION
       {
         char buffer[INI_BUFFERSIZE];
         ini_getkey(Section.c_str(), idx, buffer, INI_BUFFERSIZE, iniFilename.c_str());
         return buffer;
       }
+#else
+      ;
+#endif
 
     bool hassection(const std::string& Section) const
+#if MININI_IMPLEMENTATION
       { return ini_hassection(Section.c_str(), iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool haskey(const std::string& Section, const std::string& Key) const
+#if MININI_IMPLEMENTATION
       { return ini_haskey(Section.c_str(), Key.c_str(), iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
 #if defined INI_REAL
     INI_REAL getf(const std::string& Section, const std::string& Key, INI_REAL DefValue=0) const
+#if MININI_IMPLEMENTATION
       { return ini_getf(Section.c_str(), Key.c_str(), DefValue, iniFilename.c_str()); }
+#else
+      ;
+#endif
 #endif
 
 #if ! defined INI_READONLY
     bool put(const std::string& Section, const std::string& Key, bool Value)
+#if MININI_IMPLEMENTATION
       { return ini_putbool(Section.c_str(), Key.c_str(), (int)Value, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool put(const std::string& Section, const std::string& Key, long Value)
+#if MININI_IMPLEMENTATION
       { return ini_putl(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool put(const std::string& Section, const std::string& Key, int Value)
+#if MININI_IMPLEMENTATION
       { return ini_putl(Section.c_str(), Key.c_str(), (long)Value, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool put(const std::string& Section, const std::string& Key, const std::string& Value)
+#if MININI_IMPLEMENTATION
       { return ini_puts(Section.c_str(), Key.c_str(), Value.c_str(), iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool put(const std::string& Section, const std::string& Key, const char* Value)
+#if MININI_IMPLEMENTATION
       { return ini_puts(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
 #if defined INI_REAL
     bool put(const std::string& Section, const std::string& Key, INI_REAL Value)
+#if MININI_IMPLEMENTATION
       { return ini_putf(Section.c_str(), Key.c_str(), Value, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 #endif
 
     bool del(const std::string& Section, const std::string& Key)
+#if MININI_IMPLEMENTATION
       { return ini_puts(Section.c_str(), Key.c_str(), 0, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 
     bool del(const std::string& Section)
+#if MININI_IMPLEMENTATION
       { return ini_puts(Section.c_str(), 0, 0, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 #endif
 
 #if !defined INI_NOBROWSE
     bool browse(INI_CALLBACK Callback, void *UserData) const
+#if MININI_IMPLEMENTATION
       { return ini_browse(Callback, UserData, iniFilename.c_str()) != 0; }
+#else
+      ;
+#endif
 #endif
 
   private:
-- 
2.47.2

