some concept about serializing space from a model

This commit is contained in:
Tomasz Sowa 2021-06-21 23:11:48 +02:00
parent a8fe798279
commit 7638ad4b76
4 changed files with 140 additions and 40 deletions

View File

@ -278,7 +278,7 @@ Model * Model::get_model(const wchar_t * db_field_name, const wchar_t * flat_fie
}
ModelWrapper * Model::get_model_wrapper(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found)
ModelHelper Model::get_model_helper(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found)
{
ModelEnv model_env_local;
model_env = &model_env_local;
@ -286,12 +286,13 @@ ModelWrapper * Model::get_model_wrapper(const wchar_t * db_field_name, const wch
model_env->db_field_name = db_field_name;
model_env->flat_field_name = flat_field_name;
model_env->model = this;
ModelWrapper * models_base = nullptr;
ModelHelper model_helper;
try
{
fields();
models_base = model_env->model_wrapper;
model_helper.model_wrapper = model_env->model_wrapper;
model_helper.space = model_env->space;
}
catch(...)
{
@ -312,7 +313,7 @@ ModelWrapper * Model::get_model_wrapper(const wchar_t * db_field_name, const wch
}
model_env = nullptr;
return models_base;
return model_helper;
}

View File

@ -49,6 +49,7 @@
#include "modelenv.h"
#include "ft.h"
#include "modelwrapper.h"
#include "modelhelper.h"
#ifdef MORM_HAS_EZC_LIBRARY
#include "funinfo.h"
@ -253,7 +254,7 @@ public:
Model * get_model(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found = true);
ModelWrapper * get_model_wrapper(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found = true);
ModelHelper get_model_helper(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool put_log_if_not_found = true);
bool get_raw_value(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::Stream & stream, bool clear_stream = true, bool put_log_if_not_found = true);
bool get_raw_value(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelData * model_data, pt::Stream & stream, bool clear_stream = true, bool put_log_if_not_found = true);
@ -457,7 +458,7 @@ protected:
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)
@ -587,7 +588,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)
{
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)
@ -823,6 +824,25 @@ 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->space = &field_value;
}
}
else
{
field_generic(db_field_name, flat_field_name, field_value, field_type);
}
}
}
void field_member_set_field_value(
const wchar_t * db_field_name,
@ -1151,22 +1171,25 @@ protected:
{
ContainerItemType * item_type_null_pointer = nullptr;
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER )
if( model_connector && model_env )
{
if constexpr (std::is_base_of<Model, ContainerItemType>())
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 )
if constexpr (std::is_base_of<Model, ContainerItemType>())
{
model_env->model_wrapper = new ModelWrapperVector(&field_value);
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 ModelWrapperVector(&field_value);
}
}
}
}
else
{
ContainerItemType * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
else
{
ContainerItemType * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
}
}
}
@ -1201,22 +1224,25 @@ protected:
{
ContainerItemType * item_type_null_pointer = nullptr;
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER )
if( model_connector && model_env )
{
if constexpr (std::is_base_of<Model, ContainerItemType>())
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 )
if constexpr (std::is_base_of<Model, ContainerItemType>())
{
model_env->model_wrapper = new ModelWrapperVectorPointer(&field_value);
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 ModelWrapperVectorPointer(&field_value);
}
}
}
}
else
{
void * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
else
{
void * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
}
}
}
@ -1226,22 +1252,25 @@ protected:
{
ContainerItemType * item_type_null_pointer = nullptr;
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER )
if( model_connector && model_env )
{
if constexpr (std::is_base_of<Model, ContainerItemType>())
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 )
if constexpr (std::is_base_of<Model, ContainerItemType>())
{
model_env->model_wrapper = new ModelWrapperListPointer(&field_value);
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 ModelWrapperListPointer(&field_value);
}
}
}
}
else
{
void * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
else
{
void * pointer = nullptr;
field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer);
}
}
}

View File

@ -93,6 +93,7 @@ public:
Model * model;
Model * child_model;
ModelWrapper * model_wrapper;
pt::Space * space;
pt::Stream * stream;
bool was_field_found; // used only in MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM
@ -134,6 +135,7 @@ public:
model = e.model;
child_model = e.child_model;
model_wrapper = e.model_wrapper;
space = e.space;
stream = e.stream;
was_field_found = e.was_field_found;
@ -185,6 +187,7 @@ public:
model = nullptr;
child_model = nullptr;
model_wrapper = nullptr;
space = nullptr;
stream = nullptr;
was_field_found = false;

67
src/modelhelper.h Normal file
View File

@ -0,0 +1,67 @@
/*
* This file is a part of morm
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_morm_modelhelper
#define headerfile_morm_modelhelper
#include "modelwrapper.h"
#include "space/space.h"
namespace morm
{
class ModelHelper
{
public:
ModelWrapper * model_wrapper;
pt::Space * space;
ModelHelper()
{
model_wrapper = nullptr;
space = nullptr;
}
};
}
#endif