diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | e9ae80694875f869892f13f4fcaf1170a00dea41 (patch) | |
tree | aa2f8d8a217e2d376224c8d46b7397b68d35de2d /kommander/widget/function.cpp | |
download | tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.tar.gz tdewebdev-e9ae80694875f869892f13f4fcaf1170a00dea41.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdewebdev@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kommander/widget/function.cpp')
-rw-r--r-- | kommander/widget/function.cpp | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/kommander/widget/function.cpp b/kommander/widget/function.cpp new file mode 100644 index 00000000..3bcd21cd --- /dev/null +++ b/kommander/widget/function.cpp @@ -0,0 +1,135 @@ +/*************************************************************************** + function.cpp - Functions for internal parser + ------------------- + copyright : (C) 2004 Michal Rudolf <mrudolf@kdewebdwev.org> + + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software{} you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation{} either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "function.h" + +using namespace Parse; + +Function::Function() : m_function(0), m_minArgs(0), m_maxArgs(0) +{ +} + +Function::Function(FunctionPointer fp, ValueType value, const TypeList& params, uint min, uint max) + : m_params(params) +{ + m_function = fp; + m_returnValue = value; + m_minArgs = min <= m_params.count() ? min : m_params.count(); + m_maxArgs = max >= m_params.count() ? max : m_params.count(); +} + +Function::Function(FunctionPointer fp, ValueType value, ValueType param1, uint min, uint max) +{ + m_function = fp; + m_returnValue = value; + m_params.append(param1); + m_minArgs = min <= 1 ? min : 1; + m_maxArgs = max >= 1 ? max : 1; +} + +Function::Function(FunctionPointer fp, ValueType value, ValueType param1, ValueType param2, uint min , + uint max) +{ + m_function = fp; + m_returnValue = value; + m_params.append(param1); + m_params.append(param2); + m_minArgs = min <= 2 ? min : 2; + m_maxArgs = max >= 2 ? max : 2; +} + +Function::Function(FunctionPointer fp, ValueType value, ValueType param1, ValueType param2, ValueType param3, + uint min, uint max) +{ + m_function = fp; + m_returnValue = value; + m_params.append(param1); + m_params.append(param2); + m_params.append(param3); + m_minArgs = min <= 3 ? min : 3; + m_maxArgs = max >= 3 ? max : 3; +} + +Function::Function(FunctionPointer fp, ValueType value, ValueType param1, ValueType param2, ValueType param3, + ValueType param4, uint min, uint max) +{ + m_function = fp; + m_returnValue = value; + m_params.append(param1); + m_params.append(param2); + m_params.append(param3); + m_params.append(param4); + m_minArgs = min <= 4 ? min : 4; + m_maxArgs = max >= 4 ? max : 4; +} + +Function::Function(FunctionPointer fp, ValueType value, ValueType param1, ValueType param2, ValueType param3, + ValueType param4, ValueType param5, uint min, uint max) +{ + m_function = fp; + m_returnValue = value; + m_params.append(param1); + m_params.append(param2); + m_params.append(param3); + m_params.append(param4); + m_params.append(param5); + m_minArgs = min <= 5 ? min : 5; + m_maxArgs = max >= 5 ? max : 5; +} + +bool Function::isVoid() const +{ + return returnValue() == ValueNone; +} + +ValueType Function::returnValue() const +{ + return m_returnValue; +} + +ValueType Function::argType(uint i) const +{ + if (i < m_params.count()) + return m_params[i]; + else if (i < m_maxArgs) + return m_params.last(); + else + return ValueNone; +} + +uint Function::minArgs() const +{ + return m_minArgs; +} + +uint Function::maxArgs() const +{ + return m_maxArgs; +} + +bool Function::isValid(const ParameterList& params) const +{ + return params.count() >= minArgs() && params.count() <= maxArgs(); +} + +ParseNode Function::execute(Parser* P, const ParameterList& params) const +{ + if (m_function) + return m_function(P, params); + else + return ParseNode(); +} + |