added ModelWrapperSpace for wrapping the pt::Space class

This commit is contained in:
Tomasz Sowa 2021-06-22 17:59:44 +02:00
parent e74575db42
commit 86bf9cf688
3 changed files with 105 additions and 5 deletions

View File

@ -286,12 +286,12 @@ ModelWrapper * Model::get_model_wrapper(const wchar_t * db_field_name, const wch
model_env->db_field_name = db_field_name; model_env->db_field_name = db_field_name;
model_env->flat_field_name = flat_field_name; model_env->flat_field_name = flat_field_name;
model_env->model = this; model_env->model = this;
ModelWrapper * models_base = nullptr; ModelWrapper * model_wrapper = nullptr;
try try
{ {
fields(); fields();
models_base = model_env->model_wrapper; model_wrapper = model_env->model_wrapper;
} }
catch(...) catch(...)
{ {
@ -312,7 +312,7 @@ ModelWrapper * Model::get_model_wrapper(const wchar_t * db_field_name, const wch
} }
model_env = nullptr; model_env = nullptr;
return models_base; return model_wrapper;
} }

View File

@ -457,7 +457,7 @@ protected:
void field(const wchar_t * field_name, pt::Space & field_value, const FT & field_type = FT::default_type) void field(const wchar_t * field_name, pt::Space & field_value, const FT & field_type = FT::default_type)
{ {
field_generic(field_name, field_name, field_value, field_type); field_space(field_name, field_name, field_value, field_type);
} }
void field(const wchar_t * field_name, Model & field_value, const FT & field_type = FT::default_type) void field(const wchar_t * field_name, Model & field_value, const FT & field_type = FT::default_type)
@ -587,7 +587,7 @@ protected:
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::Space & field_value, const FT & field_type = FT::default_type) void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::Space & field_value, const FT & field_type = FT::default_type)
{ {
field_generic(db_field_name, flat_field_name, field_value, field_type); field_space(db_field_name, flat_field_name, field_value, field_type);
} }
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, Model & field_value, const FT & field_type = FT::default_type) void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, Model & field_value, const FT & field_type = FT::default_type)
@ -823,6 +823,26 @@ protected:
} }
void field_space(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::Space & field_value, const FT & field_type)
{
if( model_connector && model_env )
{
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER )
{
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) &&
!model_env->model_wrapper )
{
model_env->model_wrapper = new ModelWrapperSpace(&field_value);
}
}
else
{
field_generic(db_field_name, flat_field_name, field_value, field_type);
}
}
}
void field_member_set_field_value( void field_member_set_field_value(
const wchar_t * db_field_name, const wchar_t * db_field_name,

View File

@ -39,6 +39,9 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <string> #include <string>
#include <limits>
#include "space/space.h"
namespace morm namespace morm
@ -71,6 +74,11 @@ public:
return nullptr; return nullptr;
} }
virtual pt::Space * get_space()
{
return nullptr;
}
virtual bool is_container() virtual bool is_container()
{ {
return false; return false;
@ -85,11 +93,21 @@ public:
{ {
} }
virtual void increment_iterator(size_t space_index, size_t table_size)
{
}
virtual bool is_iterator_correct() virtual bool is_iterator_correct()
{ {
return false; return false;
} }
virtual size_t get_space_iterator_value(size_t space_index)
{
return std::numeric_limits<size_t>::max();
}
virtual void clear_childs() virtual void clear_childs()
{ {
for(auto & map_item : childs_map) for(auto & map_item : childs_map)
@ -169,6 +187,68 @@ protected:
class ModelWrapperSpace : public ModelWrapper
{
public:
const size_t MODEL_WRAPPER_SPACE_INDICES_TABLE_SIZE = 32;
ModelWrapperSpace(pt::Space * space)
{
this->space = space;
initialize_indices();
}
pt::Space * get_space()
{
return space;
}
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:
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> template<typename ContainerType>
class ModelWrapperBaseContainer : public ModelWrapper class ModelWrapperBaseContainer : public ModelWrapper