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