Update ooo320-m1
[ooovba.git] / ucb / source / inc / regexpmap.hxx
blobed76c5592949658739ec4ac7bde6c5a29eb82cf2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regexpmap.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _UCB_REGEXPMAP_HXX_
32 #define _UCB_REGEXPMAP_HXX_
34 #include <rtl/ustring.hxx>
35 #include <sal/types.h>
37 namespace ucb_impl {
39 template< typename Val > class RegexpMap;
40 template< typename Val > class RegexpMapIter;
42 //============================================================================
43 template< typename Val >
44 class RegexpMapEntry
46 public:
47 inline RegexpMapEntry(rtl::OUString const & rTheRegexp,
48 Val * pTheValue):
49 m_aRegexp(rTheRegexp), m_pValue(pTheValue) {}
51 rtl::OUString getRegexp() const { return m_aRegexp; }
53 Val const & getValue() const { return *m_pValue; }
55 Val & getValue() { return *m_pValue; }
57 private:
58 rtl::OUString m_aRegexp;
59 Val * m_pValue;
62 //============================================================================
63 template< typename Val > class RegexpMapIterImpl;
64 // MSC doesn't like this to be a private RegexpMapConstIter member
65 // class...
67 template< typename Val >
68 class RegexpMapConstIter
70 friend class RegexpMap< Val >; // to access m_pImpl, ctor
71 friend class RegexpMapIter< Val >; // to access m_pImpl, ctor
73 public:
74 RegexpMapConstIter();
76 RegexpMapConstIter(RegexpMapConstIter const & rOther);
78 ~RegexpMapConstIter();
80 RegexpMapConstIter & operator =(RegexpMapConstIter const & rOther);
82 RegexpMapConstIter & operator ++();
84 RegexpMapConstIter operator ++(int);
86 RegexpMapEntry< Val > const & operator *() const;
88 RegexpMapEntry< Val > const * operator ->() const;
90 bool equals(RegexpMapConstIter const & rOther) const;
91 // for free operator ==(), operator !=()
93 private:
94 RegexpMapIterImpl< Val > * m_pImpl;
96 RegexpMapConstIter(RegexpMapIterImpl< Val > * pTheImpl);
99 //============================================================================
100 template< typename Val >
101 class RegexpMapIter: public RegexpMapConstIter< Val >
103 friend class RegexpMap< Val >; // to access ctor
105 public:
106 RegexpMapIter() {}
108 RegexpMapIter & operator ++();
110 RegexpMapIter operator ++(int);
112 RegexpMapEntry< Val > & operator *();
114 RegexpMapEntry< Val > const & operator *() const;
116 RegexpMapEntry< Val > * operator ->();
118 RegexpMapEntry< Val > const * operator ->() const;
120 private:
121 RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl);
124 //============================================================================
125 template< typename Val > struct RegexpMapImpl;
126 // MSC doesn't like this to be a RegexpMap member class...
128 template< typename Val >
129 class RegexpMap
131 public:
132 typedef sal_uInt32 size_type;
133 typedef RegexpMapIter< Val > iterator;
134 typedef RegexpMapConstIter< Val > const_iterator;
136 RegexpMap();
138 RegexpMap(RegexpMap const & rOther);
140 ~RegexpMap();
142 RegexpMap & operator =(RegexpMap const & rOther);
144 bool add(rtl::OUString const & rKey, Val const & rValue, bool bOverwrite,
145 rtl::OUString * pReverse = 0);
146 // throws com::sun::star::lang::IllegalArgumentException
148 iterator find(rtl::OUString const & rKey, rtl::OUString * pReverse = 0);
149 // throws com::sun::star::lang::IllegalArgumentException
151 void erase(iterator const & rPos);
153 iterator begin();
155 const_iterator begin() const;
157 iterator end();
159 const_iterator end() const;
161 bool empty() const;
163 size_type size() const;
165 Val const * map(rtl::OUString const & rString,
166 rtl::OUString * pTranslation = 0, bool * pTranslated = 0)
167 const;
169 private:
170 RegexpMapImpl< Val > * m_pImpl;
175 //============================================================================
176 template< typename Val >
177 inline bool operator ==(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
178 ucb_impl::RegexpMapConstIter< Val > const & rIter2)
180 return rIter1.equals(rIter2);
183 template< typename Val >
184 inline bool operator !=(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
185 ucb_impl::RegexpMapConstIter< Val > const & rIter2)
187 return !rIter1.equals(rIter2);
190 #endif // _UCB_REGEXPMAP_HXX_