202 lines
4.7 KiB
C++
202 lines
4.7 KiB
C++
/*
|
|
* 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) 2019-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_modelenv
|
|
#define headerfile_morm_modelenv
|
|
|
|
#include "modeldata.h"
|
|
#include "cursorhelper.h"
|
|
#include "finderhelper.h"
|
|
#include "fieldvaluehelper.h"
|
|
#include "morm_types.h"
|
|
|
|
#ifdef MORM_HAS_EZC_LIBRARY
|
|
#include "funinfo.h"
|
|
#endif
|
|
|
|
|
|
namespace morm
|
|
{
|
|
class Model;
|
|
class ModelWrapper;
|
|
|
|
|
|
class ModelEnv
|
|
{
|
|
public:
|
|
|
|
// global objects to the whole models tree
|
|
// (values are copied to child models)
|
|
ModelData * model_data;
|
|
FinderHelper * finder_helper;
|
|
CursorHelper * cursor_helper;
|
|
int model_work_mode;
|
|
int model_work_submode;
|
|
bool dump_mode;
|
|
|
|
pt::WTextStream schema_name;
|
|
pt::WTextStream table_name;
|
|
int table_index;
|
|
|
|
/*
|
|
* optional additional table name
|
|
* used in eq(), neq(), ... methods in Finder
|
|
*/
|
|
const wchar_t * table2_name;
|
|
int table2_index;
|
|
|
|
|
|
int field_index;
|
|
bool was_primary_key_read;
|
|
bool has_primary_key_set;
|
|
|
|
|
|
std::vector<const wchar_t *> * set_field_name_helper;
|
|
std::vector<FieldValueHelper> * field_value_helper_tab;
|
|
|
|
/*
|
|
* used when putting a specific field's value to a stream
|
|
*/
|
|
const wchar_t * db_field_name;
|
|
const wchar_t * flat_field_name;
|
|
Model * model;
|
|
Model * child_model;
|
|
ModelWrapper * model_wrapper;
|
|
pt::TextStream * stream;
|
|
|
|
|
|
#ifdef MORM_HAS_EZC_LIBRARY
|
|
void * ezc_fun_info;
|
|
const std::type_info * ezc_fun_info_typeinfo;
|
|
#endif
|
|
|
|
ModelEnv()
|
|
{
|
|
clear();
|
|
}
|
|
|
|
~ModelEnv()
|
|
{
|
|
}
|
|
|
|
|
|
ModelEnv(const ModelEnv & e)
|
|
{
|
|
copy_global_objects(e);
|
|
|
|
table_index = e.table_index;
|
|
table2_index = e.table2_index;
|
|
set_field_name_helper = e.set_field_name_helper;
|
|
field_value_helper_tab = e.field_value_helper_tab;
|
|
field_index = e.field_index;
|
|
was_primary_key_read = e.was_primary_key_read;
|
|
has_primary_key_set = e.has_primary_key_set;
|
|
db_field_name = e.db_field_name;
|
|
flat_field_name = e.flat_field_name;
|
|
model = e.model;
|
|
ezc_fun_info = e.ezc_fun_info;
|
|
ezc_fun_info_typeinfo = e.ezc_fun_info_typeinfo;
|
|
child_model = e.child_model;
|
|
model_wrapper = e.model_wrapper;
|
|
stream = e.stream;
|
|
|
|
|
|
// schema_name and table_name don't have to be copied
|
|
table2_name = nullptr;
|
|
}
|
|
|
|
|
|
void copy_global_objects(const ModelEnv & e)
|
|
{
|
|
model_data = e.model_data;
|
|
finder_helper = e.finder_helper;
|
|
cursor_helper = e.cursor_helper;
|
|
|
|
model_work_mode = e.model_work_mode;
|
|
model_work_submode = e.model_work_submode;
|
|
dump_mode = e.dump_mode;
|
|
}
|
|
|
|
|
|
void clear()
|
|
{
|
|
model_data = nullptr;
|
|
finder_helper = nullptr;
|
|
cursor_helper = nullptr;
|
|
model_work_mode = MORM_MODEL_WORK_MODE_NONE;
|
|
model_work_submode = MORM_MODEL_WORK_SUBMODE_NONE;
|
|
dump_mode = false;
|
|
schema_name.clear();
|
|
table_name.clear();
|
|
table2_name = nullptr;
|
|
table_index = 0;
|
|
table2_index = 0;
|
|
set_field_name_helper = nullptr;
|
|
field_value_helper_tab = nullptr;
|
|
field_index = 0;
|
|
was_primary_key_read = false;
|
|
has_primary_key_set = false;
|
|
db_field_name = nullptr;
|
|
flat_field_name = nullptr;
|
|
model = nullptr;
|
|
child_model = nullptr;
|
|
model_wrapper = nullptr;
|
|
stream = nullptr;
|
|
|
|
#ifdef MORM_HAS_EZC_LIBRARY
|
|
ezc_fun_info = nullptr;
|
|
ezc_fun_info_typeinfo = nullptr;
|
|
#endif
|
|
}
|
|
|
|
|
|
void add_table_name_to_finder_helper()
|
|
{
|
|
if( finder_helper )
|
|
{
|
|
table_index = finder_helper->add_join_table(table_name);
|
|
}
|
|
else
|
|
{
|
|
table_index = 0;
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
#endif
|