1 | /* |
---|
2 | * RpChoice - Rappture 2.0 About XML object |
---|
3 | * |
---|
4 | * ====================================================================== |
---|
5 | * AUTHOR: Derrick Kearney, Purdue University |
---|
6 | * Copyright (c) 2004-2005 Purdue Research Foundation |
---|
7 | * |
---|
8 | * See the file "license.terms" for information on usage and |
---|
9 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
10 | * ====================================================================== |
---|
11 | */ |
---|
12 | |
---|
13 | #include "RpChoice.h" |
---|
14 | |
---|
15 | /**********************************************************************/ |
---|
16 | // METHOD: setDefaultValue() |
---|
17 | /// Set the default value of a RpChoice object. |
---|
18 | /** |
---|
19 | */ |
---|
20 | |
---|
21 | RpChoice& |
---|
22 | RpChoice::setDefaultValue(std::string newDefaultVal) |
---|
23 | { |
---|
24 | std::string* def = NULL; |
---|
25 | |
---|
26 | def = (std::string*) RpVariable::getDefaultValue(); |
---|
27 | |
---|
28 | if (!def) { |
---|
29 | RpVariable::setDefaultValue(new std::string (newDefaultVal)); |
---|
30 | } |
---|
31 | else { |
---|
32 | *def = newDefaultVal; |
---|
33 | } |
---|
34 | |
---|
35 | return *this; |
---|
36 | } |
---|
37 | |
---|
38 | /**********************************************************************/ |
---|
39 | // METHOD: setCurrentValue() |
---|
40 | /// Set the current value of a RpChoice object. |
---|
41 | /** |
---|
42 | */ |
---|
43 | |
---|
44 | RpChoice& |
---|
45 | RpChoice::setCurrentValue(std::string newCurrentVal) |
---|
46 | { |
---|
47 | std::string* cur = (std::string*) RpVariable::getCurrentValue(); |
---|
48 | std::string* def = (std::string*) RpVariable::getDefaultValue(); |
---|
49 | |
---|
50 | if (cur == def) { |
---|
51 | RpVariable::setCurrentValue(new std::string (newCurrentVal)); |
---|
52 | } |
---|
53 | else { |
---|
54 | *cur = newCurrentVal; |
---|
55 | } |
---|
56 | |
---|
57 | return *this; |
---|
58 | } |
---|
59 | |
---|
60 | |
---|
61 | /**********************************************************************/ |
---|
62 | // METHOD: setOption() |
---|
63 | /// Set an option for this object. |
---|
64 | /** |
---|
65 | */ |
---|
66 | |
---|
67 | RpChoice& |
---|
68 | RpChoice::setOption(std::string newOption) |
---|
69 | { |
---|
70 | options.push_back(RpOption(newOption)); |
---|
71 | return *this; |
---|
72 | } |
---|
73 | |
---|
74 | /**********************************************************************/ |
---|
75 | // METHOD: deleteOption() |
---|
76 | /// Delete the provided option from this object. |
---|
77 | /** |
---|
78 | */ |
---|
79 | |
---|
80 | RpChoice& |
---|
81 | RpChoice::deleteOption(std::string optionName) |
---|
82 | { |
---|
83 | int lvc = 0; |
---|
84 | int vsize = options.size(); |
---|
85 | // std::vector<RpOption>::iterator tempIterator; |
---|
86 | /* |
---|
87 | for (lvc=0,tempIterator=options.begin();lvc<vsize;lvc++,tempIterator++) { |
---|
88 | if (option[lvc] == option) { |
---|
89 | option.erase(tempIterator); |
---|
90 | break; |
---|
91 | } |
---|
92 | } |
---|
93 | */ |
---|
94 | for (lvc = 0;lvc < vsize; lvc++) { |
---|
95 | if (options[lvc].getLabel() == optionName) { |
---|
96 | options.erase(options.begin()+lvc); |
---|
97 | break; |
---|
98 | } |
---|
99 | } |
---|
100 | return *this; |
---|
101 | } |
---|
102 | |
---|
103 | /**********************************************************************/ |
---|
104 | // METHOD: getDefaultValue() |
---|
105 | /// Report the default value of this object. |
---|
106 | /** |
---|
107 | */ |
---|
108 | |
---|
109 | std::string |
---|
110 | RpChoice::getDefaultValue(void* null_val) const |
---|
111 | { |
---|
112 | return *((std::string*) RpVariable::getDefaultValue()); |
---|
113 | } |
---|
114 | |
---|
115 | /**********************************************************************/ |
---|
116 | // METHOD: getCurrentValue() |
---|
117 | /// Report the current value of the object. |
---|
118 | /** |
---|
119 | */ |
---|
120 | |
---|
121 | std::string |
---|
122 | RpChoice::getCurrentValue(void* null_val) const |
---|
123 | { |
---|
124 | return *((std::string*) RpVariable::getCurrentValue()); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | /************************************************************************ |
---|
129 | * |
---|
130 | * report the options of the object |
---|
131 | * |
---|
132 | ************************************************************************/ |
---|
133 | |
---|
134 | /**********************************************************************/ |
---|
135 | // METHOD: setLabel() |
---|
136 | /// Set the label of this object. |
---|
137 | /** |
---|
138 | */ |
---|
139 | |
---|
140 | std::string |
---|
141 | RpChoice::getFirstOption() |
---|
142 | { |
---|
143 | optionsIter = options.begin(); |
---|
144 | return ((*optionsIter).getLabel()); |
---|
145 | } |
---|
146 | |
---|
147 | /**********************************************************************/ |
---|
148 | // METHOD: getNextOption() |
---|
149 | /// Report the next options of the object. |
---|
150 | /** |
---|
151 | * If you get to the end of the options list, "" is returned. |
---|
152 | */ |
---|
153 | |
---|
154 | std::string |
---|
155 | RpChoice::getNextOption() |
---|
156 | { |
---|
157 | optionsIter++; |
---|
158 | if (optionsIter == options.end()) { |
---|
159 | return std::string(""); |
---|
160 | } |
---|
161 | return ((*optionsIter).getLabel()); |
---|
162 | } |
---|
163 | |
---|
164 | /**********************************************************************/ |
---|
165 | // METHOD: getOptListSize() |
---|
166 | /// Report the number of options (items) in this object. |
---|
167 | /** |
---|
168 | */ |
---|
169 | |
---|
170 | unsigned int |
---|
171 | RpChoice::getOptListSize() const |
---|
172 | { |
---|
173 | return options.size(); |
---|
174 | } |
---|
175 | |
---|
176 | // -------------------------------------------------------------------- // |
---|