aboutsummaryrefslogtreecommitdiff
path: root/src/functionunique.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/functionunique.cpp47
1 files changed, 47 insertions, 0 deletions
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 @@
1#include "functionunique.h"
2
3#include <bu/hash.h>
4#include <bu/plugger.h>
5PluginInterface3( pluginFunctionUnique, unique, FunctionUnique, Function,
6 "Mike Buland", 0, 1 );
7
8FunctionUnique::FunctionUnique()
9{
10}
11
12FunctionUnique::~FunctionUnique()
13{
14}
15
16Bu::String FunctionUnique::getName() const
17{
18 return "unique";
19}
20
21Variable FunctionUnique::call( Variable &input, VarList lParams )
22{
23 if( lParams.getSize() > 0 )
24 throw Bu::ExceptionBase("Unique does not take any parameters.");
25 if( input.getType() != Variable::typeList )
26 throw Bu::ExceptionBase("unique does not work on non-list types.");
27
28 Bu::Hash<Bu::String, bool> hHas;
29
30 Variable vOut( Variable::typeList );
31 for( VarList::iterator i = input.begin(); i; i++ )
32 {
33 if( (*i).getType() != Variable::typeString )
34 continue;
35
36 Bu::String s = (*i).getString();
37
38 if( hHas.has( s ) )
39 continue;
40
41 hHas.insert( s, true );
42 vOut.append( *i );
43 }
44
45 return vOut;
46}
47