From 1e4845594291f808f0c4c54153fd30145bbb34ce Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 17 Oct 2012 19:55:16 +0000 Subject: [PATCH] added: to Space: bool HasValue(const wchar_t * name, const wchar_t * value); bool HasValue(const wchar_t * name, const std::wstring & value); bool HasValue(const std::wstring & name, const wchar_t * value); bool HasValue(const std::wstring & name, const std::wstring & value); useful when testing whether a value is in a list (or in simple table too) git-svn-id: svn://ttmath.org/publicrep/pikotools/trunk@433 e52654a7-88a9-db11-a3e9-0013d4bc506e --- space/space.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ space/space.h | 12 ++++++++++++ 2 files changed, 63 insertions(+) diff --git a/space/space.cpp b/space/space.cpp index a617ee7..1990014 100755 --- a/space/space.cpp +++ b/space/space.cpp @@ -163,6 +163,57 @@ const std::wstring * Space::GetValue(const std::wstring & name) const +bool Space::HasValue(const wchar_t * name, const wchar_t * value) +{ + tmp_name = name; + tmp_value_text = value; + +return HasValue(tmp_name, tmp_value_text); +} + +bool Space::HasValue(const wchar_t * name, const std::wstring & value) +{ + tmp_name = name; + +return HasValue(tmp_name, value); +} + + +bool Space::HasValue(const std::wstring & name, const wchar_t * value) +{ + tmp_value_text = value; + +return HasValue(name, tmp_value_text); +} + + +bool Space::HasValue(const std::wstring & name, const std::wstring & value) +{ + TableSingle::const_iterator i = table_single.find(name); + + if( i != table_single.end() ) + { + return i->second == value; + } + else + { + Table::const_iterator t = table.find(name); + + if( t != table.end() ) + { + for(size_t i=0 ; i < t->second.size() ; ++i) + if( t->second[i] == value ) + return true; + } + } + +return false; +} + + + + + std::wstring & Space::Text(const wchar_t * name) { tmp_name = name; diff --git a/space/space.h b/space/space.h index d495440..c2367c8 100755 --- a/space/space.h +++ b/space/space.h @@ -184,6 +184,16 @@ public: const std::wstring * GetValue(const std::wstring & name) const; + /* + returns true if such an option has 'value' + useful when testing lists (they don't have to be copied out) + */ + bool HasValue(const wchar_t * name, const wchar_t * value); + bool HasValue(const wchar_t * name, const std::wstring & value); + bool HasValue(const std::wstring & name, const wchar_t * value); + bool HasValue(const std::wstring & name, const std::wstring & value); + + /* those methods are used to extract information from space.table or space.table_single as a parameter they take the name of an option @@ -299,6 +309,8 @@ public: // null means a root space Space * parent; + + /* those methods are used to extract lists note: if there is one option in table_single they will return it