00001 /* 00002 * The Apache Software License, Version 1.1 00003 * 00004 * 00005 * Copyright (c) 1999-2000 The Apache Software Foundation. All rights 00006 * reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * 1. Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in 00017 * the documentation and/or other materials provided with the 00018 * distribution. 00019 * 00020 * 3. The end-user documentation included with the redistribution, 00021 * if any, must include the following acknowledgment: 00022 * "This product includes software developed by the 00023 * Apache Software Foundation (http://www.apache.org/)." 00024 * Alternately, this acknowledgment may appear in the software itself, 00025 * if and wherever such third-party acknowledgments normally appear. 00026 * 00027 * 4. The names "Xalan" and "Apache Software Foundation" must 00028 * not be used to endorse or promote products derived from this 00029 * software without prior written permission. For written 00030 * permission, please contact apache@apache.org. 00031 * 00032 * 5. Products derived from this software may not be called "Apache", 00033 * nor may "Apache" appear in their name, without prior written 00034 * permission of the Apache Software Foundation. 00035 * 00036 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 00037 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00038 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00039 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 00040 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00041 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00042 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 00043 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00044 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00045 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00046 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00047 * SUCH DAMAGE. 00048 * ==================================================================== 00049 * 00050 * This software consists of voluntary contributions made by many 00051 * individuals on behalf of the Apache Software Foundation and was 00052 * originally based on software copyright (c) 1999, International 00053 * Business Machines, Inc., http://www.ibm.com. For more 00054 * information on the Apache Software Foundation, please see 00055 * <http://www.apache.org/>. 00056 */ 00057 #if !defined(XALAN_ARRAYKEYMAP_HEADER_GUARD) 00058 #define XALAN_ARRAYKEYMAP_HEADER_GUARD 00059 00060 00061 00062 #include <deque> 00063 #include <map> 00064 #include <vector> 00065 00066 00067 00068 template<class KeyType, class ValueType, class CompareType> 00069 class XalanArrayKeyMap 00070 { 00071 public: 00072 00073 #if defined(XALAN_NO_NAMESPACES) 00074 typedef vector<KeyType> VectorType; 00075 typedef map<const KeyType*, ValueType, CompareType> MapType; 00076 typedef deque<VectorType> VectorHolderType; 00077 #else 00078 typedef std::vector<KeyType> VectorType; 00079 typedef std::map<const KeyType*, ValueType, CompareType> MapType; 00080 typedef std::deque<VectorType> VectorHolderType; 00081 #endif 00082 00083 typedef typename MapType::key_type key_type; 00084 typedef typename MapType::value_type value_type; 00085 typedef ValueType referent_type; 00086 typedef CompareType key_compare; 00087 #if !defined(XALAN_NO_STD_ALLOCATORS) 00088 typedef typename MapType::allocator_type allocator_type; 00089 #endif 00090 typedef typename MapType::size_type size_type; 00091 typedef typename MapType::difference_type difference_type; 00092 typedef typename MapType::reference reference; 00093 typedef typename MapType::const_reference const_reference; 00094 typedef typename MapType::iterator iterator; 00095 typedef typename MapType::const_iterator const_iterator; 00096 typedef typename MapType::reverse_iterator reverse_iterator; 00097 typedef typename MapType::const_reverse_iterator const_reverse_iterator; 00098 00099 #if defined(XALAN_NO_NAMESPACES) 00100 typedef pair<iterator, bool> insert_pair_type; 00101 typedef pair<iterator, iterator> range_pair_type; 00102 typedef pair<const_iterator, const_iterator> const_range_pair_type; 00103 #else 00104 typedef std::pair<iterator, bool> insert_pair_type; 00105 typedef std::pair<iterator, iterator> range_pair_type; 00106 typedef std::pair<const_iterator, const_iterator> const_range_pair_type; 00107 #endif 00108 00109 explicit 00110 XalanArrayKeyMap() : 00111 m_map(), 00112 m_keyData() 00113 { 00114 } 00115 00116 XalanArrayKeyMap(const XalanArrayKeyMap<KeyType, ValueType, CompareType>& theOther) 00117 { 00118 *this = theOther; 00119 } 00120 00121 ~XalanArrayKeyMap() 00122 { 00123 } 00124 00125 XalanArrayKeyMap<KeyType, ValueType, CompareType>& 00126 operator=(const XalanArrayKeyMap<KeyType, ValueType, CompareType>& theRHS) 00127 { 00128 if (&theRHS != this) 00129 { 00130 XalanArrayKeyMap<KeyType, ValueType, CompareType> theTemp; 00131 00132 const const_iterator theEnd = 00133 theRHS.end(); 00134 00135 const_iterator i = theRHS.begin(); 00136 00137 while(i != theEnd) 00138 { 00139 theTemp.insert(*i); 00140 00141 ++i; 00142 } 00143 00144 swap(theTemp); 00145 } 00146 00147 return *this; 00148 } 00149 00150 bool 00151 operator==(const XalanArrayKeyMap<KeyType, ValueType, CompareType>& theRHS) const 00152 { 00153 return m_map == theRHS.m_map; 00154 } 00155 00156 size_type 00157 size() const 00158 { 00159 return m_map.size(); 00160 } 00161 00162 size_type 00163 max_size() const 00164 { 00165 return m_map.max_size(); 00166 } 00167 00168 bool 00169 empty() const 00170 { 00171 return m_map.empty(); 00172 } 00173 00174 iterator 00175 begin() 00176 { 00177 return m_map.begin(); 00178 } 00179 00180 const_iterator 00181 begin() const 00182 { 00183 return m_map.begin(); 00184 } 00185 00186 iterator 00187 end() 00188 { 00189 return m_map.end(); 00190 } 00191 00192 const_iterator 00193 end() const 00194 { 00195 return m_map.end(); 00196 } 00197 00198 reverse_iterator 00199 rbegin() 00200 { 00201 return m_map.rbegin(); 00202 } 00203 00204 const_reverse_iterator 00205 rbegin() const 00206 { 00207 return m_map.rbegin(); 00208 } 00209 00210 reverse_iterator 00211 rend() 00212 { 00213 return m_map.rend(); 00214 } 00215 00216 const_reverse_iterator 00217 rend() const 00218 { 00219 return m_map.rend(); 00220 } 00221 00222 insert_pair_type 00223 insert(const value_type& thePair) 00224 { 00225 m_keyData.push_back(VectorHolderType::value_type(thePair.first, thePair.first + (length(thePair.first) + 1))); 00226 00227 return m_map.insert(value_type(&*m_keyData.back().begin(), thePair.second)); 00228 } 00229 00230 referent_type& 00231 operator[](const key_type& theKey) 00232 { 00233 const iterator i = find(theKey); 00234 00235 if (i == end()) 00236 { 00237 return (*(insert(value_type(theKey, referent_type()))).first).second; 00238 } 00239 else 00240 { 00241 return (*i).second; 00242 } 00243 } 00244 00245 iterator 00246 find(const key_type& theKey) 00247 { 00248 return m_map.find(theKey); 00249 } 00250 00251 const_iterator 00252 find(const key_type& theKey) const 00253 { 00254 return m_map.find(theKey); 00255 } 00256 00257 iterator 00258 lower_bound(const key_type& theKey) 00259 { 00260 return m_map.lower_bound(theKey); 00261 } 00262 00263 const_iterator 00264 lower_bound(const key_type& theKey) const 00265 { 00266 return m_map.lower_bound(theKey); 00267 } 00268 00269 iterator 00270 upper_bound(const key_type& theKey) 00271 { 00272 return m_map.upper_bound(theKey); 00273 } 00274 00275 const_iterator 00276 upper_bound(const key_type& theKey) const 00277 { 00278 return m_map.upper_bound(theKey); 00279 } 00280 00281 range_pair_type 00282 equal_range(const key_type& theKey) 00283 { 00284 return m_map.equal_range(theKey); 00285 } 00286 00287 const_range_pair_type 00288 equal_range(const key_type& theKey) const 00289 { 00290 return m_map.equal_range(theKey); 00291 } 00292 00293 #if defined(XALAN_STLPORT_STL) && !defined(__STL_MEMBER_TEMPLATES) 00294 void 00295 erase(iterator theIterator) 00296 { 00297 // $$$ ToDo: Does not empty vector in the 00298 // deque!!! 00299 m_map.erase(theIterator); 00300 } 00301 00302 void 00303 erase( 00304 iterator theFirst, 00305 iterator theLast) 00306 { 00307 // $$$ ToDo: Does not empty vector in the 00308 // deque!!! 00309 m_map.erase(theFirst, theLast); 00310 } 00311 #else 00312 iterator 00313 erase(iterator theIterator) 00314 { 00315 // $$$ ToDo: Does not empty vector in the 00316 // deque!!! 00317 return m_map.erase(theIterator); 00318 } 00319 00320 iterator 00321 erase( 00322 iterator theFirst, 00323 iterator theLast) 00324 { 00325 // $$$ ToDo: Does not empty vector in the 00326 // deque!!! 00327 return m_map.erase(theFirst, theLast); 00328 } 00329 #endif 00330 00331 size_type 00332 erase(const key_type& theKey) 00333 { 00334 // $$$ ToDo: Does not empty vector in the 00335 // deque!!! 00336 return m_map.erase(theKey); 00337 } 00338 00339 void 00340 swap(XalanArrayKeyMap<KeyType, ValueType, CompareType>& theOther) 00341 { 00342 m_map.swap(theOther.m_map); 00343 00344 m_keyData.swap(theOther.m_keyData); 00345 } 00346 00347 private: 00348 00349 size_type 00350 length(const key_type& theKey) 00351 { 00352 key_type theCurrent = theKey; 00353 00354 while(*theCurrent != 0) 00355 { 00356 ++theCurrent; 00357 } 00358 00359 return theCurrent - theKey; 00360 } 00361 00362 MapType m_map; 00363 00364 VectorHolderType m_keyData; 00365 }; 00366 00367 00368 00369 #endif
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
![]() |
Xalan-C++ XSLT Processor Version 1.4 |
|