2018-03-13 23:22:17 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of morm
|
|
|
|
* and is distributed under the 2-Clause BSD licence.
|
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-02-24 01:15:17 +01:00
|
|
|
* Copyright (c) 2018-2021, Tomasz Sowa
|
2018-03-13 23:22:17 +01:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-03-23 20:26:57 +01:00
|
|
|
#include "jsonexpression.h"
|
|
|
|
#include "morm_types.h"
|
2021-10-12 19:59:19 +02:00
|
|
|
#include "convert/misc.h"
|
2018-03-13 23:22:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace morm
|
|
|
|
{
|
|
|
|
|
2018-03-23 20:26:57 +01:00
|
|
|
|
|
|
|
void JSONExpression::before_generate_from_model()
|
|
|
|
{
|
|
|
|
BaseExpression::before_generate_from_model();
|
|
|
|
|
|
|
|
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
|
|
|
|
{
|
|
|
|
(*out_stream) << "{";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSONExpression::after_generate_from_model()
|
|
|
|
{
|
|
|
|
BaseExpression::after_generate_from_model();
|
|
|
|
|
|
|
|
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
|
|
|
|
{
|
|
|
|
(*out_stream) << "}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void JSONExpression::field_before()
|
|
|
|
{
|
|
|
|
BaseExpression::field_before();
|
|
|
|
|
changed the way how we get a specific field value - now we do not use expressions (BaseExpression), to get the raw value we don't need an expression object:
- removed MORM_WORK_MODE_GET_SPECIFIC_FIELD_VALUE from expression work mode
- removed: void BaseExpression::field(const wchar_t * field_name, void (Model::*getter_method)(pt::TextStream &), const FT & field_type, ModelEnv * model_env)
- removed from BaseExpression: template<typename FunInfoStreamType> void field(const wchar_t * field_name, void (Model::*fun)(Ezc::FunInfo<FunInfoStreamType> &), const FT & field_type, ModelEnv * model_env)
- removed: void FlatConnector::to_text(const wchar_t * flat_field_name, pt::TextStream & stream, Model & model)
- renamed/changed: Model::put_field_value(...) -> Model::get_raw_value()
added classes:
class ModelWrapper - base wrapper class for a model or a model container
class ModelWrapperModel : public ModelWrapper - wrapper for a model
template<typename VectorType> class ModelWrapperVector : public ModelWrapper - wrapper for vector of models
template<typename ListType> class ModelWrapperList : public ModelWrapper - wrapper for list of models
ModelWrapper... classes are used by ezc library for iterating through child models and for iterating in [for...] statements
added to Model:
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);
2021-06-16 14:01:07 +02:00
|
|
|
if( !is_first_field )
|
2018-03-23 20:26:57 +01:00
|
|
|
{
|
|
|
|
(*out_stream) << ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-13 02:32:03 +02:00
|
|
|
void JSONExpression::before_field_name()
|
2018-03-23 20:26:57 +01:00
|
|
|
{
|
2021-10-14 23:51:05 +02:00
|
|
|
(*out_stream) << "<";
|
2018-03-23 20:26:57 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 02:32:03 +02:00
|
|
|
void JSONExpression::after_field_name()
|
2021-02-24 01:15:17 +01:00
|
|
|
{
|
2021-10-14 23:51:05 +02:00
|
|
|
(*out_stream) << ">";
|
2021-02-24 01:15:17 +01:00
|
|
|
}
|
2018-03-23 20:26:57 +01:00
|
|
|
|
2021-02-24 01:15:17 +01:00
|
|
|
|
|
|
|
|
2021-05-12 04:53:23 +02:00
|
|
|
void JSONExpression::before_field_value_string(const FT & field_type)
|
2018-03-23 20:26:57 +01:00
|
|
|
{
|
changed the way how we get a specific field value - now we do not use expressions (BaseExpression), to get the raw value we don't need an expression object:
- removed MORM_WORK_MODE_GET_SPECIFIC_FIELD_VALUE from expression work mode
- removed: void BaseExpression::field(const wchar_t * field_name, void (Model::*getter_method)(pt::TextStream &), const FT & field_type, ModelEnv * model_env)
- removed from BaseExpression: template<typename FunInfoStreamType> void field(const wchar_t * field_name, void (Model::*fun)(Ezc::FunInfo<FunInfoStreamType> &), const FT & field_type, ModelEnv * model_env)
- removed: void FlatConnector::to_text(const wchar_t * flat_field_name, pt::TextStream & stream, Model & model)
- renamed/changed: Model::put_field_value(...) -> Model::get_raw_value()
added classes:
class ModelWrapper - base wrapper class for a model or a model container
class ModelWrapperModel : public ModelWrapper - wrapper for a model
template<typename VectorType> class ModelWrapperVector : public ModelWrapper - wrapper for vector of models
template<typename ListType> class ModelWrapperList : public ModelWrapper - wrapper for list of models
ModelWrapper... classes are used by ezc library for iterating through child models and for iterating in [for...] statements
added to Model:
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);
2021-06-16 14:01:07 +02:00
|
|
|
(*out_stream) << "\"";
|
2018-03-23 20:26:57 +01:00
|
|
|
}
|
|
|
|
|
2021-05-12 04:53:23 +02:00
|
|
|
void JSONExpression::after_field_value_string(const FT & field_type)
|
2018-03-23 20:26:57 +01:00
|
|
|
{
|
changed the way how we get a specific field value - now we do not use expressions (BaseExpression), to get the raw value we don't need an expression object:
- removed MORM_WORK_MODE_GET_SPECIFIC_FIELD_VALUE from expression work mode
- removed: void BaseExpression::field(const wchar_t * field_name, void (Model::*getter_method)(pt::TextStream &), const FT & field_type, ModelEnv * model_env)
- removed from BaseExpression: template<typename FunInfoStreamType> void field(const wchar_t * field_name, void (Model::*fun)(Ezc::FunInfo<FunInfoStreamType> &), const FT & field_type, ModelEnv * model_env)
- removed: void FlatConnector::to_text(const wchar_t * flat_field_name, pt::TextStream & stream, Model & model)
- renamed/changed: Model::put_field_value(...) -> Model::get_raw_value()
added classes:
class ModelWrapper - base wrapper class for a model or a model container
class ModelWrapperModel : public ModelWrapper - wrapper for a model
template<typename VectorType> class ModelWrapperVector : public ModelWrapper - wrapper for vector of models
template<typename ListType> class ModelWrapperList : public ModelWrapper - wrapper for list of models
ModelWrapper... classes are used by ezc library for iterating through child models and for iterating in [for...] statements
added to Model:
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);
2021-06-16 14:01:07 +02:00
|
|
|
(*out_stream) << "\"";
|
2018-03-23 20:26:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSONExpression::put_name_value_separator()
|
|
|
|
{
|
|
|
|
(*out_stream) << ':';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-21 17:51:13 +02:00
|
|
|
void JSONExpression::before_field_value_list()
|
|
|
|
{
|
|
|
|
(*out_stream) << "[";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSONExpression::after_field_value_list()
|
|
|
|
{
|
|
|
|
(*out_stream) << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-20 16:25:01 +02:00
|
|
|
void JSONExpression::esc(char val, pt::TextStream & stream, const FT & field_type)
|
2018-03-13 23:22:17 +01:00
|
|
|
{
|
2021-05-11 22:11:31 +02:00
|
|
|
if( field_type.is_hexadecimal() || field_type.is_binary() )
|
2018-03-13 23:22:17 +01:00
|
|
|
{
|
2021-05-11 22:11:31 +02:00
|
|
|
char_to_hex(val, stream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-12 19:59:19 +02:00
|
|
|
pt::esc_to_json(val, stream);
|
2018-03-13 23:22:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|