source: trunk/src/core/RpChoice.cc @ 121

Last change on this file since 121 was 121, checked in by dkearney, 18 years ago

added basic doxygen tags for function definitions.

File size: 4.2 KB
Line 
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
21RpChoice&
22RpChoice::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
44RpChoice&
45RpChoice::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
67RpChoice&
68RpChoice::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
80RpChoice&
81RpChoice::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
109std::string
110RpChoice::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
121std::string
122RpChoice::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
140std::string
141RpChoice::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
154std::string
155RpChoice::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
170unsigned int
171RpChoice::getOptListSize() const
172{
173    return options.size();
174}
175
176// -------------------------------------------------------------------- //
Note: See TracBrowser for help on using the repository browser.