added to Space: child_spaces and a name of a Space

pull/4/head
Tomasz Sowa 2 years ago
parent 5b5a1dfbb6
commit 31f7bdb857

@ -50,17 +50,19 @@ namespace PT
Space::Space()
{
type = type_null;
child_spaces = nullptr;
name = nullptr;
}
Space::Space(const Space & space)
{
copy_value_from(space);
copy_from(space);
}
Space & Space::operator=(const Space & space)
{
copy_value_from(space);
copy_from(space);
return *this;
}
@ -68,6 +70,8 @@ Space & Space::operator=(const Space & space)
Space::~Space()
{
remove_value();
remove_child_spaces();
remove_space_name();
}
@ -298,7 +302,7 @@ void Space::set(const Space * space)
}
else
{
copy_value_from(*space);
copy_from(*space);
}
}
@ -472,6 +476,19 @@ Space & Space::add_empty_space(const wchar_t * field)
return add_generic(field, static_cast<Space*>(nullptr));
}
Space & Space::add_child_space(const wchar_t * space_name)
{
initialize_child_spaces_if_needed();
child_spaces->push_back(new Space());
Space * last_space = child_spaces->back();
last_space->initialize_space_name_if_needed();
last_space->name->append(space_name);
return *last_space;
}
bool Space::is_null() const
@ -947,6 +964,50 @@ void Space::copy_value_from(const Space & space)
}
void Space::copy_child_spaces_from(const Space & space)
{
if( space.child_spaces )
{
initialize_child_spaces_if_needed();
child_spaces->clear();
for(size_t i = 0 ; i < space.child_spaces->size() ; ++i)
{
child_spaces->push_back(new Space((*space.child_spaces)[i]));
}
}
else
if( child_spaces )
{
remove_child_spaces();
}
}
void Space::copy_space_name_from(const Space & space)
{
if( space.name )
{
initialize_space_name_if_needed();
*name = *space.name;
}
else
if( name )
{
remove_space_name();
}
}
void Space::copy_from(const Space & space)
{
copy_value_from(space);
copy_child_spaces_from(space);
copy_space_name_from(space);
}
void Space::copy_value_object(const Value & value_from)
@ -1074,6 +1135,25 @@ void Space::initialize_value_table_if_needed()
}
void Space::initialize_child_spaces_if_needed()
{
if( child_spaces == nullptr )
{
child_spaces = new TableType();
}
}
void Space::initialize_space_name_if_needed()
{
if( name == nullptr )
{
name = new std::wstring();
}
}
void Space::remove_value()
{
switch(type)
@ -1153,6 +1233,31 @@ void Space::remove_value_table()
}
void Space::remove_child_spaces()
{
if( child_spaces )
{
for(size_t i = 0 ; i < child_spaces->size() ; ++i)
{
delete (*child_spaces)[i];
(*child_spaces)[i] = nullptr;
}
delete child_spaces;
child_spaces = nullptr;
}
}
void Space::remove_space_name()
{
if( name )
{
delete name;
name = nullptr;
}
}
} // namespace

@ -178,6 +178,9 @@ public:
Type type;
Value value;
std::wstring * name;
TableType * child_spaces;
Space();
@ -269,6 +272,8 @@ public:
Space & add_empty_space(const wchar_t * field); // IMPROVEME rename me to something better
Space & add_child_space(const wchar_t * space_name);
bool is_null() const;
bool is_bool() const;
@ -745,6 +750,10 @@ protected:
void copy_value_from(const Space & space);
void copy_child_spaces_from(const Space & space);
void copy_space_name_from(const Space & space);
void copy_from(const Space & space);
void copy_value_object(const Value & value_from);
void copy_value_table(const Value & value_from);
@ -757,12 +766,16 @@ protected:
void initialize_value_wstring_if_needed();
void initialize_value_object_if_needed();
void initialize_value_table_if_needed();
void initialize_child_spaces_if_needed();
void initialize_space_name_if_needed();
void remove_value();
void remove_value_string();
void remove_value_wstring();
void remove_value_object();
void remove_value_table();
void remove_child_spaces();
void remove_space_name();
};

Loading…
Cancel
Save