aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/functionplugger.cpp2
-rw-r--r--src/functionunique.cpp47
-rw-r--r--src/functionunique.h16
3 files changed, 65 insertions, 0 deletions
diff --git a/src/functionplugger.cpp b/src/functionplugger.cpp
index 8bd2edd..1f2bcf5 100644
--- a/src/functionplugger.cpp
+++ b/src/functionplugger.cpp
@@ -21,6 +21,7 @@ extern Bu::PluginInfo pluginFunctionOpen;
21extern Bu::PluginInfo pluginFunctionClose; 21extern Bu::PluginInfo pluginFunctionClose;
22extern Bu::PluginInfo pluginFunctionRead; 22extern Bu::PluginInfo pluginFunctionRead;
23extern Bu::PluginInfo pluginFunctionWrite; 23extern Bu::PluginInfo pluginFunctionWrite;
24extern Bu::PluginInfo pluginFunctionUnique;
24 25
25FunctionPlugger::FunctionPlugger() 26FunctionPlugger::FunctionPlugger()
26{ 27{
@@ -42,6 +43,7 @@ FunctionPlugger::FunctionPlugger()
42 registerBuiltinPlugin( &pluginFunctionClose ); 43 registerBuiltinPlugin( &pluginFunctionClose );
43 registerBuiltinPlugin( &pluginFunctionRead ); 44 registerBuiltinPlugin( &pluginFunctionRead );
44 registerBuiltinPlugin( &pluginFunctionWrite ); 45 registerBuiltinPlugin( &pluginFunctionWrite );
46 registerBuiltinPlugin( &pluginFunctionUnique );
45 47
46 DIR *dir = opendir("/usr/lib/build"); 48 DIR *dir = opendir("/usr/lib/build");
47 if( !dir ) 49 if( !dir )
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
diff --git a/src/functionunique.h b/src/functionunique.h
new file mode 100644
index 0000000..6bc4225
--- /dev/null
+++ b/src/functionunique.h
@@ -0,0 +1,16 @@
1#ifndef FUNCTION_UNIQUE_H
2#define FUNCTION_UNIQUE_H
3
4#include "function.h"
5
6class FunctionUnique : public Function
7{
8public:
9 FunctionUnique();
10 virtual ~FunctionUnique();
11
12 virtual Bu::String getName() const;
13 virtual Variable call( Variable &input, VarList lParams );
14};
15
16#endif