Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ListOption.h
1 /*
2  * $Id$
3  * ListOption class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2010, IRIT UPS.
7  *
8  * OTAWA is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * OTAWA is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with OTAWA; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 #ifndef ELM_OPTION_LISTOPTION_H_
23 #define ELM_OPTION_LISTOPTION_H_
24 
25 #include <elm/option/ValueOption.h>
26 #include <elm/genstruct/Vector.h>
27 
28 namespace elm { namespace option {
29 
30 // ListOption class
31 template <class T>
33 public:
34 
35  ListOption(Manager& man, int tag, ...): AbstractValueOption(man)
36  { VARARG_BEGIN(args, tag) init(man, tag, args); VARARG_END }
37  ListOption(Manager& man, int tag, VarArg& args)
38  : AbstractValueOption(man, tag, args) { }
39  ListOption(const Make& make)
40  : AbstractValueOption(make) { }
41 
42  inline const T& get(int index) const { return vals[index]; };
43  inline void set(int index, const T& value) { vals[index] = value; };
44  inline T& ref(int index) { return vals[index]; }
45  inline void add(const T& val) { vals.add(val); }
46  inline void remove(int index) { vals.removeAt(index); }
47  inline int count(void) const { return vals.count(); }
48 
49  // Operators
50  inline operator bool(void) const { return !vals.isEmpty(); }
51  inline const T& operator[](int index) const { return vals[index]; }
52  inline T& operator[](int index) { return vals[index]; }
53 
54  // Option overload
55  virtual void process(String arg) { vals.add(read<T>(arg)); }
56 private:
58 };
59 
60 } } // elm::option
61 
62 #endif /* ELM_OPTION_LISTOPTION_H_ */
Definition: ValueOption.h:31
ListOption(Manager &man, int tag, VarArg &args)
Definition: ListOption.h:37
void init(Manager &manager, int tag,...)
Definition: option_Option.cpp:51
void set(int index, const T &value)
Definition: ListOption.h:43
Definition: VarArg.h:25
ListOption(const Make &make)
Definition: ListOption.h:39
Definition: Manager.h:59
ListOption(Manager &man, int tag,...)
Definition: ListOption.h:35
value_t value(CString name, int value)
Definition: rtti.h:40
T & ref(int index)
Definition: ListOption.h:44
virtual void process(String arg)
Definition: ListOption.h:55
int count(void) const
Definition: ListOption.h:47
Definition: ListOption.h:32
void add(const T &val)
Definition: ListOption.h:45
Definition: Option.h:46
T & operator[](int index)
Definition: ListOption.h:52
Definition: String.h:31
Definition: Vector.h:35
const T & operator[](int index) const
Definition: ListOption.h:51