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
BoolTable.h
1 /*
2  * $Id$
3  * Plugin class interface
4  *
5  * This file is part of OTAWA
6  * Copyright (c) 2007, 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_GENSTRUCT_BOOLTABLE_H
23 #define ELM_GENSTRUCT_BOOLTABLE_H
24 
25 #include <elm/util/BitVector.h>
26 #include <elm/genstruct/Table.h>
27 #include <elm/util/delegate.h>
28 
29 namespace elm { namespace genstruct {
30 
31 
32 // Table<bool> class
33 template <>
34 class Table<bool> {
35 public:
37 
38  inline Table(bool *table, int count): bvec(count)
39  { for(int i = 0; i < count; i++) if(table[i]) bvec.set(i); }
40  inline Table(const Table<bool>& table): bvec(table.bvec.size())
41  { copy(table); }
42 
43  // Accessors
44  typedef ArrayDelegate<Table<bool>, int, bool> delegate_t;
45  inline int count(void) const { return bvec.size(); }
46  inline bool get(int index) const { return bvec.bit(index); }
47  inline delegate_t get(int index) { return delegate_t(*this, index); }
48  inline void set(int index, bool value) { bvec.set(index, value); }
49  inline bool isEmpty(void) const { return bvec.isEmpty(); }
50 
51  // Mutators
52  inline void copy(const Table<bool>& table) { bvec = table.bvec; }
53 
54  // Operators
55  inline bool operator[](int index) const { return get(index); }
56  inline delegate_t operator[](int index) { return get(index); }
58  { copy(table); return *this; }
59  inline operator bool(void) const { return !isEmpty(); }
60 
61 protected:
63  inline Table(void) { }
64 };
65 
66 
67 // AllocatedTable<bool> class
68 template <>
69 class AllocatedTable<bool>: public Table<bool> {
70 public:
71  inline AllocatedTable(void) { }
72  inline AllocatedTable(int count) { allocate(count); }
73  inline AllocatedTable(const Table<bool>& table): Table<bool>(table) { }
74 
75  inline void allocate(int count) { bvec.resize(count); }
76  inline void free(void) { }
77  inline void copy(const AllocatedTable<bool>& table)
78  { bvec.copy(table.bvec); }
80  { copy(table); return *this; }
81 };
82 
83 } } // elm::genstruct
84 
85 #endif /* ELM_GENSTRUCT_BOOLTABLE_H */
AllocatedTable< bool > & operator=(const AllocatedTable< bool > &table)
Definition: BoolTable.h:79
bool operator[](int index) const
Definition: BoolTable.h:55
Definition: BoolTable.h:69
static Table< bool > EMPTY
Definition: BoolTable.h:36
int size(void) const
Definition: Table.h:43
void free(void)
Definition: BoolTable.h:76
Table(const Table< bool > &table)
Definition: BoolTable.h:40
Definition: Table.h:33
AllocatedTable(const Table< bool > &table)
Definition: BoolTable.h:73
Definition: Table.h:130
ArrayDelegate< Table< bool >, int, bool > delegate_t
Definition: BoolTable.h:44
Definition: delegate.h:29
Definition: BoolTable.h:34
Definition: BitVector.h:33
value_t value(CString name, int value)
Definition: rtti.h:40
void copy(const Table< T > &table)
Definition: Table.h:53
Table< bool > & operator=(const Table< bool > &table)
Definition: BoolTable.h:57
void copy(const AllocatedTable< bool > &table)
Definition: BoolTable.h:77
void allocate(int count)
Definition: Table.h:107
void set(int index, bool value)
Definition: BoolTable.h:48
void allocate(int count)
Definition: BoolTable.h:75
delegate_t operator[](int index)
Definition: BoolTable.h:56
int count(void) const
Definition: Table.h:71
BitVector bvec
Definition: BoolTable.h:62
bool isEmpty(void) const
Definition: BoolTable.h:49
Table(bool *table, int count)
Definition: BoolTable.h:38
AllocatedTable(int count)
Definition: BoolTable.h:72
Definition: Table.h:98
bool isEmpty(void) const
Definition: Table.h:50
void copy(const Table< bool > &table)
Definition: BoolTable.h:52
AllocatedTable(void)
Definition: BoolTable.h:71
int count(void) const
Definition: BoolTable.h:45
Table(void)
Definition: BoolTable.h:63