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