From 3bde64e03338416142458f4727f6159a685ef409 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 12 May 2022 00:21:42 +0200 Subject: [PATCH] add possibility to set save status for the whole tree add method: void Model::set_save_mode2(SaveMode save_mode, bool update_whole_tree = true) in the future it may be renamed to set_save_mode() --- src/dbexpression.cpp | 2 +- src/model.cpp | 22 +++++++++++++++++++- src/model.h | 49 +++++++++++++++++++++++++++++++++++++++++++- src/morm_types.h | 4 ++-- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/src/dbexpression.cpp b/src/dbexpression.cpp index 9841299..ed63b9b 100644 --- a/src/dbexpression.cpp +++ b/src/dbexpression.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2021, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/src/model.cpp b/src/model.cpp index c1f99d9..9caf383 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2021, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -74,6 +74,21 @@ Model::SaveMode Model::get_save_mode() } +void Model::set_save_mode2(SaveMode save_mode, bool update_whole_tree) +{ + this->save_mode = save_mode; + + if( update_whole_tree ) + { + ModelEnv model_env_local; + model_env = &model_env_local; + model_env->model_work_mode = MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS; + fields(); + model_env = nullptr; + } +} + + void Model::set_has_primary_key_set(bool has_primary_key) { this->has_primary_key_set = has_primary_key; @@ -1578,6 +1593,11 @@ void Model::field_model(const wchar_t * db_field_name, const wchar_t * flat_fiel } } + if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS ) + { + field_model.set_save_mode2(save_mode, true); + } + field_model.model_env = nullptr; } } diff --git a/src/model.h b/src/model.h index 7c4de9d..15ce0a9 100644 --- a/src/model.h +++ b/src/model.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2021, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -153,6 +153,9 @@ public: virtual void set_save_mode(SaveMode save_mode); virtual SaveMode get_save_mode(); + // set_save_mode() will be changed to set_save_mode2() in the future + virtual void set_save_mode2(SaveMode save_mode, bool update_whole_tree = true); + virtual void set_has_primary_key_set(bool has_primary_key); virtual bool get_has_primary_key_set(); @@ -1188,6 +1191,45 @@ protected: } + template + void field_list_propagate_save_status(ModelContainer & field_container, ModelContainerType * model_container_type, IsContainerByValueRenameMe * foo) + { + if constexpr (std::is_base_of()) + { + if constexpr (std::is_base_of()) + { + field_list_propagate_save_status_in_container_by_value(field_container, model_container_type); + } + else + { + field_list_propagate_save_status_in_container_by_pointer(field_container, model_container_type); + } + } + } + + + template + void field_list_propagate_save_status_in_container_by_value(ModelContainer & field_container, ModelContainerType * model_container_type) + { + for(ModelContainerType & item : field_container) + { + item.set_connector(model_connector); + item.set_save_mode2(save_mode, true); + } + } + + + template + void field_list_propagate_save_status_in_container_by_pointer(ModelContainer & field_container, ModelContainerType * model_container_type) + { + for(ModelContainerType * item : field_container) + { + item->set_connector(model_connector); + item->set_save_mode2(save_mode, true); + } + } + + template void field_vector(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::vector & field_value, const FT & field_type) { @@ -1372,6 +1414,11 @@ protected: { field_list_clearing_values(field_container, model_container_type, foo); } + + if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS ) + { + field_list_propagate_save_status(field_container, model_container_type, foo); + } } } diff --git a/src/morm_types.h b/src/morm_types.h index d764171..78d385d 100644 --- a/src/morm_types.h +++ b/src/morm_types.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018-2021, Tomasz Sowa + * Copyright (c) 2018-2022, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ #define MORM_MODEL_WORK_MODE_GET_FIELD_MODEL 10 #define MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER 11 #define MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM 12 - +#define MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS 13 // submodes used in some cases