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