1*6df1ea1fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6df1ea1fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6df1ea1fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6df1ea1fSAndrew Rist * distributed with this work for additional information 6*6df1ea1fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6df1ea1fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6df1ea1fSAndrew Rist * "License"); you may not use this file except in compliance 9*6df1ea1fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6df1ea1fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6df1ea1fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6df1ea1fSAndrew Rist * software distributed under the License is distributed on an 15*6df1ea1fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6df1ea1fSAndrew Rist * KIND, either express or implied. See the License for the 17*6df1ea1fSAndrew Rist * specific language governing permissions and limitations 18*6df1ea1fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6df1ea1fSAndrew Rist *************************************************************/ 21*6df1ea1fSAndrew Rist 22*6df1ea1fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _UCB_REGEXPMAP_HXX_ 25cdf0e10cSrcweir #define _UCB_REGEXPMAP_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <rtl/ustring.hxx> 28cdf0e10cSrcweir #include <sal/types.h> 29cdf0e10cSrcweir 30cdf0e10cSrcweir namespace ucb_impl { 31cdf0e10cSrcweir 32cdf0e10cSrcweir template< typename Val > class RegexpMap; 33cdf0e10cSrcweir template< typename Val > class RegexpMapIter; 34cdf0e10cSrcweir 35cdf0e10cSrcweir //============================================================================ 36cdf0e10cSrcweir template< typename Val > 37cdf0e10cSrcweir class RegexpMapEntry 38cdf0e10cSrcweir { 39cdf0e10cSrcweir public: 40cdf0e10cSrcweir inline RegexpMapEntry(rtl::OUString const & rTheRegexp, 41cdf0e10cSrcweir Val * pTheValue): 42cdf0e10cSrcweir m_aRegexp(rTheRegexp), m_pValue(pTheValue) {} 43cdf0e10cSrcweir 44cdf0e10cSrcweir rtl::OUString getRegexp() const { return m_aRegexp; } 45cdf0e10cSrcweir 46cdf0e10cSrcweir Val const & getValue() const { return *m_pValue; } 47cdf0e10cSrcweir 48cdf0e10cSrcweir Val & getValue() { return *m_pValue; } 49cdf0e10cSrcweir 50cdf0e10cSrcweir private: 51cdf0e10cSrcweir rtl::OUString m_aRegexp; 52cdf0e10cSrcweir Val * m_pValue; 53cdf0e10cSrcweir }; 54cdf0e10cSrcweir 55cdf0e10cSrcweir //============================================================================ 56cdf0e10cSrcweir template< typename Val > class RegexpMapIterImpl; 57cdf0e10cSrcweir // MSC doesn't like this to be a private RegexpMapConstIter member 58cdf0e10cSrcweir // class... 59cdf0e10cSrcweir 60cdf0e10cSrcweir template< typename Val > 61cdf0e10cSrcweir class RegexpMapConstIter 62cdf0e10cSrcweir { 63cdf0e10cSrcweir friend class RegexpMap< Val >; // to access m_pImpl, ctor 64cdf0e10cSrcweir friend class RegexpMapIter< Val >; // to access m_pImpl, ctor 65cdf0e10cSrcweir 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir RegexpMapConstIter(); 68cdf0e10cSrcweir 69cdf0e10cSrcweir RegexpMapConstIter(RegexpMapConstIter const & rOther); 70cdf0e10cSrcweir 71cdf0e10cSrcweir ~RegexpMapConstIter(); 72cdf0e10cSrcweir 73cdf0e10cSrcweir RegexpMapConstIter & operator =(RegexpMapConstIter const & rOther); 74cdf0e10cSrcweir 75cdf0e10cSrcweir RegexpMapConstIter & operator ++(); 76cdf0e10cSrcweir 77cdf0e10cSrcweir RegexpMapConstIter operator ++(int); 78cdf0e10cSrcweir 79cdf0e10cSrcweir RegexpMapEntry< Val > const & operator *() const; 80cdf0e10cSrcweir 81cdf0e10cSrcweir RegexpMapEntry< Val > const * operator ->() const; 82cdf0e10cSrcweir 83cdf0e10cSrcweir bool equals(RegexpMapConstIter const & rOther) const; 84cdf0e10cSrcweir // for free operator ==(), operator !=() 85cdf0e10cSrcweir 86cdf0e10cSrcweir private: 87cdf0e10cSrcweir RegexpMapIterImpl< Val > * m_pImpl; 88cdf0e10cSrcweir 89cdf0e10cSrcweir RegexpMapConstIter(RegexpMapIterImpl< Val > * pTheImpl); 90cdf0e10cSrcweir }; 91cdf0e10cSrcweir 92cdf0e10cSrcweir //============================================================================ 93cdf0e10cSrcweir template< typename Val > 94cdf0e10cSrcweir class RegexpMapIter: public RegexpMapConstIter< Val > 95cdf0e10cSrcweir { 96cdf0e10cSrcweir friend class RegexpMap< Val >; // to access ctor 97cdf0e10cSrcweir 98cdf0e10cSrcweir public: 99cdf0e10cSrcweir RegexpMapIter() {} 100cdf0e10cSrcweir 101cdf0e10cSrcweir RegexpMapIter & operator ++(); 102cdf0e10cSrcweir 103cdf0e10cSrcweir RegexpMapIter operator ++(int); 104cdf0e10cSrcweir 105cdf0e10cSrcweir RegexpMapEntry< Val > & operator *(); 106cdf0e10cSrcweir 107cdf0e10cSrcweir RegexpMapEntry< Val > const & operator *() const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir RegexpMapEntry< Val > * operator ->(); 110cdf0e10cSrcweir 111cdf0e10cSrcweir RegexpMapEntry< Val > const * operator ->() const; 112cdf0e10cSrcweir 113cdf0e10cSrcweir private: 114cdf0e10cSrcweir RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl); 115cdf0e10cSrcweir }; 116cdf0e10cSrcweir 117cdf0e10cSrcweir //============================================================================ 118cdf0e10cSrcweir template< typename Val > struct RegexpMapImpl; 119cdf0e10cSrcweir // MSC doesn't like this to be a RegexpMap member class... 120cdf0e10cSrcweir 121cdf0e10cSrcweir template< typename Val > 122cdf0e10cSrcweir class RegexpMap 123cdf0e10cSrcweir { 124cdf0e10cSrcweir public: 125cdf0e10cSrcweir typedef sal_uInt32 size_type; 126cdf0e10cSrcweir typedef RegexpMapIter< Val > iterator; 127cdf0e10cSrcweir typedef RegexpMapConstIter< Val > const_iterator; 128cdf0e10cSrcweir 129cdf0e10cSrcweir RegexpMap(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir RegexpMap(RegexpMap const & rOther); 132cdf0e10cSrcweir 133cdf0e10cSrcweir ~RegexpMap(); 134cdf0e10cSrcweir 135cdf0e10cSrcweir RegexpMap & operator =(RegexpMap const & rOther); 136cdf0e10cSrcweir 137cdf0e10cSrcweir bool add(rtl::OUString const & rKey, Val const & rValue, bool bOverwrite, 138cdf0e10cSrcweir rtl::OUString * pReverse = 0); 139cdf0e10cSrcweir // throws com::sun::star::lang::IllegalArgumentException 140cdf0e10cSrcweir 141cdf0e10cSrcweir iterator find(rtl::OUString const & rKey, rtl::OUString * pReverse = 0); 142cdf0e10cSrcweir // throws com::sun::star::lang::IllegalArgumentException 143cdf0e10cSrcweir 144cdf0e10cSrcweir void erase(iterator const & rPos); 145cdf0e10cSrcweir 146cdf0e10cSrcweir iterator begin(); 147cdf0e10cSrcweir 148cdf0e10cSrcweir const_iterator begin() const; 149cdf0e10cSrcweir 150cdf0e10cSrcweir iterator end(); 151cdf0e10cSrcweir 152cdf0e10cSrcweir const_iterator end() const; 153cdf0e10cSrcweir 154cdf0e10cSrcweir bool empty() const; 155cdf0e10cSrcweir 156cdf0e10cSrcweir size_type size() const; 157cdf0e10cSrcweir 158cdf0e10cSrcweir Val const * map(rtl::OUString const & rString, 159cdf0e10cSrcweir rtl::OUString * pTranslation = 0, bool * pTranslated = 0) 160cdf0e10cSrcweir const; 161cdf0e10cSrcweir 162cdf0e10cSrcweir private: 163cdf0e10cSrcweir RegexpMapImpl< Val > * m_pImpl; 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir //============================================================================ 169cdf0e10cSrcweir template< typename Val > 170cdf0e10cSrcweir inline bool operator ==(ucb_impl::RegexpMapConstIter< Val > const & rIter1, 171cdf0e10cSrcweir ucb_impl::RegexpMapConstIter< Val > const & rIter2) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir return rIter1.equals(rIter2); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir 176cdf0e10cSrcweir template< typename Val > 177cdf0e10cSrcweir inline bool operator !=(ucb_impl::RegexpMapConstIter< Val > const & rIter1, 178cdf0e10cSrcweir ucb_impl::RegexpMapConstIter< Val > const & rIter2) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return !rIter1.equals(rIter2); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir #endif // _UCB_REGEXPMAP_HXX_ 184cdf0e10cSrcweir 185