diff --git a/space/space.cpp b/space/space.cpp index 7669505..c4cb6d9 100644 --- a/space/space.cpp +++ b/space/space.cpp @@ -102,6 +102,54 @@ void Space::Clear() + +Space::Value * Space::GetValue(const wchar_t * name) +{ + tmp_name = name; + return GetValue(tmp_name); +} + + +Space::Value * Space::GetValue(const std::wstring & name) +{ + Table::iterator t = table.find(name); + + if( t == table.end() ) + { + return 0; + } + else + { + return &t->second; + } +} + + +const Space::Value * Space::GetValue(const wchar_t * name) const +{ + tmp_name = name; + return GetValue(tmp_name); +} + + +const Space::Value * Space::GetValue(const std::wstring & name) const +{ + Table::const_iterator t = table.find(name); + + if( t == table.cend() ) + { + return 0; + } + else + { + return &t->second; + } +} + + + + + std::wstring * Space::GetFirstValue(const wchar_t * name) { tmp_name = name; @@ -192,7 +240,7 @@ return false; -std::wstring Space::Text(const wchar_t * name) +std::wstring Space::Text(const wchar_t * name) const { tmp_name = name; return Text(tmp_name, L""); @@ -200,16 +248,16 @@ std::wstring Space::Text(const wchar_t * name) -std::wstring Space::Text(const wchar_t * name, const wchar_t * def) +std::wstring Space::Text(const wchar_t * name, const wchar_t * def) const { tmp_name = name; return Text(tmp_name, def); } -std::wstring Space::Text(const std::wstring & name, const wchar_t * def) +std::wstring Space::Text(const std::wstring & name, const wchar_t * def) const { - std::wstring * value = GetFirstValue(name); + const std::wstring * value = GetFirstValue(name); if( value ) { @@ -218,15 +266,13 @@ std::wstring Space::Text(const std::wstring & name, const wchar_t * def) else { return std::wstring(def); -// tmp_value_text = def; -// return tmp_value_text; } } -std::wstring Space::Text(const std::wstring & name, const std::wstring & def) +std::wstring Space::Text(const std::wstring & name, const std::wstring & def) const { - std::wstring * value = GetFirstValue(name); + const std::wstring * value = GetFirstValue(name); if( value ) { @@ -286,7 +332,7 @@ std::wstring & Space::TextRef(const std::wstring & name, const std::wstring & de -std::string Space::TextA(const wchar_t * name) +std::string Space::TextA(const wchar_t * name) const { tmp_name = name; return TextA(tmp_name, ""); @@ -294,16 +340,16 @@ std::string Space::TextA(const wchar_t * name) -std::string Space::TextA(const wchar_t * name, const char * def) +std::string Space::TextA(const wchar_t * name, const char * def) const { tmp_name = name; return TextA(tmp_name, def); } -std::string Space::TextA(const std::wstring & name, const char * def) +std::string Space::TextA(const std::wstring & name, const char * def) const { - std::wstring * value = GetFirstValue(name); + const std::wstring * value = GetFirstValue(name); if( value ) { @@ -318,7 +364,38 @@ std::string Space::TextA(const std::wstring & name, const char * def) } -std::string Space::TextA(const std::wstring & name, const std::string & def) +std::string Space::TextA(const std::wstring & name, const std::string & def) const +{ + return TextA(name, def.c_str()); +} + + + +std::string Space::TextA(const wchar_t * name, const wchar_t * def) const +{ + tmp_name = name; + return TextA(tmp_name, def); +} + + +std::string Space::TextA(const std::wstring & name, const wchar_t * def) const +{ + const std::wstring * value = GetFirstValue(name); + std::string res; + + if( value ) + { + PT::WideToUTF8(*value, res); + return res; + } + else + { + PT::WideToUTF8(def, res); + return res; + } +} + +std::string Space::TextA(const std::wstring & name, const std::wstring & def) const { return TextA(name, def.c_str()); } diff --git a/space/space.h b/space/space.h index d94e5cc..6f6dc0d 100644 --- a/space/space.h +++ b/space/space.h @@ -180,6 +180,10 @@ public: Space(const Space & s); Space & operator=(const Space & s); + // IMPROVE ME + // add move cctor + + void Clear(); @@ -231,13 +235,13 @@ public: AText(...) always returns a reference to UTF-8 string */ - std::wstring Text(const wchar_t * name); - std::wstring Text(const wchar_t * name, const wchar_t * def); - std::wstring Text(const std::wstring & name, const wchar_t * def); - std::wstring Text(const std::wstring & name, const std::wstring & def); + std::wstring Text(const wchar_t * name) const; + std::wstring Text(const wchar_t * name, const wchar_t * def) const; + std::wstring Text(const std::wstring & name, const wchar_t * def) const; + std::wstring Text(const std::wstring & name, const std::wstring & def) const; // returns a reference - // if there is no such an option then a new one is inserted + // if there is no such an option then a new one (def value) is inserted std::wstring & TextRef(const wchar_t * name); std::wstring & TextRef(const wchar_t * name, const wchar_t * def); std::wstring & TextRef(const std::wstring & name, const wchar_t * def); @@ -245,10 +249,15 @@ public: // returns UTF-8 string - std::string TextA(const wchar_t * name); - std::string TextA(const wchar_t * name, const char * def); - std::string TextA(const std::wstring & name, const char * def); - std::string TextA(const std::wstring & name, const std::string & def); + std::string TextA(const wchar_t * name) const; + std::string TextA(const wchar_t * name, const char * def) const; + std::string TextA(const std::wstring & name, const char * def) const; + std::string TextA(const std::wstring & name, const std::string & def) const; + + std::string TextA(const wchar_t * name, const wchar_t * def) const; + std::string TextA(const std::wstring & name, const wchar_t * def) const; + std::string TextA(const std::wstring & name, const std::wstring & def) const; + int Int(const wchar_t * name, int def = 0);