api2021 part I #4
155
space/space.cpp
155
space/space.cpp
|
@ -1284,6 +1284,8 @@ Space::TableType * Space::get_table()
|
||||||
return type == type_table ? &value.value_table : nullptr;
|
return type == type_table ? &value.value_table : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Space::is_equal(const char * val) const
|
bool Space::is_equal(const char * val) const
|
||||||
{
|
{
|
||||||
if( type == type_string )
|
if( type == type_string )
|
||||||
|
@ -1326,6 +1328,65 @@ bool Space::is_equal(const std::wstring & val) const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const char * val) const
|
||||||
|
{
|
||||||
|
if( type == type_string )
|
||||||
|
{
|
||||||
|
return value.value_string == val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( type == type_table )
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i < value.value_table.size() ; ++i)
|
||||||
|
{
|
||||||
|
PT::Space * table_item = value.value_table[i];
|
||||||
|
|
||||||
|
if( table_item->type == type_string )
|
||||||
|
{
|
||||||
|
return table_item->value.value_string == val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Space::has_value(const std::string & val) const
|
||||||
|
{
|
||||||
|
return has_value(val.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const wchar_t * val) const
|
||||||
|
{
|
||||||
|
if( type == type_wstring )
|
||||||
|
{
|
||||||
|
return value.value_wstring == val;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( type == type_table )
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i < value.value_table.size() ; ++i)
|
||||||
|
{
|
||||||
|
PT::Space * table_item = value.value_table[i];
|
||||||
|
|
||||||
|
if( table_item->type == type_wstring )
|
||||||
|
{
|
||||||
|
return table_item->value.value_wstring == val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const std::wstring & val) const
|
||||||
|
{
|
||||||
|
return has_value(val.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1618,6 +1679,60 @@ bool Space::is_equal(const wchar_t * field, const std::wstring & val) const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const wchar_t * field, const char * val) const
|
||||||
|
{
|
||||||
|
const Space * space = get_object_field(field);
|
||||||
|
|
||||||
|
if( space )
|
||||||
|
{
|
||||||
|
return space->has_value(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Space::has_value(const wchar_t * field, const std::string & val) const
|
||||||
|
{
|
||||||
|
const Space * space = get_object_field(field);
|
||||||
|
|
||||||
|
if( space )
|
||||||
|
{
|
||||||
|
return space->has_value(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const wchar_t * field, const wchar_t * val) const
|
||||||
|
{
|
||||||
|
const Space * space = get_object_field(field);
|
||||||
|
|
||||||
|
if( space )
|
||||||
|
{
|
||||||
|
return space->has_value(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Space::has_value(const wchar_t * field, const std::wstring & val) const
|
||||||
|
{
|
||||||
|
const Space * space = get_object_field(field);
|
||||||
|
|
||||||
|
if( space )
|
||||||
|
{
|
||||||
|
return space->has_value(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Space * Space::find_child_space(const wchar_t * name)
|
Space * Space::find_child_space(const wchar_t * name)
|
||||||
{
|
{
|
||||||
return find_child_space_generic(name);
|
return find_child_space_generic(name);
|
||||||
|
@ -1661,6 +1776,46 @@ Space & Space::find_add_child_space(const std::wstring & name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Space::remove_child_space(const wchar_t * name)
|
||||||
|
{
|
||||||
|
if( child_spaces )
|
||||||
|
{
|
||||||
|
for(size_t i=0 ; i<child_spaces->size() ; )
|
||||||
|
{
|
||||||
|
PT::Space * child = (*child_spaces)[i];
|
||||||
|
|
||||||
|
if( child->name && (*child->name) == name )
|
||||||
|
{
|
||||||
|
delete child;
|
||||||
|
child = nullptr;
|
||||||
|
child_spaces->erase(child_spaces->begin() + i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Space::remove_child_space(const std::wstring & name)
|
||||||
|
{
|
||||||
|
return remove_child_space(name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Space::remove_child_space(size_t index)
|
||||||
|
{
|
||||||
|
if( child_spaces && index < child_spaces->size() )
|
||||||
|
{
|
||||||
|
PT::Space * child = (*child_spaces)[index];
|
||||||
|
delete child;
|
||||||
|
child = nullptr;
|
||||||
|
|
||||||
|
child_spaces->erase(child_spaces->begin() + index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -294,11 +294,6 @@ public:
|
||||||
Space & add_empty_space(const std::wstring & field); // IMPROVEME rename me to something better
|
Space & add_empty_space(const std::wstring & field); // IMPROVEME rename me to something better
|
||||||
|
|
||||||
|
|
||||||
// for child spaces (used only in Space format)
|
|
||||||
// rename to something better
|
|
||||||
Space & add_child_space(const wchar_t * space_name);
|
|
||||||
|
|
||||||
|
|
||||||
// IMPROVEME add a similar 'set' method and cctor
|
// IMPROVEME add a similar 'set' method and cctor
|
||||||
template<typename StreamType>
|
template<typename StreamType>
|
||||||
Space & add_stream(const wchar_t * field, StreamType & str)
|
Space & add_stream(const wchar_t * field, StreamType & str)
|
||||||
|
@ -414,11 +409,17 @@ public:
|
||||||
ObjectType * get_object();
|
ObjectType * get_object();
|
||||||
TableType * get_table();
|
TableType * get_table();
|
||||||
|
|
||||||
|
// may a better name?
|
||||||
bool is_equal(const char * val) const;
|
bool is_equal(const char * val) const;
|
||||||
bool is_equal(const std::string & val) const;
|
bool is_equal(const std::string & val) const;
|
||||||
bool is_equal(const wchar_t * val) const;
|
bool is_equal(const wchar_t * val) const;
|
||||||
bool is_equal(const std::wstring & val) const;
|
bool is_equal(const std::wstring & val) const;
|
||||||
// add these is_equal with std::wstring
|
|
||||||
|
// may a better name?
|
||||||
|
bool has_value(const char * val) const;
|
||||||
|
bool has_value(const std::string & val) const;
|
||||||
|
bool has_value(const wchar_t * val) const;
|
||||||
|
bool has_value(const std::wstring & val) const;
|
||||||
|
|
||||||
|
|
||||||
// what about getters from tables?
|
// what about getters from tables?
|
||||||
|
@ -540,21 +541,36 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add this method with field with std::wstring
|
||||||
bool is_equal(const wchar_t * field, const char * val) const;
|
bool is_equal(const wchar_t * field, const char * val) const;
|
||||||
bool is_equal(const wchar_t * field, const std::string & val) const;
|
bool is_equal(const wchar_t * field, const std::string & val) const;
|
||||||
bool is_equal(const wchar_t * field, const wchar_t * val) const;
|
bool is_equal(const wchar_t * field, const wchar_t * val) const;
|
||||||
bool is_equal(const wchar_t * field, const std::wstring & val) const;
|
bool is_equal(const wchar_t * field, const std::wstring & val) const;
|
||||||
// add these is_equal with std::wstring
|
|
||||||
|
// may a better name?
|
||||||
|
// add this method with field with std::wstring
|
||||||
|
bool has_value(const wchar_t * field, const char * val) const;
|
||||||
|
bool has_value(const wchar_t * field, const std::string & val) const;
|
||||||
|
bool has_value(const wchar_t * field, const wchar_t * val) const;
|
||||||
|
bool has_value(const wchar_t * field, const std::wstring & val) const;
|
||||||
|
|
||||||
|
|
||||||
|
// for child spaces (used only in Space format)
|
||||||
Space * find_child_space(const wchar_t * name);
|
Space * find_child_space(const wchar_t * name);
|
||||||
Space * find_child_space(const std::wstring & name);
|
Space * find_child_space(const std::wstring & name);
|
||||||
const Space * find_child_space(const wchar_t * name) const;
|
const Space * find_child_space(const wchar_t * name) const;
|
||||||
const Space * find_child_space(const std::wstring & name) const;
|
const Space * find_child_space(const std::wstring & name) const;
|
||||||
|
|
||||||
|
Space & add_child_space(const wchar_t * space_name);
|
||||||
|
|
||||||
Space & find_add_child_space(const wchar_t * name);
|
Space & find_add_child_space(const wchar_t * name);
|
||||||
Space & find_add_child_space(const std::wstring & name);
|
Space & find_add_child_space(const std::wstring & name);
|
||||||
|
|
||||||
|
void remove_child_space(const wchar_t * name);
|
||||||
|
void remove_child_space(const std::wstring & name);
|
||||||
|
void remove_child_space(size_t index);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue