OpenASIP  2.0
OptionValue.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file OptionValue.cc
26  *
27  * Definitions of OptionValue classes.
28  *
29  * @author Jari Mäntyneva (jari.mantyneva-no.spam-tut.fi)
30  * @note rating: red
31  */
32 
33 #include <iostream>
34 #include <string>
35 #include <sstream>
36 
37 #include "Application.hh"
38 #include "OptionValue.hh"
39 
40 using std::string;
41 using std::istringstream;
42 using std::endl;
43 
44 //////////////////////////////////////////////////////////////////////////////
45 // OptionValue
46 //////////////////////////////////////////////////////////////////////////////
47 
48 /**
49  * Constructor.
50  */
52 }
53 
54 /**
55  * Destructor.
56  */
58 }
59 
60 /**
61  * This implementation should never be called.
62  *
63  * @exception WrongSubclass Called for a wrong subclass.
64  */
65 void
66 OptionValue::setStringValue(const std::string&) {
67  throw WrongSubclass(__FILE__, __LINE__, __func__);
68 }
69 
70 /**
71  * This implementation should never be called.
72  *
73  * @exception WrongSubclass Called for a wrong subclass.
74  */
75 void
77  throw WrongSubclass(__FILE__, __LINE__, __func__);
78 }
79 
80 /**
81  * This implementation should never be called.
82  *
83  * @exception WrongSubclass Called for a wrong subclass.
84  */
85 void
87  throw WrongSubclass(__FILE__, __LINE__, __func__);
88 }
89 
90 /**
91  * This implementation should never be called.
92  *
93  * @exception WrongSubclass Called for a wrong subclass.
94  */
95 void
97  throw WrongSubclass(__FILE__, __LINE__, __func__);
98 }
99 
100 /**
101  * This implementation should never be called.
102  *
103  * @exception WrongSubclass Called for a wrong subclass.
104  */
105 void
107  throw WrongSubclass(__FILE__, __LINE__, __func__);
108 }
109 
110 /**
111  * This implementation should never be called.
112  *
113  * @return Nothing.
114  * @exception WrongSubclass Called for a wrong subclass.
115  */
116 void
118  throw WrongSubclass(__FILE__, __LINE__, __func__);
119 }
120 
121 /**
122  * This implementation should never be called.
123  *
124  * @return Nothing.
125  * @exception WrongSubclass Called for a wrong subclass.
126  * @exception OutOfRange Never thrown by this function.
127  */
128 int
130  throw WrongSubclass(__FILE__, __LINE__, __func__);
131  return 0;
132 }
133 
134 /**
135  * This implementation should never be called.
136  *
137  * @return Nothing.
138  * @exception WrongSubclass Called for a wrong subclass.
139  * @exception OutOfRange Never thrown by this function.
140  */
141 std::string
143  throw WrongSubclass(__FILE__, __LINE__, __func__);
144  return "";
145 }
146 
147 /**
148  * This implementation should never be called.
149  *
150  * @return Nothing.
151  * @exception WrongSubclass Called for a wrong subclass.
152  */
153 double
155  throw WrongSubclass(__FILE__, __LINE__, __func__);
156  return 0;
157 }
158 
159 /**
160  * This implementation should never be called.
161  *
162  * @return Nothing.
163  * @exception WrongSubclass Called for a wrong subclass.
164  */
165 bool
167  throw WrongSubclass(__FILE__, __LINE__, __func__);
168  return false;
169 }
170 
171 /**
172  * This implementation should never be called.
173  *
174  * @return Nothing.
175  * @exception WrongSubclass Called for a wrong subclass.
176  */
177 bool
179  throw WrongSubclass(__FILE__, __LINE__, __func__);
180  return false;
181 }
182 
183 /**
184  * This implementation should never be called.
185  *
186  * @return Nothing.
187  * @exception WrongSubclass Called for a wrong subclass.
188  */
189 int
191  throw WrongSubclass(__FILE__, __LINE__, __func__);
192  return 0;
193 }
194 
195 //////////////////////////////////////////////////////////////////////////////
196 // IntegerOptionValue
197 //////////////////////////////////////////////////////////////////////////////
198 
199 /**
200  * Constructor.
201  *
202  * @param value The value of integer option.
203  */
205  value_ = value;
206 }
207 
208 /**
209  * Destructor.
210  */
212 }
213 
214 /**
215  * Sets new value for integer option.
216  *
217  * @param value New value for the integer option.
218  * @exception WrongSubclass Is never thrown by this function.
219  */
220 void
222  value_ = value;
223 }
224 
225 /**
226  * Returns the value of integer option.
227  *
228  * @return The value of integer option.
229  * @exception WrongSubclass Is never thrown by this function.
230  * @exception OutOfRange Never thrown by this function.
231  */
232 int
234  return value_;
235 }
236 
237 //////////////////////////////////////////////////////////////////////////////
238 // UnsignedIntegerOptionValue
239 //////////////////////////////////////////////////////////////////////////////
240 
242  value_ = value;
243 }
244 
246 }
247 
248 void
250  value_ = value;
251 }
252 
253 unsigned
255  return value_;
256 }
257 
258 //////////////////////////////////////////////////////////////////////////////
259 // StringOptionValue
260 //////////////////////////////////////////////////////////////////////////////
261 
262 /**
263  * Constructor.
264  *
265  * @param value The value of string option.
266  */
267 StringOptionValue::StringOptionValue(const std::string value) {
268  value_ = value;
269 }
270 
271 /**
272  * Destructor.
273  */
275 }
276 
277 /**
278  * Sets new value for string option.
279  *
280  * @param value New value for the string option.
281  * @exception WrongSubclass Is never thrown by this function.
282  */
283 void
284 StringOptionValue::setStringValue(const std::string& value) {
285  value_ = value;
286 }
287 
288 /**
289  * Returns the value of string option.
290  *
291  * @return The value of string option.
292  * @exception WrongSubclass Is never thrown by this function.
293  * @exception OutOfRange Never thrown by this function.
294  */
295 string
297  return value_;
298 }
299 
300 //////////////////////////////////////////////////////////////////////////////
301 // RealOptionValue
302 //////////////////////////////////////////////////////////////////////////////
303 
304 /**
305  * Constructor.
306  *
307  * @param value The value of real option.
308  */
310  value_ = value;
311 }
312 
313 /**
314  * Destructor.
315  */
317 }
318 
319 /**
320  * Sets new value for real option.
321  *
322  * @param value New value for the real option.
323  * @exception WrongSubclass Is never thrown by this function.
324  */
325 void
327  value_ = value;
328 }
329 
330 /**
331  * Returns the value of string option.
332  *
333  * @return The value of string option.
334  * @exception WrongSubclass Is never thrown by this function.
335  */
336 double
338  return value_;
339 }
340 
341 //////////////////////////////////////////////////////////////////////////////
342 // BoolOptionValue
343 //////////////////////////////////////////////////////////////////////////////
344 
345 /**
346  * Constructor.
347  *
348  * @param value The value of boolean option.
349  */
351  value_ = value;
352 }
353 
354 /**
355  * Destructor.
356  */
358 }
359 
360 /**
361  * Sets new value for boolean option.
362  *
363  * @param value New value for the boolean option.
364  * @exception WrongSubclass Is never thrown by this function.
365  */
366 void
368  value_ = value;
369 }
370 
371 /**
372  * Returns the value of boolean option.
373  *
374  * @return The value of boolean option.
375  * @exception WrongSubclass Is never thrown by this function.
376  */
377 bool
379  return value_;
380 }
381 
382 /**
383  * Returns the negative value of boolean option.
384  *
385  * @return The negative value of boolean option.
386  * @exception WrongSubclass Is never thrown by this function.
387  */
388 bool
390  return !value_;
391 }
392 
393 //////////////////////////////////////////////////////////////////////////////
394 // IntegerListOptionValue
395 //////////////////////////////////////////////////////////////////////////////
396 
397 /**
398  * Constructor.
399  *
400  * @param value The values of integer list options.
401  */
403  values_ = values;
404 }
405 
406 /**
407  * Destructor.
408  */
410 }
411 
412 /**
413  * Sets new value for integer list option.
414  *
415  * @param value New value for the integer list option.
416  * @exception WrongSubclass Is never thrown by this function.
417  */
418 void
420  values_ = values;
421 }
422 
423 /**
424  * Returns the value from the given index of integer list.
425  *
426  * The index must be given between 0 and the size of value vector - 1
427  *
428  * @return The value from the given index of integer list.
429  * @exception WrongSubclass Is never thrown by this function.
430  * @exception OutOfRange If the index is out of the range.
431  */
432 int
434  if (index < 0 || static_cast<unsigned>(index) > values_.size() - 1) {
435  string procName = "IntegerListOptionValue::integerValue";
436  throw OutOfRange(__FILE__, __LINE__, procName);
437  }
438  return values_[index];
439 }
440 
441 /**
442  * Returns the size of the integer list.
443  *
444  * @return Size of hte list.
445  */
446 int
448  return values_.size();
449 }
450 
451 //////////////////////////////////////////////////////////////////////////////
452 // StringListOptionValue
453 //////////////////////////////////////////////////////////////////////////////
454 
455 /**
456  * Constructor.
457  *
458  * @param value The values of string list options.
459  */
460 StringListOptionValue::StringListOptionValue(std::vector<string> values) {
461  values_ = values;
462 }
463 
464 /**
465  * Destructor.
466  */
468 }
469 
470 /**
471  * Sets new value for string list option.
472  *
473  * @param value New value for the string list option.
474  * @exception WrongSubclass Is never thrown by this function.
475  */
476 void
477 StringListOptionValue::setStringListValue(std::vector<string> values) {
478  values_ = values;
479 }
480 
481 /**
482  * Returns the value from the given index of string list.
483  *
484  * The index must be given between 0 and the size of value vector - 1
485  *
486  * @return The value from the given index of string list.
487  * @exception WrongSubclass Is never thrown by this function.
488  * @exception OutOfRange If the index is out of the range.
489  */
490 std::string
492  if (index < 0 || static_cast<unsigned>(index) > values_.size() - 1) {
493  string procName = "StringListOptionValue::stringValue";
494  throw OutOfRange(__FILE__, __LINE__, procName);
495  }
496  return values_[index];
497 }
498 
499 /**
500  * Returns the size of the string list.
501  *
502  * @return Size of hte list.
503  */
504 int
506  return values_.size();
507 }
RealOptionValue::RealOptionValue
RealOptionValue(double value)
Definition: OptionValue.cc:309
StringOptionValue::StringOptionValue
StringOptionValue(const std::string value)
Definition: OptionValue.cc:267
BoolOptionValue::setBoolValue
virtual void setBoolValue(bool value)
Definition: OptionValue.cc:367
BoolOptionValue::value_
bool value_
The value of option.
Definition: OptionValue.hh:200
UnsignedIntegerOptionValue::setUnsignedIntegerValue
virtual void setUnsignedIntegerValue(unsigned value)
Definition: OptionValue.cc:249
OutOfRange
Definition: Exception.hh:320
IntegerOptionValue::value_
int value_
The value of option.
Definition: OptionValue.hh:99
IntegerListOptionValue::~IntegerListOptionValue
virtual ~IntegerListOptionValue()
Definition: OptionValue.cc:409
StringOptionValue::setStringValue
virtual void setStringValue(const std::string &value)
Definition: OptionValue.cc:284
OptionValue::setStringValue
virtual void setStringValue(const std::string &)
Definition: OptionValue.cc:66
StringOptionValue::stringValue
virtual std::string stringValue(int index=0) const
Definition: OptionValue.cc:296
StringListOptionValue::values_
std::vector< std::string > values_
The value of option.
Definition: OptionValue.hh:253
UnsignedIntegerOptionValue::value_
unsigned value_
The value of option.
Definition: OptionValue.hh:123
RealOptionValue::realValue
virtual double realValue() const
Definition: OptionValue.cc:337
IntegerOptionValue::setIntegerValue
virtual void setIntegerValue(int value)
Definition: OptionValue.cc:221
OptionValue::setRealValue
virtual void setRealValue(double)
Definition: OptionValue.cc:96
OptionValue::isFlagOff
virtual bool isFlagOff() const
Definition: OptionValue.cc:178
BoolOptionValue::~BoolOptionValue
virtual ~BoolOptionValue()
Definition: OptionValue.cc:357
IntegerOptionValue::~IntegerOptionValue
virtual ~IntegerOptionValue()
Definition: OptionValue.cc:211
RealOptionValue::setRealValue
virtual void setRealValue(double value)
Definition: OptionValue.cc:326
UnsignedIntegerOptionValue::UnsignedIntegerOptionValue
UnsignedIntegerOptionValue(unsigned value)
Definition: OptionValue.cc:241
OptionValue::isFlagOn
virtual bool isFlagOn() const
Definition: OptionValue.cc:166
IntegerListOptionValue::integerValue
virtual int integerValue(int index=0) const
Definition: OptionValue.cc:433
StringListOptionValue::~StringListOptionValue
virtual ~StringListOptionValue()
Definition: OptionValue.cc:467
BoolOptionValue::isFlagOff
virtual bool isFlagOff() const
Definition: OptionValue.cc:389
WrongSubclass
Definition: Exception.hh:336
UnsignedIntegerOptionValue::unsignedIntegerValue
virtual unsigned unsignedIntegerValue(int index=0) const
Definition: OptionValue.cc:254
IntegerListOptionValue::values_
std::vector< int > values_
The value of option.
Definition: OptionValue.hh:226
Application.hh
StringOptionValue::~StringOptionValue
virtual ~StringOptionValue()
Definition: OptionValue.cc:274
OptionValue::setIntegerListValue
virtual void setIntegerListValue(std::vector< int > values)
Definition: OptionValue.cc:117
__func__
#define __func__
Definition: Application.hh:67
BoolOptionValue::isFlagOn
virtual bool isFlagOn() const
Definition: OptionValue.cc:378
IntegerListOptionValue::listSize
virtual int listSize() const
Definition: OptionValue.cc:447
OptionValue::stringValue
virtual std::string stringValue(int index=0) const
Definition: OptionValue.cc:142
RealOptionValue::~RealOptionValue
virtual ~RealOptionValue()
Definition: OptionValue.cc:316
OptionValue::realValue
virtual double realValue() const
Definition: OptionValue.cc:154
UnsignedIntegerOptionValue::~UnsignedIntegerOptionValue
virtual ~UnsignedIntegerOptionValue()
Definition: OptionValue.cc:245
StringListOptionValue::listSize
virtual int listSize() const
Definition: OptionValue.cc:505
IntegerListOptionValue::setIntegerListValue
virtual void setIntegerListValue(std::vector< int > values)
Definition: OptionValue.cc:419
OptionValue::OptionValue
OptionValue()
Definition: OptionValue.cc:51
IntegerOptionValue::IntegerOptionValue
IntegerOptionValue(int value)
Definition: OptionValue.cc:204
OptionValue::setUnsignedIntegerValue
virtual void setUnsignedIntegerValue(unsigned)
Definition: OptionValue.cc:86
StringListOptionValue::StringListOptionValue
StringListOptionValue(std::vector< std::string > values)
Definition: OptionValue.cc:460
StringOptionValue::value_
std::string value_
The value of the option.
Definition: OptionValue.hh:147
IntegerOptionValue::integerValue
virtual int integerValue(int index=0) const
Definition: OptionValue.cc:233
OptionValue::setIntegerValue
virtual void setIntegerValue(int)
Definition: OptionValue.cc:76
OptionValue::~OptionValue
virtual ~OptionValue()
Definition: OptionValue.cc:57
StringListOptionValue::setStringListValue
virtual void setStringListValue(std::vector< std::string > values)
Definition: OptionValue.cc:477
OptionValue::setBoolValue
virtual void setBoolValue(bool)
Definition: OptionValue.cc:106
RealOptionValue::value_
double value_
The value of the option.
Definition: OptionValue.hh:172
OptionValue::listSize
virtual int listSize() const
Definition: OptionValue.cc:190
IntegerListOptionValue::IntegerListOptionValue
IntegerListOptionValue(std::vector< int > values)
Definition: OptionValue.cc:402
OptionValue.hh
BoolOptionValue::BoolOptionValue
BoolOptionValue(bool value)
Definition: OptionValue.cc:350
StringListOptionValue::stringValue
virtual std::string stringValue(int index=0) const
Definition: OptionValue.cc:491
OptionValue::integerValue
virtual int integerValue(int index=0) const
Definition: OptionValue.cc:129