17 Commits

Author SHA1 Message Date
tomasz.sowa 62a094f2c6 WIP: add a Val struct as an input/output when calling a function 2025-01-31 17:10:40 +01:00
tomasz.sowa b646287c9b WIP: add a Val struct as an input/output when calling a function 2025-01-30 18:05:37 +01:00
tomasz.sowa 44ea6a162e WIP: add a Val struct as an input/output when calling a function 2025-01-29 16:59:40 +01:00
tomasz.sowa 32d9fdc816 WIP: add a Val struct as an input/output when calling a function 2025-01-28 16:46:19 +01:00
tomasz.sowa 1f2b5c8d12 WIP: add a Val struct as an input/output when calling a function 2025-01-24 19:40:52 +01:00
tomasz.sowa 37f78ad8e0 WIP: add a Val struct as an input/output when calling a function 2025-01-23 07:12:57 +01:00
tomasz.sowa 8819adbb3f WIP: add a Val struct as an input/output when calling a function 2025-01-15 18:29:46 +01:00
tomasz.sowa 19d33139fc WIP: add a Val struct as an input/output when calling a function 2025-01-15 17:17:34 +01:00
tomasz.sowa ec45ae971e WIP: add a Val struct as an input/output when calling a function 2025-01-15 09:19:24 +01:00
tomasz.sowa dc2ee61a23 WIP: add a Val struct as an input/output when calling a function 2025-01-03 17:32:59 +01:00
tomasz.sowa 345e1870e3 WIP: add a Val struct as an input/output when calling a function 2024-12-13 15:47:54 +01:00
tomasz.sowa 6f75664400 WIP: add a Val struct as an input/output when calling a function 2024-12-12 17:57:24 +01:00
tomasz.sowa 0ac4df97e9 WIP: add a Val struct as an input/output when calling a function 2024-12-11 17:29:32 +01:00
tomasz.sowa 6e2fe34a5c WIP: add a Val struct as an input/output when calling a function 2024-12-11 17:04:05 +01:00
tomasz.sowa 079a62c230 WIP: add a Val struct as an input/output when calling a function 2024-12-09 16:36:53 +01:00
tomasz.sowa 5d5d5bcdde rename the FunInfo struct to Env 2024-12-06 12:20:55 +01:00
tomasz.sowa e39311c290 WIP: use pt::Stream instead of a template argument 2024-12-05 17:48:06 +01:00
21 changed files with 4068 additions and 1318 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
CompileFlags:
Add: [-pthread, -std=c++20, -I%%%CURRENT_DIR%%%/src, -I%%%GLOBAL_WORKING_DIR%%%/pikotools/src, -I%%%GLOBAL_WORKING_DIR%%%/morm/src, -I/usr/include, -I/usr/local/include, -DEZC_HAS_MORM_LIBRARY]
Add: [-pthread, -std=c++20, -I%%%CURRENT_DIR%%%/src, -I%%%GLOBAL_WORKING_DIR%%%/pikotools/src, -I%%%GLOBAL_WORKING_DIR%%%/morm/src, -I/usr/include, -I/usr/local/include, -DEZC_HAS_MORM_LIBRARY, -DMORM_HAS_EZC_LIBRARY]
+85 -4
View File
@@ -1,31 +1,86 @@
./blocks.o: ../../pikotools/src/convert/inttostr.h
./blocks.o: ../../pikotools/src/convert/misc.h
./blocks.o: ../../pikotools/src/date/date.h
./blocks.o: ../../pikotools/src/membuffer/membuffer.h
./blocks.o: ../../pikotools/src/space/space.h
./blocks.o: ../../pikotools/src/textstream/stream_private.h
./blocks.o: ../../pikotools/src/textstream/stream.h
./blocks.o: ../../pikotools/src/textstream/textstream.h
./blocks.o: ../../pikotools/src/textstream/types.h
./blocks.o: ../../pikotools/src/utf8/utf8.h
./blocks.o: blocks.h
./blocks.o: cache.h
./blocks.o: env.h
./blocks.o: functions.h
./blocks.o: funinfo.h
./blocks.o: item.h
./blocks.o: objects.h
./blocks.o: val.h
./cache.o: ../../pikotools/src/convert/inttostr.h
./cache.o: ../../pikotools/src/convert/misc.h
./cache.o: ../../pikotools/src/date/date.h
./cache.o: ../../pikotools/src/membuffer/membuffer.h
./cache.o: ../../pikotools/src/space/space.h
./cache.o: ../../pikotools/src/textstream/stream_private.h
./cache.o: ../../pikotools/src/textstream/stream.h
./cache.o: ../../pikotools/src/textstream/textstream.h
./cache.o: ../../pikotools/src/textstream/types.h
./cache.o: ../../pikotools/src/utf8/utf8.h
./cache.o: blocks.h
./cache.o: cache.h
./cache.o: env.h
./cache.o: functions.h
./cache.o: funinfo.h
./cache.o: item.h
./cache.o: objects.h
./cache.o: val.h
./functions.o: ../../pikotools/src/convert/inttostr.h
./functions.o: ../../pikotools/src/convert/misc.h
./functions.o: ../../pikotools/src/date/date.h
./functions.o: ../../pikotools/src/membuffer/membuffer.h
./functions.o: ../../pikotools/src/space/space.h
./functions.o: ../../pikotools/src/textstream/stream_private.h
./functions.o: ../../pikotools/src/textstream/stream.h
./functions.o: ../../pikotools/src/textstream/textstream.h
./functions.o: ../../pikotools/src/textstream/types.h
./functions.o: ../../pikotools/src/utf8/utf8.h
./functions.o: env.h
./functions.o: functions.h
./functions.o: item.h
./functions.o: val.h
./item.o: item.h
./models.o: models.h
./objects.o: ../../pikotools/src/convert/inttostr.h
./objects.o: ../../pikotools/src/convert/misc.h
./objects.o: ../../pikotools/src/date/date.h
./objects.o: ../../pikotools/src/membuffer/membuffer.h
./objects.o: ../../pikotools/src/space/space.h
./objects.o: ../../pikotools/src/textstream/stream_private.h
./objects.o: ../../pikotools/src/textstream/stream.h
./objects.o: ../../pikotools/src/textstream/textstream.h
./objects.o: ../../pikotools/src/textstream/types.h
./objects.o: ../../pikotools/src/utf8/utf8.h
./objects.o: env.h
./objects.o: item.h
./objects.o: objects.h
./objects.o: val.h
./pattern.o: ../../pikotools/src/convert/inttostr.h
./pattern.o: ../../pikotools/src/convert/misc.h
./pattern.o: ../../pikotools/src/date/date.h
./pattern.o: ../../pikotools/src/membuffer/membuffer.h
./pattern.o: ../../pikotools/src/space/space.h
./pattern.o: ../../pikotools/src/textstream/stream_private.h
./pattern.o: ../../pikotools/src/textstream/stream.h
./pattern.o: ../../pikotools/src/textstream/textstream.h
./pattern.o: ../../pikotools/src/textstream/types.h
./pattern.o: ../../pikotools/src/utf8/utf8.h
./pattern.o: blocks.h
./pattern.o: cache.h
./pattern.o: env.h
./pattern.o: functions.h
./pattern.o: funinfo.h
./pattern.o: item.h
./pattern.o: objects.h
./pattern.o: pattern.h
./pattern.o: val.h
./patternparser.o: ../../pikotools/src/convert/convert.h
./patternparser.o: ../../pikotools/src/convert/double.h
./patternparser.o: ../../pikotools/src/convert/inttostr.h
@@ -45,10 +100,36 @@
./patternparser.o: ../../pikotools/src/utf8/utf8.h
./patternparser.o: blocks.h
./patternparser.o: cache.h
./patternparser.o: env.h
./patternparser.o: functions.h
./patternparser.o: funinfo.h
./patternparser.o: item.h
./patternparser.o: objects.h
./patternparser.o: pattern.h
./patternparser.o: patternparser.h
./patternparser.o: val.h
./val.o: ../../pikotools/src/convert/inttostr.h
./val.o: ../../pikotools/src/convert/misc.h
./val.o: ../../pikotools/src/date/date.h
./val.o: ../../pikotools/src/membuffer/membuffer.h
./val.o: ../../pikotools/src/space/space.h
./val.o: ../../pikotools/src/textstream/stream_private.h
./val.o: ../../pikotools/src/textstream/stream.h
./val.o: ../../pikotools/src/textstream/textstream.h
./val.o: ../../pikotools/src/textstream/types.h
./val.o: ../../pikotools/src/utf8/utf8.h
./val.o: item.h
./val.o: val.h
./valwrapper.o: ../../pikotools/src/convert/inttostr.h
./valwrapper.o: ../../pikotools/src/convert/misc.h
./valwrapper.o: ../../pikotools/src/date/date.h
./valwrapper.o: ../../pikotools/src/membuffer/membuffer.h
./valwrapper.o: ../../pikotools/src/space/space.h
./valwrapper.o: ../../pikotools/src/textstream/stream_private.h
./valwrapper.o: ../../pikotools/src/textstream/stream.h
./valwrapper.o: ../../pikotools/src/textstream/textstream.h
./valwrapper.o: ../../pikotools/src/textstream/types.h
./valwrapper.o: ../../pikotools/src/utf8/utf8.h
./valwrapper.o: item.h
./valwrapper.o: val.h
./valwrapper.o: valwrapper.h
# DO NOT DELETE
+19
View File
@@ -85,6 +85,24 @@ void Blocks::ClearCache()
void Blocks::CacheObjects(Objects & obj)
{
BlocksTable::iterator i = blocks_tab.begin();
for( ; i != blocks_tab.end() ; ++i)
Cache(obj, i->second);
}
// void Blocks::CacheFunctions(Functions & fun)
// {
// BlocksTable::iterator i = blocks_tab.begin();
// for( ; i != blocks_tab.end() ; ++i)
// Cache(fun, i->second);
// }
void Blocks::CacheBlocks(Blocks & blocks)
{
BlocksTable::iterator i = blocks_tab.begin();
@@ -95,4 +113,5 @@ void Blocks::CacheBlocks(Blocks & blocks)
} // namespace
+3 -23
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2014-2015, Tomasz Sowa
* Copyright (c) 2014-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,8 +62,8 @@ public:
size_t Size() const;
void Clear();
template<class StreamType> void CacheObjects(Objects<StreamType> & obj);
template<class StreamType> void CacheFunctions(Functions<StreamType> & fun);
void CacheObjects(Objects & obj);
//void CacheFunctions(Functions & fun);
void CacheBlocks(Blocks & blocks);
void ClearCache();
@@ -75,26 +75,6 @@ private:
};
template<class StreamType>
void Blocks::CacheObjects(Objects<StreamType> & obj)
{
BlocksTable::iterator i = blocks_tab.begin();
for( ; i != blocks_tab.end() ; ++i)
Cache(obj, i->second);
}
template<class StreamType>
void Blocks::CacheFunctions(Functions<StreamType> & fun)
{
BlocksTable::iterator i = blocks_tab.begin();
for( ; i != blocks_tab.end() ; ++i)
Cache(fun, i->second);
}
} // namespace
+51
View File
@@ -58,6 +58,32 @@ void Cache(Blocks & blocks, Item::Function & function)
}
// void Cache(Functions & fun, Item::Function & function)
// {
// function.fun_cache = 0;
// if( !function.name.empty() && function.arg < 0 )
// {
// typename Functions::Iterator i = fun.Find(function.name);
// if( i != fun.End() )
// function.fun_cache = &i->second;
// }
// for(size_t i=0 ; i < function.parameters.size() ; ++i)
// Cache(fun, *function.parameters[i]);
// }
// void Cache(Functions & fun, Item & item)
// {
// Cache(fun, item.function);
// for(size_t i=0; i < item.item_tab.size() ; ++i)
// Cache(fun, *item.item_tab[i]);
// }
void Cache(Blocks & blocks, Item & item)
{
@@ -68,6 +94,31 @@ void Cache(Blocks & blocks, Item & item)
}
void Cache(Objects & objects, Item::Function & function)
{
function.base_obj = 0;
function.method_index = -1;
if( !function.name.empty() && function.arg < 0 )
{
typename Objects::Iterator i = objects.Find(function.name, function.method_index);
if( i != objects.End() )
function.base_obj = *i;
}
for(size_t i=0 ; i < function.parameters.size() ; ++i)
Cache(objects, *function.parameters[i]);
}
void Cache(Objects & objects, Item & item)
{
Cache(objects, item.function);
for(size_t i=0; i < item.item_tab.size() ; ++i)
Cache(objects, *item.item_tab[i]);
}
+6 -65
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2014-2015, Tomasz Sowa
/*
* Copyright (c) 2014-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,70 +48,11 @@ namespace Ezc
class Blocks;
template<class StreamType>
void Cache(Functions<StreamType> & fun, Item::Function & function)
{
function.fun_cache = 0;
if( !function.name.empty() && function.arg < 0 )
{
typename Functions<StreamType>::Iterator i = fun.Find(function.name);
if( i != fun.End() )
function.fun_cache = &i->second;
}
for(size_t i=0 ; i < function.parameters.size() ; ++i)
Cache(fun, *function.parameters[i]);
}
template<class StreamType>
void Cache(Functions<StreamType> & fun, Item & item)
{
Cache(fun, item.function);
for(size_t i=0; i < item.item_tab.size() ; ++i)
Cache(fun, *item.item_tab[i]);
}
// void Cache(Functions & fun, Item::Function & function);
// void Cache(Functions & fun, Item & item);
void Cache(Blocks & blocks, Item & item);
template<class StreamType>
void Cache(Objects<StreamType> & objects, Item::Function & function)
{
function.base_obj = 0;
function.method_index = -1;
if( !function.name.empty() && function.arg < 0 )
{
typename Objects<StreamType>::Iterator i = objects.Find(function.name, function.method_index);
if( i != objects.End() )
function.base_obj = *i;
}
for(size_t i=0 ; i < function.parameters.size() ; ++i)
Cache(objects, *function.parameters[i]);
}
template<class StreamType>
void Cache(Objects<StreamType> & objects, Item & item)
{
Cache(objects, item.function);
for(size_t i=0; i < item.item_tab.size() ; ++i)
Cache(objects, *item.item_tab[i]);
}
void Cache(Objects & objects, Item::Function & function);
void Cache(Objects & objects, Item & item);
} // namespace Ezc
+52 -39
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2007-2023, Tomasz Sowa
/*
* Copyright (c) 2007-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,12 +33,14 @@
*/
#ifndef headerfile_ezc_funinfo
#define headerfile_ezc_funinfo
#ifndef headerfile_ezc_env
#define headerfile_ezc_env
#include <vector>
#include <map>
#include "item.h"
#include "val.h"
#include "textstream/stream.h"
@@ -48,27 +50,27 @@ 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;
// 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
// std::wstring str; // a string value
// bool res; // a boolean value
Var()
{
res = false;
is_function = false;
}
};
// Var()
// {
// res = false;
// is_function = false;
// }
// };
typedef std::map<std::wstring, Var> Vars;
//typedef std::map<std::wstring, Var> Vars;
@@ -140,30 +142,41 @@ struct Stack
};
// !! IMPROVE ME
// the name is bad
// may it should be called Env (environment) or FunEnv
template<class StreamType>
struct FunInfo
struct Env
{
// a result consists of a string and a boolean value
// output stream
StreamType & out;
// return value from a user's function (default false if not set directly by the function)
bool res;
pt::Stream & out; // OLD INTERFACE a reference to res.stream
// table of parameters
// the table can be empty
std::vector<Var> & params;
std::vector<Val> & params;
// output
Val & res;
//
// old interface but still available
//
// return value from a user's function (default false if not set directly by the function)
//bool res;
// old interface DEPRECATED
// the first parameter
// 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
const std::wstring & par;
//const std::wstring & par;
//
// an input stream used in [filter] statement
// if there is other statement than [filter] then this is an empty stream
const StreamType & in;
const pt::Stream & in;
// indicates that this function is from [for ...] statement
bool is_for;
@@ -207,12 +220,12 @@ struct FunInfo
// arguments: output_stream, table_of_parameters, the_first_parameter
FunInfo(StreamType & o,
std::vector<Var> & pars,
const std::wstring & first_par,
const StreamType & input_stream,
Stack & s,
const Item & item_) : out(o), params(pars), par(first_par), in(input_stream), stack(s), item(item_)
Env(pt::Stream & o,
std::vector<Val> & pars,
Val & res,
const pt::Stream & input_stream,
Stack & s,
const Item & item_) : out(o), params(pars), res(res), in(input_stream), stack(s), item(item_)
{
Clear();
}
@@ -220,7 +233,6 @@ struct FunInfo
void Clear()
{
res = false; // result is false by default
is_for = false;
is_if = false;
is_if_def = false;
@@ -230,6 +242,7 @@ struct FunInfo
iter = 0;
stack_tab = 0;
stack_index = 0;
res.clear();
}
/*
+109
View File
@@ -0,0 +1,109 @@
/*
* This file is a part of EZC -- Easy templating in C++ library
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2024, 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.
*
*/
#include "functions.h"
namespace Ezc
{
/*
void Functions::Insert(const char * key, UserFunction ufunction)
{
pt::utf8_to_wide(key, temp_key);
functions_tab[temp_key] = ufunction;
temp_key.clear();
}
void Functions::Insert(const std::string & key, UserFunction ufunction)
{
Insert(key.c_str(), ufunction);
}
void Functions::Insert(const wchar_t * key, UserFunction ufunction)
{
temp_key = key;
functions_tab[temp_key] = ufunction;
temp_key.clear();
}
void Functions::Insert(const std::wstring & key, UserFunction ufunction)
{
functions_tab[key] = ufunction;
}
typename Functions::Iterator Functions::Find(const std::wstring & key)
{
return functions_tab.find(key);
}
void Functions::Clear()
{
functions_tab.clear();
}
typename Functions::Iterator Functions::Begin()
{
return functions_tab.begin();
}
typename Functions::Iterator Functions::End()
{
return functions_tab.end();
}
size_t Functions::Size() const
{
return functions_tab.size();
}
*/
} // namespace Ezc
+6 -84
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2007-2015, Tomasz Sowa
/*
* Copyright (c) 2007-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,7 @@
#include <map>
#include "utf8/utf8.h"
#include "funinfo.h"
#include "env.h"
@@ -48,12 +48,12 @@ namespace Ezc
// functions or variables
template<class StreamType>
/*
class Functions
{
public:
typedef void (*UserFunction)(FunInfo<StreamType> &);
typedef void (*UserFunction)(Env &);
typedef std::map<std::wstring, UserFunction> FunctionsTable;
typedef typename FunctionsTable::iterator Iterator;
@@ -76,85 +76,7 @@ private:
std::wstring temp_key;
};
template<class StreamType>
void Functions<StreamType>::Insert(const char * key, UserFunction ufunction)
{
pt::utf8_to_wide(key, temp_key);
functions_tab[temp_key] = ufunction;
temp_key.clear();
}
template<class StreamType>
void Functions<StreamType>::Insert(const std::string & key, UserFunction ufunction)
{
Insert(key.c_str(), ufunction);
}
template<class StreamType>
void Functions<StreamType>::Insert(const wchar_t * key, UserFunction ufunction)
{
temp_key = key;
functions_tab[temp_key] = ufunction;
temp_key.clear();
}
template<class StreamType>
void Functions<StreamType>::Insert(const std::wstring & key, UserFunction ufunction)
{
functions_tab[key] = ufunction;
}
template<class StreamType>
typename Functions<StreamType>::Iterator Functions<StreamType>::Find(const std::wstring & key)
{
return functions_tab.find(key);
}
template<class StreamType>
void Functions<StreamType>::Clear()
{
functions_tab.clear();
}
template<class StreamType>
typename Functions<StreamType>::Iterator Functions<StreamType>::Begin()
{
return functions_tab.begin();
}
template<class StreamType>
typename Functions<StreamType>::Iterator Functions<StreamType>::End()
{
return functions_tab.end();
}
template<class StreamType>
size_t Functions<StreamType>::Size() const
{
return functions_tab.size();
}
*/
} // namespace Ezc
+1507 -917
View File
File diff suppressed because it is too large Load Diff
+52 -24
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2021, Tomasz Sowa
* Copyright (c) 2021-2025, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,6 @@
#ifdef EZC_HAS_MORM_LIBRARY
namespace Ezc
{
@@ -60,56 +59,71 @@ void Models::Clear()
}
void Models::Add(const std::wstring & name, morm::Model & model)
{
morm::Wrapper wrapper;
wrapper.model = &model;
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(&model);
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, morm::Model * model)
{
morm::Wrapper wrapper;
wrapper.model = model;
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(model);
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, pt::Space & space)
{
morm::Wrapper wrapper;
wrapper.space_wrapper = new morm::SpaceWrapper(&space);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::SpaceWrapper(&space));
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, pt::Space * space)
{
morm::Wrapper wrapper;
wrapper.space_wrapper = new morm::SpaceWrapper(space);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::SpaceWrapper(space));
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, pt::Date & date)
{
morm::Wrapper wrapper;
wrapper.date = &date;
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(&date);
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, pt::Date * date)
{
morm::Wrapper wrapper;
wrapper.date = date;
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(date);
models_map[name] = valcache;
}
morm::Wrapper * Models::Find(const std::wstring & name)
void Models::Add(const std::wstring & name, const std::wstring & value)
{
ValWrapper valcache;
valcache.val.set(value);
models_map[name] = valcache;
}
void Models::Add(const std::wstring & name, Val::UserFunction ufunction)
{
ValWrapper valcache;
valcache.val.set_pointer_to(ufunction);
models_map[name] = valcache;
}
ValWrapper * Models::Find(const std::wstring & name)
{
auto iterator = models_map.find(name);
@@ -122,13 +136,27 @@ morm::Wrapper * Models::Find(const std::wstring & name)
}
Val * Models::FindVal(const std::wstring & name)
{
auto iterator = models_map.find(name);
if( iterator != models_map.end() )
{
if( iterator->second.has_evaluated_val )
return &iterator->second.evaluated_val;
else
return &iterator->second.val;
}
return nullptr;
}
Models::ModelsMap & Models::GetMap()
{
return models_map;
}
}
+40 -29
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2021, Tomasz Sowa
* Copyright (c) 2021-2025, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,8 +37,7 @@
#ifdef EZC_HAS_MORM_LIBRARY
#include "wrapper.h"
#include "funinfo.h"
#include "valwrapper.h"
#include "space/space.h"
@@ -46,11 +45,16 @@ namespace Ezc
{
/*
* RENAMEME to a better name
* e.g.
* Vals, Vars, Variables, Values...
*/
class Models
{
public:
typedef std::map<std::wstring, morm::Wrapper> ModelsMap;
typedef std::map<std::wstring, ValWrapper> ModelsMap;
Models();
~Models();
@@ -64,71 +68,78 @@ public:
void Add(const std::wstring & name, pt::Date & space);
void Add(const std::wstring & name, pt::Date * space);
void Add(const std::wstring & name, const std::wstring & value);
void Add(const std::wstring & name, Val::UserFunction ufunction);
template<typename VectorType>
void Add(const std::wstring & name, std::vector<VectorType> & container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperVector<VectorType>(&container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperVector<VectorType>(&container));
models_map[name] = valcache;
}
template<typename VectorType>
void Add(const std::wstring & name, std::vector<VectorType> * container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperVector<VectorType>(container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperVector<VectorType>(container));
models_map[name] = valcache;
}
template<typename VectorType>
void Add(const std::wstring & name, std::vector<VectorType*> & container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperVectorPointer<VectorType>(&container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperVectorPointer<VectorType>(&container));
models_map[name] = valcache;
}
template<typename VectorType>
void Add(const std::wstring & name, std::vector<VectorType*> * container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperVectorPointer<VectorType>(container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperVectorPointer<VectorType>(container));
models_map[name] = valcache;
}
template<typename ListType>
void Add(const std::wstring & name, std::list<ListType> & container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperList<ListType>(&container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperList<ListType>(&container));
models_map[name] = valcache;
}
template<typename ListType>
void Add(const std::wstring & name, std::list<ListType> * container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperList<ListType>(container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperList<ListType>(container));
models_map[name] = valcache;
}
template<typename ListType>
void Add(const std::wstring & name, std::list<ListType*> & container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperListPointer<ListType>(&container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperListPointer<ListType>(&container));
models_map[name] = valcache;
}
template<typename ListType>
void Add(const std::wstring & name, std::list<ListType*> * container)
{
morm::Wrapper wrapper;
wrapper.model_container_wrapper = new morm::ModelWrapperListPointer<ListType>(container);
models_map[name] = wrapper;
ValWrapper valcache;
valcache.val.set_pointer_to(new morm::ModelWrapperListPointer<ListType>(container));
models_map[name] = valcache;
}
morm::Wrapper * Find(const std::wstring & name);
ValWrapper * Find(const std::wstring & name);
Val * FindVal(const std::wstring & name);
ModelsMap & GetMap();
void Clear();
+104
View File
@@ -0,0 +1,104 @@
/*
* This file is a part of EZC -- Easy templating in C++ library
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2024, 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.
*
*/
#include "objects.h"
namespace Ezc
{
typename Objects::Iterator Objects::Find(const std::wstring & key, int & method_index)
{
Iterator i = obj_tab.begin();
method_index = -1;
for( ; i != obj_tab.end() ; ++i)
{
int index = (*i)->FindFun(key);
if( index != -1 )
{
method_index = index;
return i;
}
}
return obj_tab.end();
}
void Objects::Insert(BaseObj * base_fun)
{
obj_tab.push_back(base_fun);
}
void Objects::Insert(BaseObj & base_fun)
{
obj_tab.push_back(&base_fun);
}
typename Objects::Iterator Objects::Begin()
{
return obj_tab.begin();
}
typename Objects::Iterator Objects::End()
{
return obj_tab.end();
}
size_t Objects::Size() const
{
return obj_tab.size();
}
void Objects::Clear()
{
obj_tab.clear();
}
} // namespace Ezc
+6 -74
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2015, Tomasz Sowa
* Copyright (c) 2015-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -38,6 +38,7 @@
#include <vector>
#include <string>
#include "utf8/utf8.h"
#include "env.h"
@@ -46,7 +47,6 @@ namespace Ezc
{
template<class StreamType>
class BaseObj
{
public:
@@ -69,7 +69,7 @@ public:
/*
*
*/
virtual void CallFun(int fun_index, FunInfo<StreamType> &) = 0;
virtual void CallFun(int fun_index, Env &) = 0;
/*
@@ -203,16 +203,15 @@ private:
template<class StreamType>
class Objects
{
public:
typedef std::vector<BaseObj<StreamType> * > ObjectsTable;
typedef std::vector<BaseObj*> ObjectsTable;
typedef typename ObjectsTable::iterator Iterator;
void Insert(BaseObj<StreamType> * base_fun);
void Insert(BaseObj<StreamType> & base_fun);
void Insert(BaseObj * base_fun);
void Insert(BaseObj & base_fun);
Iterator Begin();
Iterator End();
@@ -229,73 +228,6 @@ private:
template<class StreamType>
typename Objects<StreamType>::Iterator Objects<StreamType>::Find(const std::wstring & key, int & method_index)
{
Iterator i = obj_tab.begin();
method_index = -1;
for( ; i != obj_tab.end() ; ++i)
{
int index = (*i)->FindFun(key);
if( index != -1 )
{
method_index = index;
return i;
}
}
return obj_tab.end();
}
template<class StreamType>
void Objects<StreamType>::Insert(BaseObj<StreamType> * base_fun)
{
obj_tab.push_back(base_fun);
}
template<class StreamType>
void Objects<StreamType>::Insert(BaseObj<StreamType> & base_fun)
{
obj_tab.push_back(&base_fun);
}
template<class StreamType>
typename Objects<StreamType>::Iterator Objects<StreamType>::Begin()
{
return obj_tab.begin();
}
template<class StreamType>
typename Objects<StreamType>::Iterator Objects<StreamType>::End()
{
return obj_tab.end();
}
template<class StreamType>
size_t Objects<StreamType>::Size() const
{
return obj_tab.size();
}
template<class StreamType>
void Objects<StreamType>::Clear()
{
obj_tab.clear();
}
} // namespace Ezc
+25 -31
View File
@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2015-2021, Tomasz Sowa
* Copyright (c) 2015-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,6 +35,7 @@
#ifndef headerfile_ezc_outstreams
#define headerfile_ezc_outstreams
#include "textstream/stream.h"
#include <string>
#include <vector>
#include <map>
@@ -44,18 +45,17 @@ namespace Ezc
{
template<class StreamType, bool is_pikotools_stream = false>
class OutStreams
{
public:
typedef std::map<std::wstring, StreamType*> StreamsMap;
typedef std::vector<StreamType*> StreamsTab;
typedef std::map<std::wstring, pt::Stream*> StreamsMap;
typedef std::vector<pt::Stream*> StreamsTab;
StreamsMap streams_map;
StreamsTab streams_tab;
void ResizeTab(size_t len);
void ResizeTab(pt::Stream & stream_type, size_t len);
void ClearMap();
void ClearTab();
@@ -68,40 +68,35 @@ public:
};
template<class StreamType, bool is_pikotools_stream>
OutStreams<StreamType, is_pikotools_stream>::~OutStreams()
OutStreams::~OutStreams()
{
ClearTab();
}
template<class StreamType, bool is_pikotools_stream>
OutStreams<StreamType, is_pikotools_stream>::OutStreams()
OutStreams::OutStreams()
{
}
template<class StreamType, bool is_pikotools_stream>
OutStreams<StreamType, is_pikotools_stream>::OutStreams(const OutStreams<StreamType, is_pikotools_stream> & o)
OutStreams::OutStreams(const OutStreams & o)
{
// we do not copy streams but creating new ones
ResizeTab(o.streams_tab.size());
//ResizeTab(o.streams_tab.size());
}
template<class StreamType, bool is_pikotools_stream>
OutStreams<StreamType, is_pikotools_stream> & OutStreams<StreamType, is_pikotools_stream>::operator=(const OutStreams<StreamType, is_pikotools_stream> & o)
OutStreams & OutStreams::operator=(const OutStreams & o)
{
// we do not copy streams but creating new ones
streams_map.clear();
ResizeTab(o.streams_tab.size());
//ResizeTab(o.streams_tab.size());
return *this;
}
template<class StreamType, bool is_pikotools_stream>
void OutStreams<StreamType, is_pikotools_stream>::ClearTab()
void OutStreams::ClearTab()
{
for(size_t i=0 ; i<streams_tab.size() ; ++i)
delete streams_tab[i];
@@ -111,8 +106,7 @@ void OutStreams<StreamType, is_pikotools_stream>::ClearTab()
}
template<class StreamType, bool is_pikotools_stream>
void OutStreams<StreamType, is_pikotools_stream>::ResizeTab(size_t len)
void OutStreams::ResizeTab(pt::Stream & stream_type, size_t len)
{
if( streams_tab.size() != len )
{
@@ -122,7 +116,7 @@ void OutStreams<StreamType, is_pikotools_stream>::ResizeTab(size_t len)
streams_tab.resize(len);
for( ; i<streams_tab.size() ; ++i)
streams_tab[i] = new StreamType();
streams_tab[i] = stream_type.new_empty();
}
else
{
@@ -137,23 +131,23 @@ void OutStreams<StreamType, is_pikotools_stream>::ResizeTab(size_t len)
}
template<class StreamType, bool is_pikotools_stream>
void OutStreams<StreamType, is_pikotools_stream>::ClearMap()
void OutStreams::ClearMap()
{
typename StreamsMap::iterator i;
for(i=streams_map.begin() ; i != streams_map.end() ; ++i)
{
StreamType & str = *(i->second);
pt::Stream & str = *(i->second);
str.clear();
if constexpr(is_pikotools_stream)
{
str.clear();
}
else
{
str.str(L"");
}
// if constexpr(is_pikotools_stream)
// {
// str.clear();
// }
// else
// {
// str.str(L"");
// }
}
streams_map.clear();
+13 -6
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2007-2012, Tomasz Sowa
/*
* Copyright (c) 2007-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,7 +33,6 @@
*/
#include "pattern.h"
#include "utf8/utf8.h"
namespace Ezc
@@ -46,15 +45,12 @@ Pattern::Pattern()
}
void Pattern::Clear()
{
item_root.Clear();
}
void Pattern::CacheBlocks(Blocks & blocks)
{
Cache(blocks, item_root);
@@ -67,6 +63,17 @@ void Pattern::ClearCache()
}
// void Pattern::CacheFunctions(Functions & fun)
// {
// Cache(fun, item_root);
// }
void Pattern::CacheObjects(Objects & obj)
{
Cache(obj, item_root);
}
} // namespace Ezc
+4 -21
View File
@@ -4,8 +4,8 @@
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2007-2015, Tomasz Sowa
/*
* Copyright (c) 2007-2024, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,6 @@
#ifndef headerfile_ezc_pattern
#define headerfile_ezc_pattern
#include <string>
#include "item.h"
#include "cache.h"
#include "blocks.h"
@@ -56,9 +55,9 @@ public:
void Clear();
template<class StreamType> void CacheFunctions(Functions<StreamType> & fun);
//void CacheFunctions(Functions & fun);
void CacheBlocks(Blocks & blocks);
template<class StreamType> void CacheObjects(Objects<StreamType> & obj);
void CacheObjects(Objects & obj);
void ClearCache();
@@ -69,22 +68,6 @@ public:
template<class StreamType>
void Pattern::CacheFunctions(Functions<StreamType> & fun)
{
Cache(fun, item_root);
}
template<class StreamType>
void Pattern::CacheObjects(Objects<StreamType> & obj)
{
Cache(obj, item_root);
}
} // namespace Ezc
+1366
View File
File diff suppressed because it is too large Load Diff
+394
View File
@@ -0,0 +1,394 @@
/*
* This file is a part of EZC -- Easy templating in C++ library
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2024, 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_ezc_val
#define headerfile_ezc_val
#include "spacewrapper.h"
#include "date/date.h"
#include "item.h"
#include "modelcontainerwrapper.h"
#include "textstream/textstream.h"
namespace morm
{
class Model;
}
namespace Ezc
{
struct Env;
/*
*/
class Val
{
public:
using UserFunction = void (*)(Env &);
#ifdef EZC_HAS_MORM_LIBRARY
using ModelMethod1 = void (morm::Model::*)(Env &);
using ModelMethod3 = bool (morm::Model::*)();
using ModelMethod4 = bool (morm::Model::*)() const;
#endif
enum Type
{
TYPE_VOID,
TYPE_SPACE_LOCAL,
TYPE_STREAM,
TYPE_FUNCTION,
TYPE_DATE,
#ifdef EZC_HAS_MORM_LIBRARY
TYPE_MODEL,
TYPE_MODEL_CONTAINER_WRAPPER,
TYPE_MODEL_METHOD,
#endif
TYPE_SPACE,
TYPE_ITEM_BLOCK,
TYPE_CHAR,
TYPE_WCHAR, //
TYPE_SHORT,
TYPE_INT,
TYPE_LONG,
TYPE_LONG_LONG,
TYPE_UNSIGNED_CHAR,
TYPE_UNSIGNED_SHORT,
TYPE_UNSIGNED_INT,
TYPE_UNSIGNED_LONG,
TYPE_UNSIGNED_LONG_LONG,
TYPE_FLOAT,
TYPE_DOUBLE,
TYPE_LONG_DOUBLE,
TYPE_STRING,
TYPE_WSTRING,
};
Val();
Val(pt::Stream * output_stream);
Val(const Val & val);
Val & operator=(const Val & val);
~Val();
// IMPROVEME add move cctor and operator=
void set_output_stream(pt::Stream * output_stream);
void set_output_stream(pt::Stream & output_stream);
bool has_object();
bool has_function();
#ifdef EZC_HAS_MORM_LIBRARY
bool has_method();
bool has_model_object();
#endif
bool has_pod_type();
//bool has_space_object();
void clear();
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);
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);
void set_pointer_to(pt::Stream * str);
void set_pointer_to(UserFunction user_function);
#ifdef EZC_HAS_MORM_LIBRARY
void set_pointer_to(morm::Model * model, ModelMethod1 model_method1);
void set_pointer_to(morm::Model * model, ModelMethod3 model_method3);
void set_pointer_to(morm::Model * model, ModelMethod4 model_method4);
#endif
void set_pointer_to(pt::Date * date);
void set_pointer_to(morm::Model * model);
void set_pointer_to(morm::ModelContainerWrapper * model_container_wrapper);
template<typename ModelType>
void set_pointer_to(std::vector<ModelType> * model_container);
template<typename ModelType>
void set_pointer_to(std::list<ModelType> * model_container);
template<typename ModelType>
void set_pointer_to(std::vector<ModelType*> * model_container);
template<typename ModelType>
void set_pointer_to(std::list<ModelType*> * model_container);
void set_pointer_to(morm::SpaceWrapper * space_wrapper);
void set_pointer_to(pt::Space * space, bool create_wrapper = true);
//void set(Val & val);
void set_pointer_to(Item * item_block);
void set_pointer_to(bool * val);
void set_pointer_to(char * val);
void set_pointer_to(wchar_t * val);
void set_pointer_to(short * val);
void set_pointer_to(int * val);
void set_pointer_to(long * val);
void set_pointer_to(long long * val);
void set_pointer_to(unsigned char * val);
void set_pointer_to(unsigned short * val);
void set_pointer_to(unsigned int * val);
void set_pointer_to(unsigned long * val);
void set_pointer_to(unsigned long long * val);
void set_pointer_to(float * val);
void set_pointer_to(double * val);
void set_pointer_to(long double * val);
void set_pointer_to(std::string * val);
void set_pointer_to(std::wstring * val);
// 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::Stream & str);
Val & operator<<(const char * str);
Val & operator<<(const wchar_t * str);
Val & operator<<(const std::string & str);
Val & operator<<(const std::wstring & str);
Val & operator<<(char val);
Val & operator<<(unsigned char val);
Val & operator<<(wchar_t val);
Val & operator<<(bool val);
Val & operator<<(short val);
Val & operator<<(int val);
Val & operator<<(long val);
Val & operator<<(long long val);
Val & operator<<(unsigned short val);
Val & operator<<(unsigned int val);
Val & operator<<(unsigned long val);
Val & operator<<(unsigned long long val);
Val & operator<<(float val);
Val & operator<<(double val);
Val & operator<<(long double val);
Val & operator<<(const pt::Stream & str);
Val & operator=(bool res);
void put_pod_type_to_stream();
void allow_to_cache(bool allow_to_cache);
bool is_allowed_to_cache();
Type type;
pt::Space space_local;
void * pointer;
#ifdef EZC_HAS_MORM_LIBRARY
ModelMethod1 model_method1;
ModelMethod3 model_method3;
ModelMethod4 model_method4;
#endif
// used when pointer is pointing to a pt::Space
// but can be null
morm::SpaceWrapper * space_wrapper;
size_t space_table_index;
bool allow_to_cache_value;
// UserFunction user_function;
// // Wrapper
// morm::Model * model;
// morm::ModelContainerWrapper * model_container_wrapper;
// pt::Date * date;
// morm::SpaceWrapper * space_wrapper;
// //
// pt::Space * space;
// pt::Stream * stream;
// Item * item_block;
// output stream
pt::Stream * output_stream;
bool is_equal_string(const wchar_t * str) const;
private:
void initialize_empty();
void copy(const Val & val);
void increment_model_container_wrapper_ref();
void increment_space_wrapper_ref();
void clear_model_container_wrapper();
void clear_space_wrapper();
// 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_space_equal_string(const pt::Space & space, const wchar_t * str) const;
bool is_stream_equal_string(const pt::Stream & stream, const wchar_t * str) const;
bool to_bool_stream() const;
bool to_bool_space() const;
bool to_bool_model_container_wrapper() const;
void serialize_stream_to(pt::Stream & str);
void serialize_date_to(pt::Stream & str);
void serialize_model_to(pt::Stream & str);
void serialize_model_container_wrapper_to(pt::Stream & str);
void serialize_space_to(pt::Stream & str);
template<typename PODType>
void serialize_pod_type_to(pt::Stream & str)
{
PODType * val = reinterpret_cast<PODType*>(pointer);
str << *val;
}
/*
* 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
};
template<typename ModelType>
void Val::set_pointer_to(std::vector<ModelType> * model_container)
{
clear();
type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperVector<ModelType>(model_container);
this->allow_to_cache_value = true;
}
template<typename ModelType>
void Val::set_pointer_to(std::list<ModelType> * model_container)
{
clear();
type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperList<ModelType>(model_container);
this->allow_to_cache_value = true;
}
template<typename ModelType>
void Val::set_pointer_to(std::vector<ModelType*> * model_container)
{
clear();
type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperVectorPointer<ModelType>(model_container);
this->allow_to_cache_value = true;
}
template<typename ModelType>
void Val::set_pointer_to(std::list<ModelType*> * model_container)
{
clear();
type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperListPointer<ModelType>(model_container);
this->allow_to_cache_value = true;
}
typedef std::map<std::wstring, Val> Vals;
} // namespace Ezc
#endif
+142
View File
@@ -0,0 +1,142 @@
/*
* This file is a part of EZC -- Easy templating in C++ library
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2025, 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.
*
*/
#include "valwrapper.h"
namespace Ezc
{
ValWrapper::ValWrapper()
{
has_evaluated_val = false;
evaluated_str = nullptr;
}
ValWrapper::ValWrapper(const ValWrapper & valcache)
{
operator=(valcache);
}
ValWrapper & ValWrapper::operator=(const ValWrapper & valcache)
{
val = valcache.val;
has_evaluated_val = valcache.has_evaluated_val;
evaluated_val = valcache.evaluated_val;
if( valcache.evaluated_str )
{
evaluated_str = valcache.evaluated_str->new_empty();
if( !valcache.evaluated_str->empty() )
{
evaluated_str->escape_input(false);
*evaluated_str << *valcache.evaluated_str;
}
}
else
{
evaluated_str = nullptr;
}
return *this;
}
void ValWrapper::clear()
{
val.clear();
clear_evaluated_value();
clear_childs();
}
void ValWrapper::clear_evaluated_value()
{
has_evaluated_val = false;
if( evaluated_str )
{
delete evaluated_str;
}
evaluated_str = nullptr;
evaluated_val.clear();
}
void ValWrapper::clear_childs()
{
childs_map.clear();
}
ValWrapper * ValWrapper::add_child(const std::wstring & child_name, const ValWrapper & val)
{
ValWrapper & v = childs_map[child_name];
v.clear();
v = val;
return &v;
}
ValWrapper * ValWrapper::add_child(const std::wstring & child_name, const Val & val)
{
ValWrapper & v = childs_map[child_name];
v.clear();
v.val = val;
return &v;
}
ValWrapper * ValWrapper::find_child(const std::wstring & child_name)
{
auto i = childs_map.find(child_name);
if( i != childs_map.end() )
{
return &i->second;
}
return nullptr;
}
} // namespace Ezc
+83
View File
@@ -0,0 +1,83 @@
/*
* This file is a part of EZC -- Easy templating in C++ library
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2025, 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_ezc_valcache
#define headerfile_ezc_valcache
#include "val.h"
namespace Ezc
{
//ValWrapper
class ValWrapper
{
public:
ValWrapper();
ValWrapper(const ValWrapper &);
ValWrapper & operator=(const ValWrapper &);
Val val;
bool has_evaluated_val;
Val evaluated_val;
pt::Stream * evaluated_str; // can be null
void clear();
void clear_evaluated_value();
void clear_childs();
ValWrapper * add_child(const std::wstring & child_name, const ValWrapper & val);
ValWrapper * add_child(const std::wstring & child_name, const Val & val);
ValWrapper * find_child(const std::wstring & child_name);
private:
std::map<std::wstring, ValWrapper> childs_map;
};
} // namespace Ezc
#endif