start working on types for Ezc
- now Var struct has some basic types (string, bool, stream, model, etc.) - Generator doesn't directly put output to out_stream but to Var& result
This commit is contained in:
parent
a983698e3d
commit
e826ba34ae
|
@ -3,33 +3,56 @@
|
||||||
blocks.o: blocks.h item.h cache.h functions.h ../../pikotools/src/utf8/utf8.h
|
blocks.o: blocks.h item.h cache.h functions.h ../../pikotools/src/utf8/utf8.h
|
||||||
blocks.o: ../../pikotools/src/textstream/stream.h
|
blocks.o: ../../pikotools/src/textstream/stream.h
|
||||||
blocks.o: ../../pikotools/src/utf8/utf8_templates.h
|
blocks.o: ../../pikotools/src/utf8/utf8_templates.h
|
||||||
blocks.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h objects.h
|
blocks.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h var.h
|
||||||
|
blocks.o: ../../pikotools/src/date/date.h
|
||||||
|
blocks.o: ../../pikotools/src/convert/inttostr.h
|
||||||
|
blocks.o: ../../pikotools/src/textstream/textstream.h
|
||||||
|
blocks.o: ../../pikotools/src/textstream/stream.h
|
||||||
|
blocks.o: ../../pikotools/src/space/space.h
|
||||||
|
blocks.o: ../../pikotools/src/textstream/types.h
|
||||||
|
blocks.o: ../../pikotools/src/membuffer/membuffer.h
|
||||||
|
blocks.o: ../../pikotools/src/textstream/types.h objects.h
|
||||||
cache.o: cache.h item.h functions.h ../../pikotools/src/utf8/utf8.h
|
cache.o: cache.h item.h functions.h ../../pikotools/src/utf8/utf8.h
|
||||||
cache.o: ../../pikotools/src/textstream/stream.h
|
cache.o: ../../pikotools/src/textstream/stream.h
|
||||||
cache.o: ../../pikotools/src/utf8/utf8_templates.h
|
cache.o: ../../pikotools/src/utf8/utf8_templates.h
|
||||||
cache.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h objects.h blocks.h
|
cache.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h var.h
|
||||||
|
cache.o: ../../pikotools/src/date/date.h
|
||||||
|
cache.o: ../../pikotools/src/convert/inttostr.h
|
||||||
|
cache.o: ../../pikotools/src/textstream/textstream.h
|
||||||
|
cache.o: ../../pikotools/src/textstream/stream.h
|
||||||
|
cache.o: ../../pikotools/src/space/space.h
|
||||||
|
cache.o: ../../pikotools/src/textstream/types.h
|
||||||
|
cache.o: ../../pikotools/src/membuffer/membuffer.h
|
||||||
|
cache.o: ../../pikotools/src/textstream/types.h objects.h blocks.h
|
||||||
item.o: item.h
|
item.o: item.h
|
||||||
models.o: models.h
|
models.o: models.h
|
||||||
pattern.o: pattern.h item.h cache.h functions.h
|
pattern.o: pattern.h item.h cache.h functions.h
|
||||||
pattern.o: ../../pikotools/src/utf8/utf8.h
|
pattern.o: ../../pikotools/src/utf8/utf8.h
|
||||||
pattern.o: ../../pikotools/src/textstream/stream.h
|
pattern.o: ../../pikotools/src/textstream/stream.h
|
||||||
pattern.o: ../../pikotools/src/utf8/utf8_templates.h
|
pattern.o: ../../pikotools/src/utf8/utf8_templates.h
|
||||||
pattern.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h objects.h
|
pattern.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h var.h
|
||||||
pattern.o: blocks.h
|
pattern.o: ../../pikotools/src/date/date.h
|
||||||
|
pattern.o: ../../pikotools/src/convert/inttostr.h
|
||||||
|
pattern.o: ../../pikotools/src/textstream/textstream.h
|
||||||
|
pattern.o: ../../pikotools/src/textstream/stream.h
|
||||||
|
pattern.o: ../../pikotools/src/space/space.h
|
||||||
|
pattern.o: ../../pikotools/src/textstream/types.h
|
||||||
|
pattern.o: ../../pikotools/src/membuffer/membuffer.h
|
||||||
|
pattern.o: ../../pikotools/src/textstream/types.h objects.h blocks.h
|
||||||
patternparser.o: patternparser.h blocks.h item.h cache.h functions.h
|
patternparser.o: patternparser.h blocks.h item.h cache.h functions.h
|
||||||
patternparser.o: ../../pikotools/src/utf8/utf8.h
|
patternparser.o: ../../pikotools/src/utf8/utf8.h
|
||||||
patternparser.o: ../../pikotools/src/textstream/stream.h
|
patternparser.o: ../../pikotools/src/textstream/stream.h
|
||||||
patternparser.o: ../../pikotools/src/utf8/utf8_templates.h
|
patternparser.o: ../../pikotools/src/utf8/utf8_templates.h
|
||||||
patternparser.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h objects.h
|
patternparser.o: ../../pikotools/src/utf8/utf8_private.h funinfo.h var.h
|
||||||
patternparser.o: pattern.h ../../pikotools/src/log/log.h
|
patternparser.o: ../../pikotools/src/date/date.h
|
||||||
|
patternparser.o: ../../pikotools/src/convert/inttostr.h
|
||||||
patternparser.o: ../../pikotools/src/textstream/textstream.h
|
patternparser.o: ../../pikotools/src/textstream/textstream.h
|
||||||
patternparser.o: ../../pikotools/src/textstream/stream.h
|
patternparser.o: ../../pikotools/src/textstream/stream.h
|
||||||
patternparser.o: ../../pikotools/src/space/space.h
|
patternparser.o: ../../pikotools/src/space/space.h
|
||||||
patternparser.o: ../../pikotools/src/textstream/types.h
|
patternparser.o: ../../pikotools/src/textstream/types.h
|
||||||
patternparser.o: ../../pikotools/src/convert/inttostr.h
|
|
||||||
patternparser.o: ../../pikotools/src/date/date.h
|
|
||||||
patternparser.o: ../../pikotools/src/membuffer/membuffer.h
|
patternparser.o: ../../pikotools/src/membuffer/membuffer.h
|
||||||
patternparser.o: ../../pikotools/src/textstream/types.h
|
patternparser.o: ../../pikotools/src/textstream/types.h objects.h pattern.h
|
||||||
|
patternparser.o: ../../pikotools/src/log/log.h
|
||||||
patternparser.o: ../../pikotools/src/log/filelog.h
|
patternparser.o: ../../pikotools/src/log/filelog.h
|
||||||
patternparser.o: ../../pikotools/src/convert/convert.h
|
patternparser.o: ../../pikotools/src/convert/convert.h
|
||||||
patternparser.o: ../../pikotools/src/convert/inttostr.h
|
patternparser.o: ../../pikotools/src/convert/inttostr.h
|
||||||
|
@ -38,3 +61,14 @@ patternparser.o: ../../pikotools/src/convert/strtoint.h
|
||||||
patternparser.o: ../../pikotools/src/convert/text.h
|
patternparser.o: ../../pikotools/src/convert/text.h
|
||||||
patternparser.o: ../../pikotools/src/convert/misc.h
|
patternparser.o: ../../pikotools/src/convert/misc.h
|
||||||
patternparser.o: ../../pikotools/src/convert/double.h
|
patternparser.o: ../../pikotools/src/convert/double.h
|
||||||
|
var.o: var.h ../../pikotools/src/date/date.h
|
||||||
|
var.o: ../../pikotools/src/convert/inttostr.h
|
||||||
|
var.o: ../../pikotools/src/textstream/textstream.h
|
||||||
|
var.o: ../../pikotools/src/textstream/stream.h
|
||||||
|
var.o: ../../pikotools/src/space/space.h
|
||||||
|
var.o: ../../pikotools/src/textstream/types.h ../../pikotools/src/utf8/utf8.h
|
||||||
|
var.o: ../../pikotools/src/textstream/stream.h
|
||||||
|
var.o: ../../pikotools/src/utf8/utf8_templates.h
|
||||||
|
var.o: ../../pikotools/src/utf8/utf8_private.h
|
||||||
|
var.o: ../../pikotools/src/membuffer/membuffer.h
|
||||||
|
var.o: ../../pikotools/src/textstream/types.h
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
o = blocks.o cache.o item.o models.o pattern.o patternparser.o
|
o = blocks.o cache.o item.o models.o pattern.o patternparser.o var.o
|
|
@ -42,33 +42,14 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
#include "modelcontainerwrapper.h"
|
||||||
|
#include "var.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Ezc
|
namespace Ezc
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
a variable
|
|
||||||
*/
|
|
||||||
struct Var
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
|
|
||||||
Var()
|
|
||||||
{
|
|
||||||
res = false;
|
|
||||||
is_function = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<std::wstring, Var> Vars;
|
typedef std::map<std::wstring, Var> Vars;
|
||||||
|
@ -152,8 +133,9 @@ struct FunInfo
|
||||||
// a result consists of a string and a boolean value
|
// a result consists of a string and a boolean value
|
||||||
// output stream
|
// output stream
|
||||||
StreamType & out;
|
StreamType & out;
|
||||||
// return value from a user's function (default false if not set directly by the function)
|
|
||||||
bool res;
|
// result
|
||||||
|
Var & res;
|
||||||
|
|
||||||
// table of parameters
|
// table of parameters
|
||||||
// the table can be empty
|
// the table can be empty
|
||||||
|
@ -162,7 +144,7 @@ struct FunInfo
|
||||||
// the first parameter
|
// the first parameter
|
||||||
// you can always use it even if there are not any parameters (params is empty)
|
// you can always use it even if there are not any parameters (params is empty)
|
||||||
// in such a way the reference points to an empty string
|
// in such a way the reference points to an empty string
|
||||||
const std::wstring & par;
|
//const std::wstring & par;
|
||||||
|
|
||||||
// an input stream used in [filter] statement
|
// an input stream used in [filter] statement
|
||||||
// if there is other statement than [filter] then this is an empty stream
|
// if there is other statement than [filter] then this is an empty stream
|
||||||
|
@ -209,13 +191,11 @@ struct FunInfo
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// arguments: output_stream, table_of_parameters, the_first_parameter
|
FunInfo(Var & result,
|
||||||
FunInfo(StreamType & o,
|
|
||||||
std::vector<Var> & pars,
|
std::vector<Var> & pars,
|
||||||
const std::wstring & first_par,
|
|
||||||
const StreamType & input_stream,
|
const StreamType & input_stream,
|
||||||
Stack & s,
|
Stack & s,
|
||||||
const Item & item_) : out(o), params(pars), par(first_par), in(input_stream), stack(s), item(item_)
|
const Item & item_) : out(result.stream), res(result), params(pars), in(input_stream), stack(s), item(item_)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
@ -223,7 +203,6 @@ struct FunInfo
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
res = false; // result is false by default
|
|
||||||
is_for = false;
|
is_for = false;
|
||||||
is_if = false;
|
is_if = false;
|
||||||
is_if_def = false;
|
is_if_def = false;
|
||||||
|
@ -231,7 +210,7 @@ struct FunInfo
|
||||||
is_normal = false;
|
is_normal = false;
|
||||||
is_filter = false;
|
is_filter = false;
|
||||||
iter = 0;
|
iter = 0;
|
||||||
stack_tab = 0;
|
stack_tab = nullptr;
|
||||||
stack_index = 0;
|
stack_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +221,7 @@ struct FunInfo
|
||||||
*
|
*
|
||||||
* add a function with const wchar_t *
|
* add a function with const wchar_t *
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
Stack * FindLastFor(const std::wstring & name)
|
Stack * FindLastFor(const std::wstring & name)
|
||||||
{
|
{
|
||||||
for(size_t i = stack_index ; i > 0 ; --i)
|
for(size_t i = stack_index ; i > 0 ; --i)
|
||||||
|
@ -257,8 +237,9 @@ struct FunInfo
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
Stack * FindLastFor(const std::wstring & name, const std::wstring & postfix)
|
Stack * FindLastFor(const std::wstring & name, const std::wstring & postfix)
|
||||||
{
|
{
|
||||||
for(size_t i = stack_index ; i > 0 ; --i)
|
for(size_t i = stack_index ; i > 0 ; --i)
|
||||||
|
@ -274,8 +255,10 @@ struct FunInfo
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
template<class FunUserObject>
|
template<class FunUserObject>
|
||||||
FunUserObject * FindUserObject(const std::wstring & function_name, Stack ** ezc_stack = 0)
|
FunUserObject * FindUserObject(const std::wstring & function_name, Stack ** ezc_stack = 0)
|
||||||
{
|
{
|
||||||
|
@ -294,7 +277,7 @@ struct FunInfo
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
431
src/generator.h
431
src/generator.h
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,301 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "var.h"
|
||||||
|
#include "utf8/utf8.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ezc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Var::Var()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Var::clear()
|
||||||
|
{
|
||||||
|
//res = false;
|
||||||
|
//is_function = false;
|
||||||
|
|
||||||
|
type = TYPE_VOID;
|
||||||
|
model = nullptr;
|
||||||
|
model_container_wrapper = nullptr;
|
||||||
|
date = nullptr;
|
||||||
|
space_wrapper = nullptr;
|
||||||
|
space_local.clear();
|
||||||
|
stream.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::to_bool() const
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case TYPE_VOID:
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case TYPE_BOOL:
|
||||||
|
return space_local.to_bool();
|
||||||
|
|
||||||
|
case TYPE_STRING:
|
||||||
|
return to_bool_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::to_bool_str() const
|
||||||
|
{
|
||||||
|
if( space_local.is_str() )
|
||||||
|
return !space_local.get_str()->empty();
|
||||||
|
else
|
||||||
|
if( space_local.is_wstr() )
|
||||||
|
return !space_local.get_wstr()->empty();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set(bool val)
|
||||||
|
{
|
||||||
|
type = TYPE_BOOL;
|
||||||
|
space_local.set(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set(const char * str)
|
||||||
|
{
|
||||||
|
type = TYPE_STRING;
|
||||||
|
space_local.set(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set(const wchar_t * str)
|
||||||
|
{
|
||||||
|
type = TYPE_STRING;
|
||||||
|
space_local.set(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set(const std::string & str)
|
||||||
|
{
|
||||||
|
type = TYPE_STRING;
|
||||||
|
space_local.set(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set(const std::wstring & str)
|
||||||
|
{
|
||||||
|
type = TYPE_STRING;
|
||||||
|
space_local.set(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::set_function(const std::wstring & str)
|
||||||
|
{
|
||||||
|
type = TYPE_FUNCTION;
|
||||||
|
space_local.set(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal(const char * str) const
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case TYPE_BOOL:
|
||||||
|
return is_equal_bool(str);
|
||||||
|
|
||||||
|
case TYPE_STRING:
|
||||||
|
return is_equal_string(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal(const wchar_t * str) const
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case TYPE_BOOL:
|
||||||
|
return is_equal_bool(str);
|
||||||
|
|
||||||
|
case TYPE_STRING:
|
||||||
|
return is_equal_string(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal(const std::string & str) const
|
||||||
|
{
|
||||||
|
return is_equal(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal(const std::wstring & str) const
|
||||||
|
{
|
||||||
|
return is_equal(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal_bool(const char * str) const
|
||||||
|
{
|
||||||
|
if( space_local.to_bool() )
|
||||||
|
{
|
||||||
|
return str[0] != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return str[0] == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::is_equal_bool(const wchar_t * str) const
|
||||||
|
{
|
||||||
|
if( space_local.to_bool() )
|
||||||
|
{
|
||||||
|
return str[0] != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return str[0] == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Var::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Var::serialize_to(pt::WTextStream & str)
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case TYPE_BOOL:
|
||||||
|
case TYPE_LONG:
|
||||||
|
case TYPE_STRING:
|
||||||
|
space_local.serialize_to_string(str);
|
||||||
|
break;
|
||||||
|
case TYPE_STREAM:
|
||||||
|
str = stream;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Var & Var::operator<<(const char * str)
|
||||||
|
{
|
||||||
|
type == TYPE_STREAM;
|
||||||
|
stream << str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Var & Var::operator<<(const wchar_t * str)
|
||||||
|
{
|
||||||
|
type == TYPE_STREAM;
|
||||||
|
stream << str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Var & Var::operator<<(const std::string & str)
|
||||||
|
{
|
||||||
|
type == TYPE_STREAM;
|
||||||
|
stream << str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Var & Var::operator<<(const std::wstring & str)
|
||||||
|
{
|
||||||
|
type == TYPE_STREAM;
|
||||||
|
stream << str;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,159 @@
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace Ezc
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
a variable
|
||||||
|
*/
|
||||||
|
class Var
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
// string or wstring from space_local
|
||||||
|
TYPE_VOID,
|
||||||
|
TYPE_BOOL,
|
||||||
|
TYPE_LONG,
|
||||||
|
TYPE_STRING,
|
||||||
|
TYPE_STREAM,
|
||||||
|
|
||||||
|
TYPE_FUNCTION,
|
||||||
|
|
||||||
|
TYPE_MODEL,
|
||||||
|
TYPE_MODEL_CONTAINER_WRAPPER,
|
||||||
|
TYPE_SPACE_WRAPPER, // or just type_space
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
Type type;
|
||||||
|
|
||||||
|
Var();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
|
||||||
|
bool to_bool() const;
|
||||||
|
|
||||||
|
|
||||||
|
void set(bool val);
|
||||||
|
void set(const char * str);
|
||||||
|
void set(const wchar_t * str);
|
||||||
|
void set(const std::string & str);
|
||||||
|
void set(const std::wstring & str);
|
||||||
|
|
||||||
|
void set_function(const std::wstring & str);
|
||||||
|
|
||||||
|
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);
|
||||||
|
// add the rest of << operators...
|
||||||
|
|
||||||
|
|
||||||
|
morm::Model * model;
|
||||||
|
morm::ModelContainerWrapper * model_container_wrapper;
|
||||||
|
pt::Date * date;
|
||||||
|
morm::SpaceWrapper * space_wrapper;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//pt::Space * space;
|
||||||
|
|
||||||
|
|
||||||
|
pt::Space space_local;
|
||||||
|
pt::WTextStream stream;
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
bool to_bool_str() const;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue