Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
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/data/Vector.h>
27 
28 namespace elm { namespace option {
29 
30 // ListOption class
31 template <class T>
33 public:
34 
35  ListOption(const Make& make)
36  : AbstractValueOption(make) { }
37 
38  inline const T& get(int index) const { return vals[index]; };
39  inline void set(int index, const T& value) { vals[index] = value; };
40  inline T& ref(int index) { return vals[index]; }
41  inline void add(const T& val) { vals.add(val); }
42  inline void remove(int index) { vals.removeAt(index); }
43  inline int count(void) const { return vals.count(); }
44 
45  // Operators
46  inline operator bool(void) const { return !vals.isEmpty(); }
47  inline const T& operator[](int index) const { return vals[index]; }
48  inline T& operator[](int index) { return vals[index]; }
49  inline typename Vector<T>::Iter begin() const { return vals.begin(); }
50  inline typename Vector<T>::Iter end() const { return vals.end(); }
51 
52  // Option overload
53  virtual void process(String arg) { vals.add(read<T>(arg)); }
54 private:
55  Vector<T> vals;
56 };
57 
58 } } // elm::option
59 
60 #endif /* ELM_OPTION_LISTOPTION_H_ */
elm::option::ListOption::ref
T & ref(int index)
Definition: ListOption.h:40
elm::option::ListOption::end
Vector< T >::Iter end() const
Definition: ListOption.h:50
elm::option::AbstractValueOption
Definition: ValueOption.h:31
elm::Vector::count
int count(void) const
Definition: Vector.h:81
elm::option::ListOption::get
const T & get(int index) const
Definition: ListOption.h:38
elm::Vector::begin
Iter begin(void) const
Definition: Vector.h:88
elm::option::ListOption::operator[]
T & operator[](int index)
Definition: ListOption.h:48
elm::option::ListOption::set
void set(int index, const T &value)
Definition: ListOption.h:39
elm::option::ListOption::add
void add(const T &val)
Definition: ListOption.h:41
elm::option::ListOption::remove
void remove(int index)
Definition: ListOption.h:42
elm::option::ListOption::ListOption
ListOption(const Make &make)
Definition: ListOption.h:35
elm::option::ListOption::count
int count(void) const
Definition: ListOption.h:43
value
bool
elm::option::ListOption::operator[]
const T & operator[](int index) const
Definition: ListOption.h:47
elm::option::Option::Make
Definition: Option.h:52
elm::option::ListOption
Definition: ListOption.h:32
elm
Definition: adapter.h:26
elm::Vector::add
void add(const T &v)
Definition: Vector.h:101
elm::Vector
Definition: Vector.h:34
elm::Vector::end
Iter end(void) const
Definition: Vector.h:89
elm::String
Definition: String.h:30
elm::option::ListOption::process
virtual void process(String arg)
Definition: ListOption.h:53
elm::option::ListOption::begin
Vector< T >::Iter begin() const
Definition: ListOption.h:49
elm::Vector::isEmpty
bool isEmpty(void) const
Definition: Vector.h:86
elm::Vector::removeAt
void removeAt(int i)
Definition: Vector.h:143