reorganizing class hierarchy
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1075 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
254
src/baseexpression.h
Normal file
254
src/baseexpression.h
Normal file
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* 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) 2018, 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_baseexpression
|
||||
#define headerfile_morm_baseexpression
|
||||
|
||||
|
||||
#include "textstream/textstream.h"
|
||||
#include "morm_types.h"
|
||||
|
||||
|
||||
namespace morm
|
||||
{
|
||||
class Model;
|
||||
class ModelConnector;
|
||||
|
||||
|
||||
class BaseExpression
|
||||
{
|
||||
public:
|
||||
|
||||
BaseExpression();
|
||||
virtual ~BaseExpression();
|
||||
|
||||
|
||||
virtual void set_work_mode(int work_mode);
|
||||
virtual void generate_from_model(PT::TextStream & stream, Model & model);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
int work_mode; /* what to do: generating fields list, values list or fields-values list */
|
||||
bool is_first_field;
|
||||
|
||||
// niech Stream bedzie jakims interfejsem z operatorami << dla standardowych typow
|
||||
// albo w pikotoolsach dodać klase bazowa (intefejs) dla streamow
|
||||
// i dodatkowo dodac loger ktory dziedziczy po niej i dodaje loglevel i endline
|
||||
// jako metode bazowa dodac format("string", parametry,...)
|
||||
// przyda sie do formatowania doubli
|
||||
PT::TextStream * out_stream;
|
||||
|
||||
// virtual void map_fields(Model * model)
|
||||
// {
|
||||
// work_mode = model->work_mode;
|
||||
// out_stream = model->out_stream;
|
||||
// is_insert = model->is_insert;
|
||||
// is_update = model->is_update;
|
||||
//
|
||||
// generate_from_model();
|
||||
// }
|
||||
|
||||
virtual void before_generate_from_model();
|
||||
virtual void after_generate_from_model();
|
||||
virtual bool can_field_be_generated(bool insertable, bool updatable, bool is_primary_key);
|
||||
virtual void field_before();
|
||||
virtual void field_after();
|
||||
|
||||
template<typename FieldValue>
|
||||
void field(const wchar_t * field_name, const FieldValue & field_value, bool insertable = true, bool updatable = true, bool is_primary_key = false)
|
||||
{
|
||||
if( can_field_be_generated(insertable, updatable, is_primary_key) )
|
||||
{
|
||||
field_before();
|
||||
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS )
|
||||
{
|
||||
put_field_name(field_name);
|
||||
}
|
||||
else
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_VALUES )
|
||||
{
|
||||
put_field_value(field_value);
|
||||
}
|
||||
else
|
||||
if( work_mode == MORM_WORK_MODE_MODEL_FIELDS_VALUES )
|
||||
{
|
||||
print_field_name_value(field_name, field_value);
|
||||
}
|
||||
|
||||
field_after();
|
||||
}
|
||||
}
|
||||
|
||||
//void field(const wchar_t * field_name, Model & field, bool insertable = true, bool updatable = true);
|
||||
|
||||
virtual void put_field_name(const wchar_t * field_name);
|
||||
|
||||
template<typename FieldValue>
|
||||
void put_field_value(const FieldValue & field_value)
|
||||
{
|
||||
before_field_value(field_value);
|
||||
esc(field_value, *out_stream);
|
||||
after_field_value(field_value);
|
||||
}
|
||||
|
||||
|
||||
virtual void before_field_name();
|
||||
virtual void after_field_name();
|
||||
|
||||
virtual void before_field_value(const std::wstring &);
|
||||
virtual void after_field_value(const std::wstring &);
|
||||
|
||||
virtual void before_field_value(const std::string &);
|
||||
virtual void after_field_value(const std::string &);
|
||||
|
||||
template<typename FieldValue>
|
||||
void before_field_value(const FieldValue &)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename FieldValue>
|
||||
void after_field_value(const FieldValue &)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void put_name_value_separator();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
template<typename Container>
|
||||
void field_container(const wchar_t * field_name, Container container, bool insertable = true, bool updatable = true)
|
||||
{
|
||||
typename Container::value Value; // czy tu jest Container::value? sprawdzic
|
||||
|
||||
if( !is_first_field )
|
||||
(*out_stream) << ",";
|
||||
|
||||
if( work_mode == ORM_STREAM_MODE_CREATING_JSON )
|
||||
{
|
||||
(*out_stream) << "[";
|
||||
boolean is_first = true;
|
||||
|
||||
for(Value v : container)
|
||||
{
|
||||
if( !is_first )
|
||||
(*out_stream) << ",";
|
||||
|
||||
v.map_fields(this);
|
||||
is_first = false;
|
||||
}
|
||||
|
||||
(*out_stream) << "]";
|
||||
}
|
||||
// a co z bazą danych?
|
||||
|
||||
|
||||
is_first_field = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
template<typename FieldValue>
|
||||
void print_field_name_value(const wchar_t * field_name, const FieldValue & field_value)
|
||||
{
|
||||
put_field_name(field_name);
|
||||
put_name_value_separator();
|
||||
put_field_value(field_value);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
template<typename Container>
|
||||
virtual void field_container(const wchar_t * field_name, Container container, bool insertable = true, bool updatable = true)
|
||||
{
|
||||
typename Container::value Value; // czy tu jest Container::value? sprawdzic
|
||||
|
||||
if( !is_first_field )
|
||||
(*out_stream) << ",";
|
||||
|
||||
if( work_mode == ORM_STREAM_MODE_CREATING_JSON )
|
||||
{
|
||||
(*out_stream) << "[";
|
||||
boolean is_first = true;
|
||||
|
||||
for(Value v : container)
|
||||
{
|
||||
if( !is_first )
|
||||
(*out_stream) << ",";
|
||||
|
||||
v.map_fields(this);
|
||||
is_first = false;
|
||||
}
|
||||
|
||||
(*out_stream) << "]";
|
||||
}
|
||||
// a co z bazą danych?
|
||||
|
||||
|
||||
is_first_field = false;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
virtual void esc(char val, PT::TextStream & stream);
|
||||
virtual void esc(unsigned char val, PT::TextStream & stream);
|
||||
|
||||
virtual void esc(const std::wstring & val, PT::TextStream & stream);
|
||||
virtual void esc(const wchar_t * val, PT::TextStream & stream);
|
||||
virtual void esc(const std::string & val, PT::TextStream & stream);
|
||||
virtual void esc(const char * val, PT::TextStream & stream);
|
||||
|
||||
virtual void esc(bool val, PT::TextStream & stream);
|
||||
virtual void esc(short val, PT::TextStream & stream);
|
||||
virtual void esc(unsigned short val, PT::TextStream & stream);
|
||||
virtual void esc(int val, PT::TextStream & stream);
|
||||
virtual void esc(unsigned int val, PT::TextStream & stream);
|
||||
virtual void esc(long val, PT::TextStream & stream);
|
||||
virtual void esc(unsigned long val, PT::TextStream & stream);
|
||||
virtual void esc(long long val, PT::TextStream & stream);
|
||||
virtual void esc(unsigned long long val, PT::TextStream & stream);
|
||||
virtual void esc(float val, PT::TextStream & stream);
|
||||
virtual void esc(double val, PT::TextStream & stream);
|
||||
virtual void esc(long double val, PT::TextStream & stream);
|
||||
virtual void esc(void* val, PT::TextStream & stream);
|
||||
|
||||
friend ModelConnector;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user