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