xref: /AOO41X/main/ucb/source/inc/regexpmap.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _UCB_REGEXPMAP_HXX_
29*cdf0e10cSrcweir #define _UCB_REGEXPMAP_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <rtl/ustring.hxx>
32*cdf0e10cSrcweir #include <sal/types.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir namespace ucb_impl {
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir template< typename Val > class RegexpMap;
37*cdf0e10cSrcweir template< typename Val > class RegexpMapIter;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //============================================================================
40*cdf0e10cSrcweir template< typename Val >
41*cdf0e10cSrcweir class RegexpMapEntry
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir public:
44*cdf0e10cSrcweir 	inline RegexpMapEntry(rtl::OUString const & rTheRegexp,
45*cdf0e10cSrcweir 						  Val * pTheValue):
46*cdf0e10cSrcweir 		m_aRegexp(rTheRegexp), m_pValue(pTheValue) {}
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 	rtl::OUString getRegexp() const { return m_aRegexp; }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 	Val const & getValue() const { return *m_pValue; }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 	Val & getValue() { return *m_pValue; }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir private:
55*cdf0e10cSrcweir 	rtl::OUString m_aRegexp;
56*cdf0e10cSrcweir 	Val * m_pValue;
57*cdf0e10cSrcweir };
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //============================================================================
60*cdf0e10cSrcweir template< typename Val > class RegexpMapIterImpl;
61*cdf0e10cSrcweir 	// MSC doesn't like this to be a private RegexpMapConstIter member
62*cdf0e10cSrcweir 	// class...
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir template< typename Val >
65*cdf0e10cSrcweir class RegexpMapConstIter
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	friend class RegexpMap< Val >; // to access m_pImpl, ctor
68*cdf0e10cSrcweir 	friend class RegexpMapIter< Val >; // to access m_pImpl, ctor
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir public:
71*cdf0e10cSrcweir 	RegexpMapConstIter();
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	RegexpMapConstIter(RegexpMapConstIter const & rOther);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	~RegexpMapConstIter();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	RegexpMapConstIter & operator =(RegexpMapConstIter const & rOther);
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	RegexpMapConstIter & operator ++();
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 	RegexpMapConstIter operator ++(int);
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir 	RegexpMapEntry< Val > const & operator *() const;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	RegexpMapEntry< Val > const * operator ->() const;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	bool equals(RegexpMapConstIter const & rOther) const;
88*cdf0e10cSrcweir 		// for free operator ==(), operator !=()
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir private:
91*cdf0e10cSrcweir 	RegexpMapIterImpl< Val > * m_pImpl;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	RegexpMapConstIter(RegexpMapIterImpl< Val > * pTheImpl);
94*cdf0e10cSrcweir };
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir //============================================================================
97*cdf0e10cSrcweir template< typename Val >
98*cdf0e10cSrcweir class RegexpMapIter: public RegexpMapConstIter< Val >
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir 	friend class RegexpMap< Val >; // to access ctor
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir public:
103*cdf0e10cSrcweir 	RegexpMapIter() {}
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	RegexpMapIter & operator ++();
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 	RegexpMapIter operator ++(int);
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 	RegexpMapEntry< Val > & operator *();
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 	RegexpMapEntry< Val > const & operator *() const;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	RegexpMapEntry< Val > * operator ->();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	RegexpMapEntry< Val > const * operator ->() const;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir private:
118*cdf0e10cSrcweir 	RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl);
119*cdf0e10cSrcweir };
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir //============================================================================
122*cdf0e10cSrcweir template< typename Val > struct RegexpMapImpl;
123*cdf0e10cSrcweir 	// MSC doesn't like this to be a RegexpMap member class...
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir template< typename Val >
126*cdf0e10cSrcweir class RegexpMap
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir public:
129*cdf0e10cSrcweir 	typedef sal_uInt32 size_type;
130*cdf0e10cSrcweir 	typedef RegexpMapIter< Val > iterator;
131*cdf0e10cSrcweir 	typedef RegexpMapConstIter< Val > const_iterator;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 	RegexpMap();
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	RegexpMap(RegexpMap const & rOther);
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	~RegexpMap();
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	RegexpMap & operator =(RegexpMap const & rOther);
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	bool add(rtl::OUString const & rKey, Val const & rValue, bool bOverwrite,
142*cdf0e10cSrcweir 			 rtl::OUString * pReverse = 0);
143*cdf0e10cSrcweir 		// throws com::sun::star::lang::IllegalArgumentException
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	iterator find(rtl::OUString const & rKey, rtl::OUString * pReverse = 0);
146*cdf0e10cSrcweir 		// throws com::sun::star::lang::IllegalArgumentException
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	void erase(iterator const & rPos);
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	iterator begin();
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	const_iterator begin() const;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	iterator end();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	const_iterator end() const;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	bool empty() const;
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	size_type size() const;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	Val const * map(rtl::OUString const & rString,
163*cdf0e10cSrcweir 					rtl::OUString * pTranslation = 0, bool * pTranslated = 0)
164*cdf0e10cSrcweir 		const;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir private:
167*cdf0e10cSrcweir 	RegexpMapImpl< Val > * m_pImpl;
168*cdf0e10cSrcweir };
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //============================================================================
173*cdf0e10cSrcweir template< typename Val >
174*cdf0e10cSrcweir inline bool operator ==(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
175*cdf0e10cSrcweir 						ucb_impl::RegexpMapConstIter< Val > const & rIter2)
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir 	return rIter1.equals(rIter2);
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir template< typename Val >
181*cdf0e10cSrcweir inline bool operator !=(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
182*cdf0e10cSrcweir 						ucb_impl::RegexpMapConstIter< Val > const & rIter2)
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir 	return !rIter1.equals(rIter2);
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir #endif // _UCB_REGEXPMAP_HXX_
188*cdf0e10cSrcweir 
189