55
66#include < filesystem>
77
8- SimpleIni* SimpleIni::create (const std::string& path, const std::string& defContent) {
8+ std::unique_ptr< SimpleIni> SimpleIni::create (const std::string& path, const std::string& defContent) {
99 if (!std::filesystem::exists (ll::string_utils::str2wstr (path))) {
1010 // 创建新的
1111 std::filesystem::create_directories (
@@ -18,59 +18,58 @@ SimpleIni* SimpleIni::create(const std::string& path, const std::string& defCont
1818 }
1919
2020 // 已存在
21- auto root = new SimpleIni;
21+ auto root = std::make_unique< SimpleIni>() ;
2222 root->SetUnicode (true );
2323 auto res = root->LoadFile (path.c_str ());
2424 if (res < 0 ) {
2525 lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().error (" Failed in loading ini file" );
2626 lse::LegacyScriptEngine::getInstance ().getSelf ().getLogger ().error (
27- string (" Error Code:" ) + std::to_string ((int )res)
27+ std:: string (" Error Code:" ) + std::to_string ((int )res)
2828 );
29- delete root;
3029 return nullptr ;
3130 } else {
3231 root->filePath = path;
3332 return root;
3433 }
3534}
3635
37- bool SimpleIni::setInt (const string& sec, const string& key, int value) {
36+ bool SimpleIni::setInt (const std:: string& sec, const std:: string& key, int value) {
3837 bool isOk = SetLongValue (sec.c_str (), key.c_str (), value) >= 0 ;
3938 SaveFile (filePath.c_str ());
4039 return isOk;
4140}
4241
43- bool SimpleIni::setFloat (const string& sec, const string& key, float value) {
42+ bool SimpleIni::setFloat (const std:: string& sec, const std:: string& key, float value) {
4443 bool isOk = SetDoubleValue (sec.c_str (), key.c_str (), value) >= 0 ;
4544 SaveFile (filePath.c_str ());
4645 return isOk;
4746}
4847
49- bool SimpleIni::setString (const string& sec, const string& key, const string& value) {
48+ bool SimpleIni::setString (const std:: string& sec, const std:: string& key, const std:: string& value) {
5049 bool isOk = SetValue (sec.c_str (), key.c_str (), value.c_str ()) >= 0 ;
5150 SaveFile (filePath.c_str ());
5251 return isOk;
5352}
5453
55- bool SimpleIni::setBool (const string& sec, const string& key, bool value) {
54+ bool SimpleIni::setBool (const std:: string& sec, const std:: string& key, bool value) {
5655 bool isOk = SetBoolValue (sec.c_str (), key.c_str (), value) >= 0 ;
5756 SaveFile (filePath.c_str ());
5857 return isOk;
5958}
6059
61- int SimpleIni::getInt (const string& sec, const string& key, int def) {
60+ int SimpleIni::getInt (const std:: string& sec, const std:: string& key, int def) {
6261 return GetLongValue (sec.c_str (), key.c_str (), def);
6362}
6463
65- float SimpleIni::getFloat (const string& sec, const string& key, float def) {
64+ float SimpleIni::getFloat (const std:: string& sec, const std:: string& key, float def) {
6665 return (float )GetDoubleValue (sec.c_str (), key.c_str (), def);
6766}
6867
69- string SimpleIni::getString (const string& sec, const string& key, const string& def) {
68+ std:: string SimpleIni::getString (const std:: string& sec, const std:: string& key, const std:: string& def) {
7069 return GetValue (sec.c_str (), key.c_str (), def.c_str ());
7170}
7271
73- bool SimpleIni::getBool (const string& sec, const string& key, bool def) {
72+ bool SimpleIni::getBool (const std:: string& sec, const std:: string& key, bool def) {
7473 return GetBoolValue (sec.c_str (), key.c_str (), def);
7574}
7675
0 commit comments