2010-11-22 02:23:32 +01:00
|
|
|
/*
|
2014-10-17 23:48:11 +02:00
|
|
|
* This file is a part of EZC -- Easy templating in C++ library
|
|
|
|
* and is distributed under the BSD 3-Clause licence.
|
2010-11-22 02:23:32 +01:00
|
|
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2021-08-29 20:55:15 +02:00
|
|
|
* Copyright (c) 2007-2021, Tomasz Sowa
|
2010-11-22 02:23:32 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-08-29 20:55:15 +02:00
|
|
|
#ifndef headerfile_ezc_env
|
|
|
|
#define headerfile_ezc_env
|
2010-11-22 02:23:32 +01:00
|
|
|
|
|
|
|
#include <vector>
|
2021-05-23 10:02:51 +02:00
|
|
|
#include <map>
|
2016-04-04 17:53:11 +02:00
|
|
|
#include "item.h"
|
2021-08-29 20:35:15 +02:00
|
|
|
#include "modelcontainerwrapper.h"
|
|
|
|
#include "var.h"
|
2010-11-22 02:23:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ezc
|
|
|
|
{
|
|
|
|
|
2014-10-28 18:46:24 +01:00
|
|
|
|
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
//typedef std::map<std::wstring, Var<StreamType>> Vars;
|
2021-05-23 10:02:51 +02:00
|
|
|
|
|
|
|
|
2012-02-27 18:39:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
a base class for your own function data class
|
|
|
|
*/
|
2012-02-24 13:04:36 +01:00
|
|
|
struct FunData
|
|
|
|
{
|
|
|
|
FunData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~FunData()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-11-22 02:23:32 +01:00
|
|
|
|
2012-02-27 18:39:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
a generator's stack item
|
|
|
|
each statement ([if ...] [for ...] [normal_funcion]) have its own stack item
|
2014-10-19 07:42:25 +02:00
|
|
|
iter - is used only in [for...] - it is the current iteration (start from zero)
|
|
|
|
for other statements it is always zero
|
|
|
|
fun_data - by default this is null pointer, you can set it to a pointer
|
|
|
|
to an object derived from FunData
|
|
|
|
(this have sense only in [for...] statement because in other statements
|
|
|
|
this object would be immediately removed)
|
2016-03-23 16:22:59 +01:00
|
|
|
auto_remove - when true it means that object pointing by fun_data and for_name should be automatically
|
|
|
|
removed -- (by using delete fun_data and delete for_name)
|
2014-10-19 07:42:25 +02:00
|
|
|
is_for - true if the item is from [for] statement
|
|
|
|
currently used only in [if-index]
|
|
|
|
(it has to look for the last [for] item)
|
2012-02-27 18:39:46 +01:00
|
|
|
*/
|
|
|
|
struct Stack
|
|
|
|
{
|
|
|
|
size_t iter;
|
|
|
|
FunData * fun_data;
|
2014-10-19 07:42:25 +02:00
|
|
|
bool auto_remove;
|
2016-03-23 16:22:59 +01:00
|
|
|
bool is_for;
|
2016-04-04 17:53:11 +02:00
|
|
|
const Item * item;
|
2016-03-23 16:22:59 +01:00
|
|
|
|
2012-02-27 18:39:46 +01:00
|
|
|
|
|
|
|
Stack()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2014-10-17 23:36:55 +02:00
|
|
|
~Stack()
|
|
|
|
{
|
2016-03-23 16:22:59 +01:00
|
|
|
if( auto_remove )
|
2014-10-17 23:36:55 +02:00
|
|
|
{
|
2016-03-23 16:22:59 +01:00
|
|
|
if( fun_data )
|
|
|
|
{
|
|
|
|
delete fun_data;
|
|
|
|
fun_data = 0;
|
|
|
|
}
|
2014-10-17 23:36:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 18:39:46 +01:00
|
|
|
void Clear()
|
|
|
|
{
|
2014-10-19 07:42:25 +02:00
|
|
|
iter = 0;
|
|
|
|
fun_data = 0;
|
|
|
|
auto_remove = true;
|
|
|
|
is_for = false;
|
2016-04-04 17:53:11 +02:00
|
|
|
item = 0;
|
2012-02-27 18:39:46 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-11-22 02:23:32 +01:00
|
|
|
template<class StreamType>
|
2021-08-29 20:55:15 +02:00
|
|
|
struct Env
|
2010-11-22 02:23:32 +01:00
|
|
|
{
|
2021-10-20 08:23:45 +02:00
|
|
|
// an alias to res.stream
|
2010-11-22 02:23:32 +01:00
|
|
|
StreamType & out;
|
2021-08-29 20:35:15 +02:00
|
|
|
|
|
|
|
// result
|
2021-10-20 08:23:45 +02:00
|
|
|
Var<StreamType> & res;
|
2010-11-22 02:23:32 +01:00
|
|
|
|
|
|
|
// table of parameters
|
2011-01-15 00:59:30 +01:00
|
|
|
// the table can be empty
|
2021-10-20 08:23:45 +02:00
|
|
|
std::vector<Var<StreamType>> & params;
|
2010-11-22 02:23:32 +01:00
|
|
|
|
|
|
|
// the first parameter
|
2014-10-17 23:36:55 +02:00
|
|
|
// you can always use it even if there are not any parameters (params is empty)
|
2010-11-22 02:23:32 +01:00
|
|
|
// in such a way the reference points to an empty string
|
2021-08-29 20:35:15 +02:00
|
|
|
//const std::wstring & par;
|
2010-11-22 02:23:32 +01:00
|
|
|
|
2011-01-26 13:42:49 +01:00
|
|
|
// an input stream used in [filter] statement
|
2021-11-06 19:07:39 +01:00
|
|
|
// and when methods/functions are chained
|
|
|
|
Var<StreamType> & in;
|
2011-01-26 13:42:49 +01:00
|
|
|
|
2012-01-17 23:57:06 +01:00
|
|
|
// indicates that this function is from [for ...] statement
|
|
|
|
bool is_for;
|
|
|
|
|
2012-02-24 13:04:36 +01:00
|
|
|
// indicates that this function is from [if ...] statement
|
|
|
|
bool is_if;
|
|
|
|
|
2021-07-02 20:23:20 +02:00
|
|
|
// indicates that this function is from [if-def ...] statement
|
|
|
|
bool is_if_def;
|
|
|
|
|
|
|
|
// indicates that this function is from [if-not-def ...] statement
|
|
|
|
bool is_if_not_def;
|
|
|
|
|
2012-02-24 13:04:36 +01:00
|
|
|
// indicates that this funcion is a normal statement e.g.: [funcion_name]
|
|
|
|
bool is_normal;
|
|
|
|
|
|
|
|
// indicates that this function is from a filter statement [filter ...]
|
|
|
|
bool is_filter;
|
|
|
|
|
2014-11-02 18:26:56 +01:00
|
|
|
// a pointer to the stack
|
|
|
|
Stack * stack_tab;
|
|
|
|
|
|
|
|
// current stack item
|
|
|
|
size_t stack_index;
|
|
|
|
|
2014-10-17 23:36:55 +02:00
|
|
|
// a stack's item from generator's stack
|
2012-02-27 18:39:46 +01:00
|
|
|
// each function has a new stack item
|
|
|
|
// on this stack you have iter (description below) and fun_data pointer
|
|
|
|
// you can assign to it your own object derived from FunData
|
2014-11-02 18:26:56 +01:00
|
|
|
// 'stack' is a reference to stack_tab[stack_index]
|
2014-10-17 23:36:55 +02:00
|
|
|
Stack & stack;
|
2012-02-24 13:04:36 +01:00
|
|
|
|
2014-10-17 23:36:55 +02:00
|
|
|
// the same as stack.iter (this is mainly for backward compatibility)
|
2012-02-24 13:04:36 +01:00
|
|
|
// it indicates the number of a current iteration for the [for] statement (the first iteration is 0)
|
|
|
|
// for other statements than [for] this is always zero
|
|
|
|
size_t iter;
|
2012-01-17 23:57:06 +01:00
|
|
|
|
2016-04-04 17:53:11 +02:00
|
|
|
//
|
|
|
|
const Item & item;
|
|
|
|
|
|
|
|
|
2010-11-22 02:23:32 +01:00
|
|
|
|
2021-10-20 08:23:45 +02:00
|
|
|
Env(Var<StreamType> & result,
|
|
|
|
std::vector<Var<StreamType>> & pars,
|
2021-11-06 19:07:39 +01:00
|
|
|
Var<StreamType> & input_stream,
|
2021-08-29 20:55:15 +02:00
|
|
|
Stack & s,
|
|
|
|
const Item & item_) : out(result.stream), res(result), params(pars), in(input_stream), stack(s), item(item_)
|
2010-11-22 02:23:32 +01:00
|
|
|
{
|
2021-08-29 20:55:15 +02:00
|
|
|
clear();
|
2010-11-22 02:23:32 +01:00
|
|
|
}
|
|
|
|
|
2012-02-24 13:04:36 +01:00
|
|
|
|
2021-08-29 20:55:15 +02:00
|
|
|
void clear()
|
2010-11-22 02:23:32 +01:00
|
|
|
{
|
2012-02-24 13:04:36 +01:00
|
|
|
is_for = false;
|
|
|
|
is_if = false;
|
2021-07-02 20:23:20 +02:00
|
|
|
is_if_def = false;
|
|
|
|
is_if_not_def = false;
|
2012-02-24 13:04:36 +01:00
|
|
|
is_normal = false;
|
|
|
|
is_filter = false;
|
|
|
|
iter = 0;
|
2021-08-29 20:35:15 +02:00
|
|
|
stack_tab = nullptr;
|
2014-11-02 18:26:56 +01:00
|
|
|
stack_index = 0;
|
2010-11-22 02:23:32 +01:00
|
|
|
}
|
2016-03-23 16:22:59 +01:00
|
|
|
|
2016-04-04 17:53:11 +02:00
|
|
|
|
2010-11-22 02:23:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Ezc
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|