Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: Mon Jun 11 2012 00003 author: Paul D Turner <paul@cegui.org.uk> 00004 *************************************************************************/ 00005 /*************************************************************************** 00006 * Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining 00009 * a copy of this software and associated documentation files (the 00010 * "Software"), to deal in the Software without restriction, including 00011 * without limitation the rights to use, copy, modify, merge, publish, 00012 * distribute, sublicense, and/or sell copies of the Software, and to 00013 * permit persons to whom the Software is furnished to do so, subject to 00014 * the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be 00017 * included in all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00020 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00022 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00023 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00024 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00025 * OTHER DEALINGS IN THE SOFTWARE. 00026 ***************************************************************************/ 00027 #ifndef _CEGUINamedDefinitionCollator_h_ 00028 #define _CEGUINamedDefinitionCollator_h_ 00029 00030 #include "CEGUI/Base.h" 00031 #include <vector> 00032 #include <algorithm> 00033 00034 #if defined(_MSC_VER) 00035 # pragma warning(push) 00036 # pragma warning(disable : 4251) 00037 #endif 00038 00039 namespace CEGUI 00040 { 00046 template<typename K, typename V> 00047 class NamedDefinitionCollator 00048 { 00049 public: 00050 typedef V value_type; 00051 00053 size_t size() const 00054 { return d_values.size(); } 00055 00057 V& at(size_t idx) 00058 { return d_values.at(idx).second; } 00059 00061 const V& at(size_t idx) const 00062 { return d_values.at(idx).second; } 00063 00070 void set(const K& key, const V& val) 00071 { 00072 typename ValueArray::iterator i = 00073 std::find_if(d_values.begin(), d_values.end(), pred(key)); 00074 00075 if (i != d_values.end()) 00076 d_values.erase(i); 00077 00078 d_values.push_back(std::make_pair(key, val)); 00079 } 00080 00081 protected: 00082 typedef std::pair<K, V> Entry; 00083 typedef std::vector<Entry CEGUI_VECTOR_ALLOC(Entry)> ValueArray; 00084 00085 struct pred 00086 { 00087 const K& d_k; 00088 pred(const K& k) : d_k(k) {} 00089 bool operator()(const Entry& e) 00090 { return e.first == d_k; } 00091 }; 00092 00093 ValueArray d_values; 00094 00095 public: 00099 class const_iterator 00100 { 00101 public: 00102 const_iterator(typename ValueArray::const_iterator i) : 00103 d_iter(i) {} 00104 00105 const_iterator(const const_iterator& iter) : 00106 d_iter(iter.d_iter) {} 00107 00108 const_iterator() 00109 {} 00110 00111 const V& operator*() const 00112 { return d_iter->second; } 00113 00114 const V* operator->() const 00115 { return &**this; } 00116 00117 bool operator==(const const_iterator& iter) const 00118 { return d_iter == iter.d_iter; } 00119 00120 bool operator!=(const const_iterator& iter) const 00121 { return !operator==(iter); } 00122 00123 const_iterator& operator++() 00124 { 00125 ++d_iter; 00126 return *this; 00127 } 00128 00129 const_iterator& operator++(int) 00130 { 00131 const_iterator& tmp = *this; 00132 ++*this; 00133 return tmp; 00134 } 00135 00136 const_iterator& operator--() 00137 { 00138 --d_iter; 00139 return *this; 00140 } 00141 00142 const_iterator& operator--(int) 00143 { 00144 const_iterator& tmp = *this; 00145 --*this; 00146 return tmp; 00147 } 00148 00149 const_iterator& operator=(const const_iterator& iter) 00150 { 00151 d_iter = iter.d_iter; 00152 return *this; 00153 } 00154 00155 protected: 00156 typename ValueArray::const_iterator d_iter; 00157 }; 00158 00159 const_iterator begin() const 00160 { return const_iterator(d_values.begin()); } 00161 00162 const_iterator end() const 00163 { return const_iterator(d_values.end()); } 00164 00165 const_iterator find(const K& key) const 00166 { 00167 return const_iterator(std::find_if(d_values.begin(), 00168 d_values.end(), 00169 pred(key))); 00170 } 00171 00172 }; 00173 00174 } 00175 00176 #if defined(_MSC_VER) 00177 # pragma warning(pop) 00178 #endif 00179 00180 #endif 00181