Commits

dirtycold  committed abf20a0

added: readonly mode

  • Participants
  • Parent commits 494c93a

Comments (0)

Files changed (2)

File IniConfig/iniconfig.cpp

 
 using namespace RP;
 
-IniConfig::IniConfig(const std::string &filepath)
-    :m_filepath(filepath)
+IniConfig::IniConfig(const std::string &filepath, bool readonly)
+    :m_filepath(filepath),m_readonly(readonly)
 {
     read();
 }
 
 IniConfig::~IniConfig()
 {
-    write();
+    if(!m_readonly)
+        write();
 }
 
 void IniConfig::map(std::stringstream &stream)

File IniConfig/iniconfig.h

     /**
      * @brief 构造函数
      * @param filepath 指定配置文件的路径和文件名
+     * @param readonly 指定是否为只读模式,避免文件写入操作
      */
-    INI IniConfig (const std::string &filepath);
+    INI IniConfig (const std::string &filepath, bool readonly = false);
 
     INI ~IniConfig ();
     /**
     void write();
 
 protected:
+    bool m_readonly;
     std::string m_filepath;
     RP::StringMap m_map;
 };