added: Wrapper class as a wrapper for: a model, model container (list/vector), Space or Date

added BaseObjectWrapper as base class for: SpaceWrapper and ModelContainerWrapper
removed: ModelWrapperModel, now one Model doesn't need a wrapper
renamed: ModelWrapperSpace -> SpaceWrapper, now as a base class it has BaseObjectWrapper
renamed: Model::get_model_wrapper() -> Model::get_wrapper() - now it returns Wrapper object
removed logging from Model::get_model() and Model::get_wrapper()
field() methods don't take ModelWrapper** but Wrapper& now
This commit is contained in:
2021-07-01 22:55:56 +02:00
parent 84fd351bfc
commit dc6c70499c
8 changed files with 505 additions and 285 deletions

View File

@@ -32,16 +32,13 @@
*
*/
#ifndef headerfile_morm_modelwrapper
#define headerfile_morm_modelwrapper
#ifndef headerfile_morm_modelcontainerwrapper
#define headerfile_morm_modelcontainerwrapper
#include <map>
#include <vector>
#include <list>
#include <string>
#include <limits>
#include "space/space.h"
#include "baseobjectwrapper.h"
namespace morm
@@ -49,41 +46,15 @@ namespace morm
class Model;
class ModelWrapper
class ModelContainerWrapper : public BaseObjectWrapper
{
public:
ModelWrapper()
{
auto_remove = true;
}
virtual ~ModelWrapper()
{
clear_childs();
}
virtual bool should_be_auto_removed()
{
return auto_remove;
}
virtual Model * get_model()
{
return nullptr;
}
virtual pt::Space * get_space()
{
return nullptr;
}
virtual bool is_container()
{
return false;
}
virtual bool is_container_empty()
{
return true;
@@ -93,174 +64,17 @@ public:
{
}
virtual void increment_iterator(size_t space_index, size_t table_size)
{
}
virtual size_t space_indices_table_size()
{
return 0;
}
virtual bool is_iterator_correct()
{
return false;
}
virtual size_t get_space_iterator_value(size_t space_index)
{
return std::numeric_limits<size_t>::max();
}
virtual void clear_childs()
{
for(auto & map_item : childs_map)
{
if( map_item.second->should_be_auto_removed() )
{
delete map_item.second;
map_item.second = nullptr;
}
}
childs_map.clear();
}
virtual void add_child(const std::wstring & child_name, ModelWrapper * models_base)
{
childs_map[child_name] = models_base;
}
virtual ModelWrapper * find_child(const std::wstring & child_name)
{
auto i = childs_map.find(child_name);
if( i != childs_map.end() )
{
return i->second;
}
return nullptr;
}
protected:
bool auto_remove;
std::map<std::wstring, ModelWrapper*> childs_map;
private:
ModelWrapper(const ModelWrapper &)
{
auto_remove = false;
}
ModelWrapper & operator=(const ModelWrapper &)
{
return *this;
}
};
class ModelWrapperModel : public ModelWrapper
{
public:
ModelWrapperModel(Model * model)
{
this->model = model;
}
Model * get_model()
{
return model;
}
protected:
Model * model;
};
class ModelWrapperSpace : public ModelWrapper
{
public:
ModelWrapperSpace(pt::Space * space)
{
this->space = space;
initialize_indices();
}
pt::Space * get_space()
{
return space;
}
size_t space_indices_table_size()
{
return MODEL_WRAPPER_SPACE_INDICES_TABLE_SIZE;
}
void increment_iterator(size_t space_index, size_t table_size)
{
if( space_index < indices.size() )
{
if( indices[space_index] >= table_size )
{
indices[space_index] = 0;
}
else
{
indices[space_index] += 1;
}
}
}
size_t get_space_iterator_value(size_t space_index)
{
if( space_index < indices.size() )
{
return indices[space_index];
}
return std::numeric_limits<size_t>::max();
}
protected:
const size_t MODEL_WRAPPER_SPACE_INDICES_TABLE_SIZE = 32;
pt::Space * space;
std::vector<size_t> indices;
void initialize_indices()
{
indices.resize(MODEL_WRAPPER_SPACE_INDICES_TABLE_SIZE);
for(size_t & val : indices)
{
val = std::numeric_limits<size_t>::max();
}
}
};
template<typename ContainerType>
class ModelWrapperBaseContainer : public ModelWrapper
class ModelWrapperBaseContainer : public ModelContainerWrapper
{
public:
@@ -270,11 +84,6 @@ public:
iterator = container->end();
}
bool is_container()
{
return true;
}
bool is_container_empty()
{
return container->empty();