From ea17d3262924f95a4fa721b3de6d7fe499bdcf14 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 5 Apr 2012 22:52:54 +0000 Subject: Added unique function and a workaround for non-matching inputs to rules passing the rule input filter. --- src/functionunique.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/functionunique.cpp (limited to 'src/functionunique.cpp') diff --git a/src/functionunique.cpp b/src/functionunique.cpp new file mode 100644 index 0000000..ca2461f --- /dev/null +++ b/src/functionunique.cpp @@ -0,0 +1,47 @@ +#include "functionunique.h" + +#include +#include +PluginInterface3( pluginFunctionUnique, unique, FunctionUnique, Function, + "Mike Buland", 0, 1 ); + +FunctionUnique::FunctionUnique() +{ +} + +FunctionUnique::~FunctionUnique() +{ +} + +Bu::String FunctionUnique::getName() const +{ + return "unique"; +} + +Variable FunctionUnique::call( Variable &input, VarList lParams ) +{ + if( lParams.getSize() > 0 ) + throw Bu::ExceptionBase("Unique does not take any parameters."); + if( input.getType() != Variable::typeList ) + throw Bu::ExceptionBase("unique does not work on non-list types."); + + Bu::Hash hHas; + + Variable vOut( Variable::typeList ); + for( VarList::iterator i = input.begin(); i; i++ ) + { + if( (*i).getType() != Variable::typeString ) + continue; + + Bu::String s = (*i).getString(); + + if( hHas.has( s ) ) + continue; + + hHas.insert( s, true ); + vOut.append( *i ); + } + + return vOut; +} + -- cgit v1.2.3