ENH: relocate/rename expression-related ops to exprOps

This commit is contained in:
Mark Olesen
2019-12-04 09:27:55 +01:00
parent 9a7adf3606
commit dac0dd137e
2 changed files with 139 additions and 75 deletions

View File

@ -38,8 +38,8 @@ SourceFiles
#ifndef exprTools_H
#define exprTools_H
#include "exprOps.H"
#include "exprString.H"
#include "scalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -47,7 +47,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Namespace exprTools Declaration
Namespace exprTools Declarations
\*---------------------------------------------------------------------------*/
namespace exprTools
@ -100,81 +100,9 @@ List<expressions::exprString> getList
);
// Boolean-like values
//- Convert [0-1] values (usually scalars) as false/true
template<class T>
struct toBoolOp
{
int operator()(const T& val) const
{
return (0.5 < Foam::mag(val));
}
};
//- No conversion needed for bool
template<>
struct toBoolOp<bool>
{
int operator()(bool val) const
{
return val;
}
};
//- Inverse test of toBoolOp()
template<class T>
struct toBoolNotOp
{
int operator()(const T& val) const
{
return (Foam::mag(val) < 0.5);
}
};
//- Inverse test of toBoolOp, no conversion needed for bool
template<>
struct toBoolNotOp<bool>
{
int operator()(bool val) const
{
return !val;
}
};
//- Logical 'and' with scalars as (false, true) values
template<class T>
struct toBoolAndOp
{
int operator()(const T& a, const T& b) const
{
return (toBoolOp<T>()(a) && toBoolOp<T>()(b));
}
};
//- Logical 'or' with scalars as (false, true) values
template<class T>
struct toBoolOrOp
{
int operator()(const T& a, const T& b) const
{
return (toBoolOp<T>()(a) || toBoolOp<T>()(b));
}
};
//- Logical 'xor' with scalars as (false, true) values
template<class T>
struct toBoolXorOp
{
int operator()(const T& a, const T& b) const
{
return (toBoolOp<T>()(a) ? toBoolNotOp<T>()(b) : toBoolOp<T>()(b));
}
};
} // End namespace exprTools
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam