Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanArrayKeyMap.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #if !defined(XALAN_ARRAYKEYMAP_HEADER_GUARD)
00017 #define XALAN_ARRAYKEYMAP_HEADER_GUARD
00018 
00019 
00020 
00021 #include <deque>
00022 #include <map>
00023 #include <vector>
00024 
00025 
00026 
00027 XALAN_CPP_NAMESPACE_BEGIN
00028 
00029 
00030 
00031 template<class KeyType, class ValueType, class CompareType>
00032 class XalanArrayKeyMap
00033 {
00034 public:
00035 
00036 #if defined(XALAN_NO_STD_NAMESPACE)
00037     typedef vector<KeyType>                                 VectorType;
00038     typedef map<const KeyType*, ValueType, CompareType>     MapType;
00039     typedef deque<VectorType>                               VectorHolderType;
00040 #else
00041     typedef std::vector<KeyType>                                VectorType;
00042     typedef std::map<const KeyType*, ValueType, CompareType>    MapType;
00043     typedef std::deque<VectorType>                              VectorHolderType;
00044 #endif
00045 
00046     typedef typename MapType::key_type                  key_type;
00047     typedef typename MapType::value_type                value_type;
00048     typedef ValueType                                   referent_type;
00049     typedef CompareType                                 key_compare;
00050 #if !defined(XALAN_NO_STD_ALLOCATORS)
00051     typedef typename MapType::allocator_type            allocator_type;
00052 #endif
00053     typedef typename MapType::size_type                 size_type;
00054     typedef typename MapType::difference_type           difference_type;
00055     typedef typename MapType::reference                 reference;
00056     typedef typename MapType::const_reference           const_reference;
00057     typedef typename MapType::iterator                  iterator;
00058     typedef typename MapType::const_iterator            const_iterator;
00059     typedef typename MapType::reverse_iterator          reverse_iterator;
00060     typedef typename MapType::const_reverse_iterator    const_reverse_iterator;
00061 
00062 #if defined(XALAN_NO_STD_NAMESPACE)
00063     typedef pair<iterator, bool>                    insert_pair_type;
00064     typedef pair<iterator, iterator>                range_pair_type;
00065     typedef pair<const_iterator, const_iterator>    const_range_pair_type;
00066 #else
00067     typedef std::pair<iterator, bool>                   insert_pair_type;
00068     typedef std::pair<iterator, iterator>               range_pair_type;
00069     typedef std::pair<const_iterator, const_iterator>   const_range_pair_type;
00070 #endif
00071 
00072     explicit
00073     XalanArrayKeyMap() :
00074         m_map(),
00075         m_keyData()
00076     {
00077     }
00078 
00079     XalanArrayKeyMap(const XalanArrayKeyMap<KeyType, ValueType, CompareType>&   theOther)
00080     {
00081         *this = theOther;
00082     }
00083 
00084     ~XalanArrayKeyMap()
00085     {
00086     }
00087 
00088     XalanArrayKeyMap<KeyType, ValueType, CompareType>&
00089     operator=(const XalanArrayKeyMap<KeyType, ValueType, CompareType>&  theRHS)
00090     {
00091         if (&theRHS != this)
00092         {
00093             XalanArrayKeyMap<KeyType, ValueType, CompareType>   theTemp;
00094 
00095             const const_iterator    theEnd =
00096                 theRHS.end();
00097 
00098             const_iterator  i = theRHS.begin();
00099 
00100             while(i != theEnd)
00101             {
00102                 theTemp.insert(*i);
00103 
00104                 ++i;
00105             }
00106 
00107             swap(theTemp);
00108         }
00109 
00110         return *this;
00111     }
00112 
00113     bool
00114     operator==(const XalanArrayKeyMap<KeyType, ValueType, CompareType>&     theRHS) const
00115     {
00116         return m_map == theRHS.m_map;
00117     }
00118 
00119     size_type
00120     size() const
00121     {
00122         return m_map.size();
00123     }
00124 
00125     size_type
00126     max_size() const
00127     {
00128         return m_map.max_size();
00129     }
00130 
00131     bool
00132     empty() const
00133     {
00134         return m_map.empty();
00135     }
00136 
00137     iterator
00138     begin()
00139     {
00140         return m_map.begin();
00141     }
00142 
00143     const_iterator
00144     begin() const
00145     {
00146         return m_map.begin();
00147     }
00148 
00149     iterator
00150     end()
00151     {
00152         return m_map.end();
00153     }
00154 
00155     const_iterator
00156     end() const
00157     {
00158         return m_map.end();
00159     }
00160 
00161     reverse_iterator
00162     rbegin()
00163     {
00164         return m_map.rbegin();
00165     }
00166 
00167     const_reverse_iterator
00168     rbegin() const
00169     {
00170         return m_map.rbegin();
00171     }
00172 
00173     reverse_iterator
00174     rend()
00175     {
00176         return m_map.rend();
00177     }
00178 
00179     const_reverse_iterator
00180     rend() const
00181     {
00182         return m_map.rend();
00183     }
00184 
00185     insert_pair_type
00186     insert(const value_type&    thePair)
00187     {
00188         m_keyData.push_back(VectorHolderType::value_type(thePair.first, thePair.first + (length(thePair.first) + 1)));
00189 
00190         return m_map.insert(value_type(&*m_keyData.back().begin(), thePair.second));
00191     }
00192 
00193     referent_type&
00194     operator[](const key_type&  theKey)
00195     {
00196         const iterator  i = find(theKey);
00197 
00198         if (i == end())
00199         {
00200             return (*(insert(value_type(theKey, referent_type()))).first).second;
00201         }
00202         else
00203         {
00204             return (*i).second;
00205         }
00206     }
00207 
00208     iterator
00209     find(const key_type&    theKey)
00210     {
00211         return m_map.find(theKey);
00212     }
00213 
00214     const_iterator
00215     find(const key_type&    theKey) const
00216     {
00217         return m_map.find(theKey);
00218     }
00219 
00220     iterator
00221     lower_bound(const key_type&     theKey)
00222     {
00223         return m_map.lower_bound(theKey);
00224     }
00225 
00226     const_iterator
00227     lower_bound(const key_type&     theKey) const
00228     {
00229         return m_map.lower_bound(theKey);
00230     }
00231 
00232     iterator
00233     upper_bound(const key_type&     theKey)
00234     {
00235         return m_map.upper_bound(theKey);
00236     }
00237 
00238     const_iterator
00239     upper_bound(const key_type&     theKey) const
00240     {
00241         return m_map.upper_bound(theKey);
00242     }
00243 
00244     range_pair_type
00245     equal_range(const key_type&     theKey)
00246     {
00247         return m_map.equal_range(theKey);
00248     }
00249 
00250     const_range_pair_type
00251     equal_range(const key_type&     theKey) const
00252     {
00253         return m_map.equal_range(theKey);
00254     }
00255 
00256 #if defined(XALAN_STLPORT_STL) && !defined(__STL_MEMBER_TEMPLATES)
00257     void
00258     erase(iterator  theIterator)
00259     {
00260         // $$$ ToDo: Does not empty vector in the
00261         // deque!!!
00262         m_map.erase(theIterator);
00263     }
00264 
00265     void
00266     erase(
00267             iterator    theFirst,
00268             iterator    theLast)
00269     {
00270         // $$$ ToDo: Does not empty vector in the
00271         // deque!!!
00272         m_map.erase(theFirst, theLast);
00273     }
00274 #else
00275     iterator
00276     erase(iterator  theIterator)
00277     {
00278         // $$$ ToDo: Does not empty vector in the
00279         // deque!!!
00280         return m_map.erase(theIterator);
00281     }
00282 
00283     iterator
00284     erase(
00285             iterator    theFirst,
00286             iterator    theLast)
00287     {
00288         // $$$ ToDo: Does not empty vector in the
00289         // deque!!!
00290         return m_map.erase(theFirst, theLast);
00291     }
00292 #endif
00293 
00294     size_type
00295     erase(const key_type&   theKey)
00296     {
00297         // $$$ ToDo: Does not empty vector in the
00298         // deque!!!
00299         return m_map.erase(theKey);
00300     }
00301 
00302     void
00303     swap(XalanArrayKeyMap<KeyType, ValueType, CompareType>&     theOther)
00304     {
00305         m_map.swap(theOther.m_map);
00306 
00307         m_keyData.swap(theOther.m_keyData);
00308     }
00309 
00310 private:
00311 
00312     size_type
00313     length(const key_type&  theKey)
00314     {
00315         key_type    theCurrent = theKey;
00316 
00317         while(*theCurrent != 0)
00318         {
00319             ++theCurrent;
00320         }
00321 
00322         return theCurrent - theKey;
00323     }
00324 
00325     MapType             m_map;
00326 
00327     VectorHolderType    m_keyData;
00328 };
00329 
00330 
00331 
00332 XALAN_CPP_NAMESPACE_END
00333 
00334 
00335 
00336 #endif

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo