Rework namespaces to prevent conflicts and fix diff() function within expression object

This commit is contained in:
Alex Harker
2018-10-16 09:21:37 +01:00
parent aae13fc385
commit 06960473ea
7 changed files with 643 additions and 637 deletions
@@ -6,7 +6,7 @@
// Absolute diff functor
namespace
namespace FrameLib_Binary_Ops
{
struct absDiff { double operator()(double x, double y) { return std::abs(x-y); } };
}
@@ -51,7 +51,7 @@ template<> inline const char *FrameLib_BinaryOp<std::logical_and<double>>::getDe
template<> inline const char *FrameLib_BinaryOp<std::logical_or<double>>::getDescriptionString()
{ return "Calculates the logical or of the left and right input frame values"; }
template<> inline const char *FrameLib_BinaryOp<absDiff>::getDescriptionString()
template<> inline const char *FrameLib_BinaryOp<FrameLib_Binary_Ops::absDiff>::getDescriptionString()
{ return "Calculates the absolute differences between values in the two input frames"; }
@@ -72,7 +72,7 @@ typedef FrameLib_BinaryOp<std::less_equal<double>> FrameLib_LessThanEqual;
typedef FrameLib_BinaryOp<std::logical_and<double>> FrameLib_LogicalAnd;
typedef FrameLib_BinaryOp<std::logical_or<double>> FrameLib_LogicalOr;
typedef FrameLib_BinaryOp<absDiff> FrameLib_Diff;
typedef FrameLib_BinaryOp<FrameLib_Binary_Ops::absDiff> FrameLib_Diff;
// Binary (functions)
@@ -7,7 +7,7 @@
// Specialisations to allow implicit multiples of i for complex numbers
template<>
const char *FrameLib_ExprParser<std::complex<double>>::extentNumber(const char *expr)
const char *FrameLib_ExprParser::Parser<std::complex<double>>::extentNumber(const char *expr)
{
if (isDigit(*expr))
{
@@ -21,7 +21,7 @@ const char *FrameLib_ExprParser<std::complex<double>>::extentNumber(const char *
}
template<>
std::complex<double> FrameLib_ExprParser<std::complex<double>>::convertTextToNumber(const char* text)
std::complex<double> FrameLib_ExprParser::Parser<std::complex<double>>::convertTextToNumber(const char* text)
{
if (text[strlen(text) - 1] == 'i')
{
@@ -37,7 +37,7 @@ std::complex<double> FrameLib_ExprParser<std::complex<double>>::convertTextToNum
// Function/Operator Templates
template <typename Op>
struct UnaryOperation final : public OpBase<std::complex<double>>
struct UnaryOperation final : public FrameLib_ExprParser::OpBase<std::complex<double>>
{
typedef std::complex<double> complex;
@@ -53,7 +53,7 @@ struct UnaryOperation final : public OpBase<std::complex<double>>
};
template <typename Op>
struct BinaryOperation final : public OpBase<std::complex<double>>
struct BinaryOperation final : public FrameLib_ExprParser::OpBase<std::complex<double>>
{
typedef std::complex<double> complex;
@@ -72,7 +72,7 @@ struct BinaryOperation final : public OpBase<std::complex<double>>
static std::complex<double> negate(const std::complex<double>& a) { return -a; }
FrameLib_ComplexExpression::Parser::Parser() : FrameLib_ExprParser(3)
FrameLib_ComplexExpression::Parser::Parser() : FrameLib_ExprParser::Parser<std::complex<double>>(3)
{
// Default Return Constant
@@ -285,8 +285,9 @@ void FrameLib_ComplexExpression::ConstantOut::process()
FrameLib_ComplexExpression::FrameLib_ComplexExpression(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, FrameLib_Proxy *proxy) : FrameLib_Block(kProcessor, context, proxy), mParameters(context, proxy, &sParamInfo)
{
typedef Graph<std::complex<double>> Graph;
typedef FrameLib_ExprParser::Graph<std::complex<double>> Graph;
typedef FrameLib_Block::Connection Connection;
using namespace FrameLib_ExprParser;
mParameters.addString(kExpression, "expr", 0);
mParameters.setInstantiation();
@@ -20,7 +20,7 @@ class FrameLib_ComplexExpression : public FrameLib_Block
// Internal Classes
struct Parser : public FrameLib_ExprParser<std::complex<double>>
struct Parser : public FrameLib_ExprParser::Parser<std::complex<double>>
{
Parser();
};
File diff suppressed because it is too large Load Diff
@@ -3,6 +3,7 @@
#include "../Unary/FrameLib_Unary_Template.h"
#include "../Binary/FrameLib_Binary_Template.h"
#include "../Binary/FrameLib_Binary_Objects.h"
#include "../Ternary/FrameLib_Ternary_Template.h"
#include "../Ternary/FrameLib_Ternary_Objects.h"
@@ -11,7 +12,7 @@
// Function/Operator Templates
template <typename Op>
struct UnaryOperation final : public OpBase<double>
struct UnaryOperation final : public FrameLib_ExprParser::OpBase<double>
{
UnaryOperation(const char* name, int precedence = 0) : OpBase(name, precedence) {}
@@ -25,7 +26,7 @@ struct UnaryOperation final : public OpBase<double>
};
template <typename Op>
struct BinaryOperation final : public OpBase<double>
struct BinaryOperation final : public FrameLib_ExprParser::OpBase<double>
{
BinaryOperation(const char* name, int precedence = 0) : OpBase(name, precedence) {}
@@ -41,7 +42,7 @@ struct BinaryOperation final : public OpBase<double>
};
template <typename Op>
struct TernaryOperation final : public OpBase<double>
struct TernaryOperation final : public FrameLib_ExprParser::OpBase<double>
{
TernaryOperation(const char* name, int precedence = 0) : OpBase(name, precedence) {}
@@ -58,7 +59,7 @@ struct TernaryOperation final : public OpBase<double>
static double negate(double a) { return -a; }
FrameLib_Expression::Parser::Parser() : FrameLib_ExprParser(7)
FrameLib_Expression::Parser::Parser() : FrameLib_ExprParser::Parser<double>(7)
{
// Default Return Constant
@@ -131,11 +132,11 @@ FrameLib_Expression::Parser::Parser() : FrameLib_ExprParser(7)
addFunction(new BinaryOperation<Binary_Functor<hypot>>("hypot"));
addFunction(new BinaryOperation<Binary_Functor<fmin>>("min"));
addFunction(new BinaryOperation<Binary_Functor<fmax>>("max"));
addFunction(new BinaryOperation<Binary_Functor<fdim>>("diff"));
addFunction(new BinaryOperation<FrameLib_Binary_Ops::absDiff>("diff"));
addFunction(new TernaryOperation<Ternary_Functor<Ternary::clip>>("clip"));
addFunction(new TernaryOperation<Ternary_Functor<Ternary::wrap>>("wrap"));
addFunction(new TernaryOperation<Ternary_Functor<Ternary::fold>>("fold"));
addFunction(new TernaryOperation<Ternary_Functor<FrameLib_Ternary_Ops::clip>>("clip"));
addFunction(new TernaryOperation<Ternary_Functor<FrameLib_Ternary_Ops::wrap>>("wrap"));
addFunction(new TernaryOperation<Ternary_Functor<FrameLib_Ternary_Ops::fold>>("fold"));
}
// Input Processor Class
@@ -235,9 +236,10 @@ void FrameLib_Expression::ConstantOut::process()
FrameLib_Expression::FrameLib_Expression(FrameLib_Context context, FrameLib_Parameters::Serial *serialisedParameters, FrameLib_Proxy *proxy) : FrameLib_Block(kProcessor, context, proxy), mParameters(context, proxy, &sParamInfo)
{
typedef Graph<double> Graph;
typedef FrameLib_ExprParser::Graph<double> Graph;
typedef FrameLib_Block::Connection Connection;
using namespace FrameLib_ExprParser;
mParameters.addString(kExpression, "expr", 0);
mParameters.setInstantiation();
@@ -18,7 +18,7 @@ class FrameLib_Expression : public FrameLib_Block
// Interal Classes
struct Parser : public FrameLib_ExprParser<double>
struct Parser : public FrameLib_ExprParser::Parser<double>
{
Parser();
};
@@ -4,7 +4,7 @@
#include "FrameLib_Ternary_Template.h"
namespace Ternary
namespace FrameLib_Ternary_Ops
{
// Specification/signature taken from C++17 std::clamp, (although that specifies use of only < rather than < and >)
// If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise returns v.
@@ -76,27 +76,27 @@ namespace Ternary
};
template<>
inline const char* FrameLib_Ternary<Ternary::clip<double>>::getDescriptionString()
inline const char* FrameLib_Ternary<FrameLib_Ternary_Ops::clip<double>>::getDescriptionString()
{
return "Clips the incoming frame to the range delimited by the low and high parameters.";
}
template<>
inline const char* FrameLib_Ternary<Ternary::wrap<double>>::getDescriptionString()
inline const char* FrameLib_Ternary<FrameLib_Ternary_Ops::wrap<double>>::getDescriptionString()
{
return "Wraps the incoming frame into the range delimited by the low and high parameters.";
}
template<>
inline const char* FrameLib_Ternary<Ternary::fold<double>>::getDescriptionString()
inline const char* FrameLib_Ternary<FrameLib_Ternary_Ops::fold<double>>::getDescriptionString()
{
return "Folds the incoming frame into the range delimited by the low and high parameters";
}
typedef FrameLib_Ternary<Ternary::clip<double>> FrameLib_Clip;
typedef FrameLib_Ternary<Ternary::wrap<double>> FrameLib_Wrap;
typedef FrameLib_Ternary<Ternary::fold<double>> FrameLib_Fold;
typedef FrameLib_Ternary<FrameLib_Ternary_Ops::clip<double>> FrameLib_Clip;
typedef FrameLib_Ternary<FrameLib_Ternary_Ops::wrap<double>> FrameLib_Wrap;
typedef FrameLib_Ternary<FrameLib_Ternary_Ops::fold<double>> FrameLib_Fold;
#endif