1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | #include <sstream> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <errno.h> |
---|
6 | #include <vector> |
---|
7 | |
---|
8 | |
---|
9 | // #include "RpLibrary.h" |
---|
10 | |
---|
11 | #ifndef _RpVARIABLE_H |
---|
12 | #include "RpVariable.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #ifndef _RpOPTION_H |
---|
16 | #include "RpOption.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #ifndef _RpCHOICE_H |
---|
20 | #define _RpCHOICE_H |
---|
21 | |
---|
22 | class RpChoice : public RpVariable |
---|
23 | { |
---|
24 | public: |
---|
25 | |
---|
26 | // users member fxns |
---|
27 | |
---|
28 | virtual RpChoice& setDefaultValue (std::string newDefaultVal); |
---|
29 | virtual RpChoice& setCurrentValue (std::string newCurrentVal); |
---|
30 | virtual RpChoice& setOption (std::string newOption); |
---|
31 | virtual RpChoice& deleteOption (std::string newOption); |
---|
32 | |
---|
33 | // changed from "Value" to "Val" because base class makes |
---|
34 | // these functions virtual and derived class has a different |
---|
35 | // return type. compiler doesnt like this. need to find another |
---|
36 | // way around this |
---|
37 | // |
---|
38 | // if we keep the null_val=NULL will that give us undefined behavior? |
---|
39 | // |
---|
40 | virtual std::string getDefaultValue (void* null_val=NULL) const; |
---|
41 | virtual std::string getCurrentValue (void* null_val=NULL) const; |
---|
42 | virtual std::string getFirstOption (); |
---|
43 | virtual std::string getNextOption (); |
---|
44 | virtual unsigned int getOptListSize () const; |
---|
45 | |
---|
46 | |
---|
47 | // place the information from this object into the xml library 'lib' |
---|
48 | // virtual RpChoice& put(RpLibrary lib); |
---|
49 | // RpChoice& put() const; |
---|
50 | |
---|
51 | RpChoice ( |
---|
52 | std::string path, |
---|
53 | std::string defaultVal, |
---|
54 | std::string optionList |
---|
55 | ) |
---|
56 | : RpVariable (path, new std::string (defaultVal) ) |
---|
57 | { |
---|
58 | // optionList is a comma separated list of options |
---|
59 | |
---|
60 | optionsIter = options.begin(); |
---|
61 | std::string::size_type pos = optionList.find (',',0); |
---|
62 | std::string::size_type lastPos = 0; |
---|
63 | std::string tmpStr; |
---|
64 | |
---|
65 | |
---|
66 | while (pos != std::string::npos) { |
---|
67 | tmpStr = optionList.substr(lastPos, pos-lastPos); |
---|
68 | setOption(tmpStr); |
---|
69 | lastPos = pos + 1; |
---|
70 | pos = optionList.find (",",lastPos); |
---|
71 | } |
---|
72 | |
---|
73 | tmpStr = optionList.substr(lastPos); |
---|
74 | setOption(tmpStr); |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | RpChoice ( |
---|
79 | std::string path, |
---|
80 | std::string defaultVal, |
---|
81 | std::string label, |
---|
82 | std::string desc, |
---|
83 | std::string optionList |
---|
84 | ) |
---|
85 | : RpVariable (path, new std::string (defaultVal), label, desc) |
---|
86 | { |
---|
87 | // optionList is a comma separated list of options |
---|
88 | |
---|
89 | optionsIter = options.begin(); |
---|
90 | std::string::size_type pos = optionList.find (',',0); |
---|
91 | std::string::size_type lastPos = 0; |
---|
92 | std::string tmpStr; |
---|
93 | |
---|
94 | |
---|
95 | while (pos != std::string::npos) { |
---|
96 | tmpStr = optionList.substr(lastPos, pos-lastPos); |
---|
97 | setOption(tmpStr); |
---|
98 | lastPos = pos + 1; |
---|
99 | pos = optionList.find (",",lastPos); |
---|
100 | } |
---|
101 | |
---|
102 | tmpStr = optionList.substr(lastPos); |
---|
103 | setOption(tmpStr); |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | // copy constructor |
---|
108 | RpChoice ( const RpChoice& myRpChoice ) |
---|
109 | : RpVariable (myRpChoice), |
---|
110 | options (myRpChoice.options) |
---|
111 | { |
---|
112 | } |
---|
113 | |
---|
114 | // default destructor |
---|
115 | virtual ~RpChoice () |
---|
116 | { |
---|
117 | // clean up dynamic memory |
---|
118 | |
---|
119 | } |
---|
120 | private: |
---|
121 | |
---|
122 | std::vector<RpOption> options; |
---|
123 | std::vector<RpOption>::iterator optionsIter; |
---|
124 | }; |
---|
125 | |
---|
126 | /*--------------------------------------------------------------------------*/ |
---|
127 | /*--------------------------------------------------------------------------*/ |
---|
128 | |
---|
129 | #endif |
---|