2021-08-29 20:35:15 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of EZC -- Easy templating in C++ library
|
|
|
|
* and is distributed under the BSD 3-Clause 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:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * 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.
|
|
|
|
*
|
|
|
|
* * Neither the name Tomasz Sowa nor the names of contributors to this
|
|
|
|
* project may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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 OWNER 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_ezc_var
|
|
|
|
#define headerfile_ezc_var
|
|
|
|
|
|
|
|
#include "spacewrapper.h"
|
|
|
|
#include "date/date.h"
|
|
|
|
#include "modelcontainerwrapper.h"
|
|
|
|
#include "textstream/textstream.h"
|
2021-11-05 09:34:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
namespace morm
|
|
|
|
{
|
|
|
|
class Model;
|
|
|
|
class ModelContainerWrapper;
|
|
|
|
class SpaceWrapper;
|
|
|
|
}
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ezc
|
|
|
|
{
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
template<typename StreamType>
|
|
|
|
struct Env;
|
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
a variable
|
|
|
|
*/
|
2021-10-20 08:23:45 +02:00
|
|
|
template<typename StreamType>
|
2021-08-29 20:35:15 +02:00
|
|
|
class Var
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
typedef void (*UserFunction)(Env<StreamType> &);
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
// string or wstring from space_local
|
|
|
|
TYPE_VOID,
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-11-05 09:34:05 +01:00
|
|
|
TYPE_SPACE_LOCAL,
|
|
|
|
// TYPE_BOOL,
|
|
|
|
// TYPE_LONG,
|
|
|
|
// TYPE_DOUBLE,
|
|
|
|
// TYPE_STRING,
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
TYPE_STREAM,
|
|
|
|
|
|
|
|
TYPE_FUNCTION,
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
TYPE_DATE,
|
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
TYPE_MODEL,
|
|
|
|
TYPE_MODEL_CONTAINER_WRAPPER,
|
|
|
|
TYPE_SPACE_WRAPPER, // or just type_space
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Var();
|
2021-10-27 14:23:48 +02:00
|
|
|
Var(const Var & var);
|
|
|
|
Var & operator=(const Var & var);
|
|
|
|
~Var();
|
|
|
|
// IMPROVEME add move cctor and operator=
|
|
|
|
|
|
|
|
Var * add_child(const std::wstring & child_name, const Var & var);
|
|
|
|
Var * find_child(const std::wstring & child_name);
|
|
|
|
bool has_object();
|
|
|
|
bool has_model_object();
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
void clear();
|
2021-10-27 14:23:48 +02:00
|
|
|
void clear_childs();
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
bool to_bool() const;
|
|
|
|
|
|
|
|
|
|
|
|
void set(const char * str);
|
|
|
|
void set(const wchar_t * str);
|
|
|
|
void set(const std::string & str);
|
|
|
|
void set(const std::wstring & str);
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
// void set(char val);
|
|
|
|
// void set(unsigned char val);
|
|
|
|
// void set(wchar_t val);
|
|
|
|
void set(bool val);
|
|
|
|
void set(short val);
|
|
|
|
void set(int val);
|
|
|
|
void set(long val);
|
|
|
|
void set(long long val);
|
|
|
|
void set(unsigned short val);
|
|
|
|
void set(unsigned int val);
|
|
|
|
void set(unsigned long val);
|
|
|
|
void set(unsigned long long val);
|
|
|
|
|
|
|
|
void set(float val);
|
|
|
|
void set(double val);
|
|
|
|
void set(long double val);
|
|
|
|
|
|
|
|
// this str object is copied
|
|
|
|
void set(const pt::Stream & str);
|
|
|
|
|
|
|
|
void set(UserFunction user_function);
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
void set(const pt::Date & date);
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
// this model is not copied, is it a correct interface?
|
|
|
|
void set(morm::Model & model);
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
void set(morm::ModelContainerWrapper & model_container_wrapper);
|
2021-10-20 08:23:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
bool is_equal(const char * str) const;
|
|
|
|
bool is_equal(const wchar_t * str) const;
|
|
|
|
|
|
|
|
bool is_equal(const std::string & str) const;
|
|
|
|
bool is_equal(const std::wstring & str) const;
|
|
|
|
|
|
|
|
void serialize_to(pt::WTextStream & str);
|
|
|
|
|
|
|
|
|
|
|
|
Var & operator<<(const char * str);
|
|
|
|
Var & operator<<(const wchar_t * str);
|
|
|
|
Var & operator<<(const std::string & str);
|
|
|
|
Var & operator<<(const std::wstring & str);
|
2021-10-20 08:23:45 +02:00
|
|
|
Var & operator<<(char val);
|
|
|
|
Var & operator<<(unsigned char val);
|
|
|
|
Var & operator<<(wchar_t val);
|
|
|
|
Var & operator<<(bool val);
|
|
|
|
Var & operator<<(short val);
|
|
|
|
Var & operator<<(int val);
|
|
|
|
Var & operator<<(long val);
|
|
|
|
Var & operator<<(long long val);
|
|
|
|
Var & operator<<(unsigned short val);
|
|
|
|
Var & operator<<(unsigned int val);
|
|
|
|
Var & operator<<(unsigned long val);
|
|
|
|
Var & operator<<(unsigned long long val);
|
|
|
|
Var & operator<<(float val);
|
|
|
|
Var & operator<<(double val);
|
|
|
|
Var & operator<<(long double val);
|
|
|
|
Var & operator<<(const pt::Stream & str);
|
|
|
|
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
|
|
|
|
Type type;
|
2021-10-20 08:23:45 +02:00
|
|
|
UserFunction user_function;
|
2021-08-29 20:35:15 +02:00
|
|
|
morm::Model * model;
|
|
|
|
morm::ModelContainerWrapper * model_container_wrapper;
|
|
|
|
pt::Date * date;
|
|
|
|
morm::SpaceWrapper * space_wrapper;
|
|
|
|
|
|
|
|
pt::Space space_local;
|
2021-10-20 08:23:45 +02:00
|
|
|
StreamType stream;
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
std::map<std::wstring, Var> childs_map;
|
|
|
|
|
|
|
|
void initialize_empty();
|
|
|
|
void copy(const Var & var);
|
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
bool is_equal_bool(const char * str) const;
|
|
|
|
bool is_equal_string(const char * str) const;
|
|
|
|
|
|
|
|
bool is_equal_bool(const wchar_t * str) const;
|
|
|
|
bool is_equal_string(const wchar_t * str) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
/*
|
|
|
|
* old
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if true then means 'str' is a function name and should be called (res is ignored)
|
|
|
|
*
|
|
|
|
* if false then means 'str' is a string value and res is a boolean value
|
|
|
|
*/
|
|
|
|
//bool is_function;
|
|
|
|
|
|
|
|
//std::wstring str; // a string value
|
|
|
|
//bool res; // a boolean value
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType>::Var()
|
2021-10-27 14:23:48 +02:00
|
|
|
{
|
|
|
|
initialize_empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType>::Var(const Var & var)
|
|
|
|
{
|
|
|
|
initialize_empty();
|
|
|
|
copy(var);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator=(const Var & var)
|
2021-10-20 08:23:45 +02:00
|
|
|
{
|
|
|
|
clear();
|
2021-10-27 14:23:48 +02:00
|
|
|
copy(var);
|
|
|
|
|
|
|
|
return *this;
|
2021-10-20 08:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
2021-10-27 14:23:48 +02:00
|
|
|
void Var<StreamType>::copy(const Var & var)
|
2021-10-20 08:23:45 +02:00
|
|
|
{
|
2021-10-27 14:23:48 +02:00
|
|
|
type = var.type;
|
|
|
|
user_function = var.user_function;
|
|
|
|
model = var.model;
|
|
|
|
model_container_wrapper = var.model_container_wrapper;
|
|
|
|
date = var.date;
|
|
|
|
space_wrapper = var.space_wrapper;
|
|
|
|
space_local = var.space_local;
|
|
|
|
stream = var.stream;
|
|
|
|
|
|
|
|
if( model_container_wrapper )
|
|
|
|
{
|
|
|
|
model_container_wrapper->increment_reference_counter();
|
|
|
|
}
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
if( space_wrapper )
|
|
|
|
{
|
|
|
|
space_wrapper->increment_reference_counter();
|
|
|
|
}
|
|
|
|
|
|
|
|
// childs_map don't need to be copied
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType>::~Var()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::initialize_empty()
|
|
|
|
{
|
2021-10-20 08:23:45 +02:00
|
|
|
type = TYPE_VOID;
|
|
|
|
user_function = nullptr;
|
|
|
|
model = nullptr;
|
|
|
|
model_container_wrapper = nullptr;
|
|
|
|
date = nullptr;
|
|
|
|
space_wrapper = nullptr;
|
2021-10-27 14:23:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::clear()
|
|
|
|
{
|
|
|
|
if( model_container_wrapper )
|
|
|
|
{
|
|
|
|
model_container_wrapper->decrement_reference_counter();
|
|
|
|
|
|
|
|
if( model_container_wrapper->get_reference_counter() == 0 && model_container_wrapper->should_be_auto_removed() )
|
|
|
|
{
|
|
|
|
delete model_container_wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( space_wrapper )
|
|
|
|
{
|
|
|
|
space_wrapper->decrement_reference_counter();
|
|
|
|
|
|
|
|
if( space_wrapper->get_reference_counter() == 0 && space_wrapper->should_be_auto_removed() )
|
|
|
|
{
|
|
|
|
delete space_wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize_empty();
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.clear();
|
|
|
|
stream.clear();
|
2021-10-27 14:23:48 +02:00
|
|
|
clear_childs();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::clear_childs()
|
|
|
|
{
|
|
|
|
childs_map.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> * Var<StreamType>::add_child(const std::wstring & child_name, const Var & var)
|
|
|
|
{
|
|
|
|
Var & v = childs_map[child_name];
|
|
|
|
v.clear();
|
|
|
|
v = var;
|
|
|
|
return &v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> * Var<StreamType>::find_child(const std::wstring & child_name)
|
|
|
|
{
|
|
|
|
auto i = childs_map.find(child_name);
|
|
|
|
|
|
|
|
if( i != childs_map.end() )
|
|
|
|
{
|
|
|
|
return &i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::has_object()
|
|
|
|
{
|
|
|
|
return type != TYPE_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::has_model_object()
|
|
|
|
{
|
|
|
|
return model || model_container_wrapper;
|
2021-10-20 08:23:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::to_bool() const
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case TYPE_VOID:
|
|
|
|
return false;
|
|
|
|
|
2021-11-05 09:34:05 +01:00
|
|
|
// case TYPE_BOOL:
|
|
|
|
// case TYPE_LONG:
|
|
|
|
// case TYPE_DOUBLE:
|
|
|
|
// case TYPE_STRING:
|
|
|
|
case TYPE_SPACE_LOCAL:
|
2021-10-20 08:23:45 +02:00
|
|
|
return space_local.to_bool();
|
|
|
|
|
|
|
|
case TYPE_STREAM:
|
|
|
|
case TYPE_FUNCTION:
|
2021-10-27 14:23:48 +02:00
|
|
|
case TYPE_DATE:
|
2021-10-20 08:23:45 +02:00
|
|
|
case TYPE_MODEL:
|
|
|
|
case TYPE_MODEL_CONTAINER_WRAPPER:
|
|
|
|
case TYPE_SPACE_WRAPPER:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const char * str)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const wchar_t * str)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const std::string & str)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const std::wstring & str)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(char val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(unsigned char val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(wchar_t val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(str);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(bool val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(short val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(int val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(long val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(long long val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(unsigned short val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(unsigned int val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(unsigned long val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(unsigned long long val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(float val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(double val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(long double val)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
type = TYPE_SPACE_LOCAL;
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.set(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const pt::Stream & str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream.clear();
|
|
|
|
stream << str;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(UserFunction user_function)
|
|
|
|
{
|
|
|
|
type = TYPE_FUNCTION;
|
|
|
|
this->user_function = user_function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(const pt::Date & date)
|
|
|
|
{
|
|
|
|
type = TYPE_DATE;
|
|
|
|
this->date = &date;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(morm::Model & model)
|
|
|
|
{
|
|
|
|
type = TYPE_MODEL;
|
|
|
|
this->model = &model;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::set(morm::ModelContainerWrapper & model_container_wrapper)
|
|
|
|
{
|
|
|
|
type = TYPE_MODEL_CONTAINER_WRAPPER;
|
|
|
|
this->model_container_wrapper = &model_container_wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal(const char * str) const
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
case TYPE_SPACE_LOCAL:
|
|
|
|
if( space_local.is_str() || space_local.is_wstr() )
|
|
|
|
return is_equal_string(str);
|
|
|
|
|
|
|
|
if( space_local.is_bool() )
|
|
|
|
return is_equal_bool(str);
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-11-05 09:34:05 +01:00
|
|
|
// IMPLEMENTME
|
|
|
|
// implement the rest of conversion methods
|
|
|
|
|
|
|
|
return false;
|
2021-10-20 08:23:45 +02:00
|
|
|
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_STREAM:
|
|
|
|
case TYPE_FUNCTION:
|
2021-10-27 14:23:48 +02:00
|
|
|
case TYPE_DATE:
|
2021-10-20 08:23:45 +02:00
|
|
|
case TYPE_MODEL:
|
|
|
|
case TYPE_MODEL_CONTAINER_WRAPPER:
|
|
|
|
case TYPE_SPACE_WRAPPER:
|
2021-11-05 09:34:05 +01:00
|
|
|
// IMPLEMENTME
|
2021-10-20 08:23:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal(const wchar_t * str) const
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
case TYPE_SPACE_LOCAL:
|
|
|
|
if( space_local.is_str() || space_local.is_wstr() )
|
|
|
|
return is_equal_string(str);
|
|
|
|
|
|
|
|
if( space_local.is_bool() )
|
|
|
|
return is_equal_bool(str);
|
2021-10-20 08:23:45 +02:00
|
|
|
|
2021-11-05 09:34:05 +01:00
|
|
|
// IMPLEMENTME
|
|
|
|
// implement the rest of conversion methods
|
|
|
|
|
|
|
|
return false;
|
2021-10-20 08:23:45 +02:00
|
|
|
|
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_STREAM:
|
|
|
|
case TYPE_FUNCTION:
|
2021-10-27 14:23:48 +02:00
|
|
|
case TYPE_DATE:
|
2021-10-20 08:23:45 +02:00
|
|
|
case TYPE_MODEL:
|
|
|
|
case TYPE_MODEL_CONTAINER_WRAPPER:
|
|
|
|
case TYPE_SPACE_WRAPPER:
|
2021-11-05 09:34:05 +01:00
|
|
|
// IMPLEMENTME
|
2021-10-20 08:23:45 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal(const std::string & str) const
|
|
|
|
{
|
|
|
|
return is_equal(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal(const std::wstring & str) const
|
|
|
|
{
|
|
|
|
return is_equal(str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal_bool(const char * str) const
|
|
|
|
{
|
|
|
|
if( space_local.to_bool() )
|
|
|
|
{
|
|
|
|
return str[0] != 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return str[0] == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal_string(const char * str) const
|
|
|
|
{
|
|
|
|
if( space_local.is_str() )
|
|
|
|
{
|
|
|
|
return space_local.is_equal(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( space_local.is_wstr() )
|
|
|
|
{
|
|
|
|
std::string space_str_utf8;
|
|
|
|
pt::wide_to_utf8(*space_local.get_wstr(), space_str_utf8);
|
|
|
|
return space_str_utf8 == str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal_bool(const wchar_t * str) const
|
|
|
|
{
|
|
|
|
if( space_local.to_bool() )
|
|
|
|
{
|
|
|
|
return str[0] != 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return str[0] == 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
bool Var<StreamType>::is_equal_string(const wchar_t * str) const
|
|
|
|
{
|
|
|
|
if( space_local.is_wstr() )
|
|
|
|
{
|
|
|
|
return space_local.is_equal(str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if( space_local.is_str() )
|
|
|
|
{
|
|
|
|
std::string str_utf8;
|
|
|
|
pt::wide_to_utf8(str, str_utf8);
|
|
|
|
return space_local.is_equal(str_utf8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
void Var<StreamType>::serialize_to(pt::WTextStream & str)
|
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2021-11-05 09:34:05 +01:00
|
|
|
case TYPE_SPACE_LOCAL:
|
|
|
|
// case TYPE_BOOL:
|
|
|
|
// case TYPE_LONG:
|
|
|
|
// case TYPE_DOUBLE:
|
|
|
|
// case TYPE_STRING:
|
2021-10-20 08:23:45 +02:00
|
|
|
space_local.serialize_to_string(str);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_STREAM:
|
2021-11-05 09:34:05 +01:00
|
|
|
str << stream;
|
2021-10-20 08:23:45 +02:00
|
|
|
break;
|
|
|
|
|
2021-10-27 14:23:48 +02:00
|
|
|
case TYPE_DATE:
|
|
|
|
date->SerializeISO(str);
|
|
|
|
break;
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
case TYPE_VOID:
|
|
|
|
case TYPE_FUNCTION:
|
|
|
|
case TYPE_MODEL:
|
|
|
|
case TYPE_MODEL_CONTAINER_WRAPPER:
|
|
|
|
case TYPE_SPACE_WRAPPER:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(const char * str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(const wchar_t * str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(const std::string & str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(const std::wstring & str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(char val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(unsigned char val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(wchar_t val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(bool val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(short val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(int val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(long val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(long long val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(unsigned short val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(unsigned int val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(unsigned long val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(unsigned long long val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(float val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(double val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(long double val)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << val;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename StreamType>
|
|
|
|
Var<StreamType> & Var<StreamType>::operator<<(const pt::Stream & str)
|
|
|
|
{
|
|
|
|
type = TYPE_STREAM;
|
|
|
|
stream << str;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-08-29 20:35:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|