Crazy Eddie's GUI System 0.8.7
NamedDefinitionCollator.h
1/***********************************************************************
2 created: Mon Jun 11 2012
3 author: Paul D Turner <paul@cegui.org.uk>
4*************************************************************************/
5/***************************************************************************
6 * Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27#ifndef _CEGUINamedDefinitionCollator_h_
28#define _CEGUINamedDefinitionCollator_h_
29
30#include "CEGUI/Base.h"
31#include <vector>
32#include <algorithm>
33
34#if defined(_MSC_VER)
35# pragma warning(push)
36# pragma warning(disable : 4251)
37#endif
38
39namespace CEGUI
40{
46template<typename K, typename V>
48{
49public:
50 typedef V value_type;
51
53 size_t size() const
54 { return d_values.size(); }
55
57 V& at(size_t idx)
58 { return d_values.at(idx).second; }
59
61 const V& at(size_t idx) const
62 { return d_values.at(idx).second; }
63
70 void set(const K& key, const V& val)
71 {
72 typename ValueArray::iterator i =
73 std::find_if(d_values.begin(), d_values.end(), pred(key));
74
75 if (i != d_values.end())
76 d_values.erase(i);
77
78 d_values.push_back(std::make_pair(key, val));
79 }
80
81protected:
82 typedef std::pair<K, V> Entry;
83 typedef std::vector<Entry CEGUI_VECTOR_ALLOC(Entry)> ValueArray;
84
85 struct pred
86 {
87 const K& d_k;
88 pred(const K& k) : d_k(k) {}
89 bool operator()(const Entry& e)
90 { return e.first == d_k; }
91 };
92
93 ValueArray d_values;
94
95public:
100 {
101 public:
102 const_iterator(typename ValueArray::const_iterator i) :
103 d_iter(i) {}
104
105 const_iterator(const const_iterator& iter) :
106 d_iter(iter.d_iter) {}
107
109 {}
110
111 const V& operator*() const
112 { return d_iter->second; }
113
114 const V* operator->() const
115 { return &**this; }
116
117 bool operator==(const const_iterator& iter) const
118 { return d_iter == iter.d_iter; }
119
120 bool operator!=(const const_iterator& iter) const
121 { return !operator==(iter); }
122
123 const_iterator& operator++()
124 {
125 ++d_iter;
126 return *this;
127 }
128
129 const_iterator& operator++(int)
130 {
131 const_iterator& tmp = *this;
132 ++*this;
133 return tmp;
134 }
135
136 const_iterator& operator--()
137 {
138 --d_iter;
139 return *this;
140 }
141
142 const_iterator& operator--(int)
143 {
144 const_iterator& tmp = *this;
145 --*this;
146 return tmp;
147 }
148
149 const_iterator& operator=(const const_iterator& iter)
150 {
151 d_iter = iter.d_iter;
152 return *this;
153 }
154
155 protected:
156 typename ValueArray::const_iterator d_iter;
157 };
158
159 const_iterator begin() const
160 { return const_iterator(d_values.begin()); }
161
162 const_iterator end() const
163 { return const_iterator(d_values.end()); }
164
165 const_iterator find(const K& key) const
166 {
167 return const_iterator(std::find_if(d_values.begin(),
168 d_values.end(),
169 pred(key)));
170 }
171
172};
173
174}
175
176#if defined(_MSC_VER)
177# pragma warning(pop)
178#endif
179
180#endif
181
Definition: NamedDefinitionCollator.h:100
Helper container used to implement inherited collections of component definitions specified in a Widg...
Definition: NamedDefinitionCollator.h:48
V & at(size_t idx)
return reference to value at given index.
Definition: NamedDefinitionCollator.h:57
void set(const K &key, const V &val)
Set value for a given key. If a value is already associated with the given key, it is replaced with t...
Definition: NamedDefinitionCollator.h:70
const V & at(size_t idx) const
return const reference to value at given index.
Definition: NamedDefinitionCollator.h:61
size_t size() const
Return total number of values in the collection.
Definition: NamedDefinitionCollator.h:53
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Definition: NamedDefinitionCollator.h:86