added: possibility to define a block
changed: in Functions Functions are only for user-defined functions now (before they could remember a string variable too) added: class Vars for variables a variable can be a string or an alias to an other function or block added: now we can have nested functions calls e.g.: [function1 [function2]] in the above example an output (stream) from function2 will be passed as the first argument to funcion1 (will be passed as a string) removed: UTF8() method from PatternParser now it is treated that when we have only std::string (or char*) that this is an UTF-8 string git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@970 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
146
src/functions.h
146
src/functions.h
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007-2012, Tomasz Sowa
|
||||
* Copyright (c) 2007-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -39,8 +39,9 @@
|
||||
#define headerfile_ezc_functions
|
||||
|
||||
#include <map>
|
||||
#include "utf8/utf8.h"
|
||||
#include "funinfo.h"
|
||||
#include "stringconv.h"
|
||||
|
||||
|
||||
|
||||
namespace Ezc
|
||||
@@ -55,95 +56,43 @@ class Functions
|
||||
public:
|
||||
|
||||
typedef void (*UserFunction)(FunInfo<StreamType> &);
|
||||
enum Type { function, variable };
|
||||
|
||||
struct Function
|
||||
{
|
||||
Function();
|
||||
|
||||
Type type;
|
||||
UserFunction user_function; // used when type is 'function'
|
||||
std::wstring variable; // used when type is 'variable'
|
||||
};
|
||||
|
||||
typedef std::map<std::wstring, Function> FunctionsTable;
|
||||
typedef std::map<std::wstring, UserFunction> FunctionsTable;
|
||||
typedef typename FunctionsTable::iterator Iterator;
|
||||
|
||||
|
||||
void Insert(const char * key, UserFunction ufunction); // inserting a function
|
||||
void Insert(const char * key, const char * var); // inserting a variable
|
||||
void Insert(const char * key, const std::string & var); // inserting a variable
|
||||
void Insert(const std::string & key, UserFunction ufunction); // inserting a function
|
||||
void Insert(const std::string & key, const char * var); // inserting a variable
|
||||
void Insert(const std::string & key, const std::string & var); // inserting a variable
|
||||
void Insert(const char * key, UserFunction ufunction);
|
||||
void Insert(const std::string & key, UserFunction ufunction);
|
||||
void Insert(const wchar_t * key, UserFunction ufunction);
|
||||
void Insert(const std::wstring & key, UserFunction ufunction);
|
||||
void Insert(const std::wstring & key, const wchar_t * var);
|
||||
void Insert(const std::wstring & key, const std::wstring & var);
|
||||
|
||||
bool Find(const std::string & key, Function ** fun);
|
||||
bool Find(const std::wstring & key, Function ** fun);
|
||||
typename Iterator Find(const std::wstring & key);
|
||||
|
||||
Iterator Begin();
|
||||
Iterator End();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
size_t Size() const;
|
||||
void Clear();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
FunctionsTable functions_tab;
|
||||
std::wstring temp_key;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
Functions<StreamType>::Function::Function()
|
||||
{
|
||||
type = Functions::variable;
|
||||
user_function = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, UserFunction ufunction)
|
||||
{
|
||||
Function f;
|
||||
f.type = function;
|
||||
f.user_function = ufunction;
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
PT::UTF8ToWide(key, temp_key);
|
||||
functions_tab[temp_key] = ufunction;
|
||||
temp_key.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, const char * var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
AssignString(var, f.variable);
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const char * key, const std::string & var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
AssignString(var, f.variable);
|
||||
|
||||
AssignString(key, temp_key);
|
||||
functions_tab[temp_key] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, UserFunction ufunction)
|
||||
{
|
||||
@@ -152,54 +101,18 @@ void Functions<StreamType>::Insert(const std::string & key, UserFunction ufuncti
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, const char * var)
|
||||
void Functions<StreamType>::Insert(const wchar_t * key, UserFunction ufunction)
|
||||
{
|
||||
Insert(key.c_str(), var);
|
||||
temp_key = key;
|
||||
functions_tab[temp_key] = ufunction;
|
||||
temp_key.clear();
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::string & key, const std::string & var)
|
||||
{
|
||||
Insert(key.c_str(), var);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, UserFunction ufunction)
|
||||
{
|
||||
Function f;
|
||||
f.type = function;
|
||||
f.user_function = ufunction;
|
||||
|
||||
functions_tab[key] = f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, const wchar_t * var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
f.variable = var;
|
||||
|
||||
functions_tab[key] = f;
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
void Functions<StreamType>::Insert(const std::wstring & key, const std::wstring & var)
|
||||
{
|
||||
Function f;
|
||||
f.type = variable;
|
||||
f.variable = var;
|
||||
|
||||
functions_tab[key] = f;
|
||||
functions_tab[key] = ufunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,25 +120,12 @@ void Functions<StreamType>::Insert(const std::wstring & key, const std::wstring
|
||||
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Functions<StreamType>::Find(const std::string & key, Function ** fun)
|
||||
{
|
||||
AssignString(key, temp_key);
|
||||
return Find(temp_key, fun);
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType>
|
||||
bool Functions<StreamType>::Find(const std::wstring & key, Function ** fun)
|
||||
typename Functions<StreamType>::Iterator Functions<StreamType>::Find(const std::wstring & key)
|
||||
{
|
||||
typename FunctionsTable::iterator i = functions_tab.find( key );
|
||||
|
||||
if( i == functions_tab.end() )
|
||||
return false;
|
||||
|
||||
*fun = &(i->second);
|
||||
|
||||
return true;
|
||||
return functions_tab.find(key);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user