aboutsummaryrefslogtreecommitdiff
path: root/src/functionrange.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/functionrange.cpp')
-rw-r--r--src/functionrange.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/functionrange.cpp b/src/functionrange.cpp
new file mode 100644
index 0000000..f45cf0e
--- /dev/null
+++ b/src/functionrange.cpp
@@ -0,0 +1,71 @@
1#include "functionrange.h"
2
3#include <bu/plugger.h>
4PluginInterface3( pluginFunctionRange, range, FunctionRange, Function,
5 "Mike Buland", 0, 1 );
6
7FunctionRange::FunctionRange()
8{
9}
10
11FunctionRange::~FunctionRange()
12{
13}
14
15Bu::String FunctionRange::getName() const
16{
17 return "range";
18}
19
20Variable FunctionRange::call( Variable &input, VarList lParams )
21{
22 Variable vRet( Variable::typeList );
23 int iLow = 1;
24 int iHigh = 1;
25 int iStep = 1;
26 if( lParams.getSize() == 1 )
27 {
28 iHigh = lParams.first().toInt();
29 }
30 else if( lParams.getSize() == 2 )
31 {
32 iLow = lParams.first().toInt();
33 iHigh = lParams.last().toInt();
34 }
35 else if( lParams.getSize() == 3 )
36 {
37 VarList::iterator i = lParams.begin();
38 iLow = (*i).toInt();
39 i++;
40 iHigh = (*i).toInt();
41 i++;
42 iStep = (*i).toInt();
43 }
44 if( iStep == 0 )
45 throw Bu::ExceptionBase("Step cannot be zero.");
46
47 if( iHigh < iLow )
48 {
49 if( iStep > 0 )
50 throw Bu::ExceptionBase(
51 "If start is less than end then step must be negative.");
52 for( int j = iLow; j >= iHigh; j += iStep )
53 {
54 vRet.append( Variable( j ) );
55 }
56 }
57 else
58 {
59 if( iStep < 0 )
60 throw Bu::ExceptionBase(
61 "If start is more than end then step must be positive.");
62 for( int j = iLow; j <= iHigh; j += iStep )
63 {
64 vRet.append( Variable( j ) );
65 }
66 }
67
68
69 return vRet;
70}
71