xref: /trunk/main/ucb/source/inc/regexpmap.tpt (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_TPT_
29*cdf0e10cSrcweir#define _UCB_REGEXPMAP_TPT_
30*cdf0e10cSrcweir
31*cdf0e10cSrcweir#ifndef _UCB_REGEXPMAP_HXX_
32*cdf0e10cSrcweir#include <regexpmap.hxx>
33*cdf0e10cSrcweir#endif
34*cdf0e10cSrcweir
35*cdf0e10cSrcweir#include <list>
36*cdf0e10cSrcweir
37*cdf0e10cSrcweir#ifndef _RTL_USTRING_HXX_
38*cdf0e10cSrcweir#include <rtl/ustring.hxx>
39*cdf0e10cSrcweir#endif
40*cdf0e10cSrcweir
41*cdf0e10cSrcweir#ifndef _UCB_REGEXP_HXX_
42*cdf0e10cSrcweir#include "regexp.hxx"
43*cdf0e10cSrcweir#endif
44*cdf0e10cSrcweir
45*cdf0e10cSrcweirusing namespace ucb_impl;
46*cdf0e10cSrcweir
47*cdf0e10cSrcweirnamespace ucb_impl {
48*cdf0e10cSrcweir
49*cdf0e10cSrcweir//============================================================================
50*cdf0e10cSrcweir
51*cdf0e10cSrcweirtemplate< typename Val >
52*cdf0e10cSrcweirstruct Entry
53*cdf0e10cSrcweir{
54*cdf0e10cSrcweir    Regexp m_aRegexp;
55*cdf0e10cSrcweir    Val m_aValue;
56*cdf0e10cSrcweir
57*cdf0e10cSrcweir    inline Entry(Regexp const & rTheRegexp, Val const & rTheValue):
58*cdf0e10cSrcweir        m_aRegexp(rTheRegexp), m_aValue(rTheValue) {}
59*cdf0e10cSrcweir};
60*cdf0e10cSrcweir
61*cdf0e10cSrcweir//============================================================================
62*cdf0e10cSrcweirtemplate< typename Val > class List: public std::list< Entry< Val > > {};
63*cdf0e10cSrcweir
64*cdf0e10cSrcweir//============================================================================
65*cdf0e10cSrcweir//
66*cdf0e10cSrcweir//  RegexpMapIterImpl
67*cdf0e10cSrcweir//
68*cdf0e10cSrcweir//============================================================================
69*cdf0e10cSrcweir
70*cdf0e10cSrcweirtemplate< typename Val >
71*cdf0e10cSrcweirclass RegexpMapIterImpl
72*cdf0e10cSrcweir{
73*cdf0e10cSrcweirpublic:
74*cdf0e10cSrcweir    typedef RegexpMapImpl< Val > MapImpl;
75*cdf0e10cSrcweir    typedef typename List< Val >::iterator ListIterator;
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir    // Solaris needs these for the ctor...
78*cdf0e10cSrcweir
79*cdf0e10cSrcweir    inline RegexpMapIterImpl();
80*cdf0e10cSrcweir
81*cdf0e10cSrcweir    inline RegexpMapIterImpl(MapImpl * pTheMap, int nTheList,
82*cdf0e10cSrcweir                             ListIterator aTheIndex);
83*cdf0e10cSrcweir
84*cdf0e10cSrcweir    RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap, bool bBegin);
85*cdf0e10cSrcweir
86*cdf0e10cSrcweir    bool operator ==(RegexpMapIterImpl const & rOther) const;
87*cdf0e10cSrcweir
88*cdf0e10cSrcweir    RegexpMapImpl< Val > const * getMap() const { return m_pMap; }
89*cdf0e10cSrcweir
90*cdf0e10cSrcweir    int getList() const { return m_nList; }
91*cdf0e10cSrcweir
92*cdf0e10cSrcweir    typename List< Val >::iterator const & getIndex() const { return m_aIndex; }
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir    void next();
95*cdf0e10cSrcweir
96*cdf0e10cSrcweir    RegexpMapEntry< Val > & get();
97*cdf0e10cSrcweir
98*cdf0e10cSrcweirprivate:
99*cdf0e10cSrcweir    mutable RegexpMapEntry< Val > m_aEntry;
100*cdf0e10cSrcweir    typename List< Val >::iterator m_aIndex;
101*cdf0e10cSrcweir    RegexpMapImpl< Val > * m_pMap;
102*cdf0e10cSrcweir    int m_nList;
103*cdf0e10cSrcweir    mutable bool m_bEntrySet;
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir    void setEntry() const;
106*cdf0e10cSrcweir};
107*cdf0e10cSrcweir
108*cdf0e10cSrcweir}
109*cdf0e10cSrcweir
110*cdf0e10cSrcweirtemplate< typename Val >
111*cdf0e10cSrcweirinline RegexpMapIterImpl< Val >::RegexpMapIterImpl():
112*cdf0e10cSrcweir    m_aEntry(rtl::OUString(), 0),
113*cdf0e10cSrcweir    m_pMap(0),
114*cdf0e10cSrcweir    m_nList(-1),
115*cdf0e10cSrcweir    m_bEntrySet(false)
116*cdf0e10cSrcweir{}
117*cdf0e10cSrcweir
118*cdf0e10cSrcweirtemplate< typename Val >
119*cdf0e10cSrcweirinline RegexpMapIterImpl< Val >::RegexpMapIterImpl(MapImpl * pTheMap,
120*cdf0e10cSrcweir                                                   int nTheList,
121*cdf0e10cSrcweir                                                   ListIterator aTheIndex):
122*cdf0e10cSrcweir    m_aEntry(rtl::OUString(), 0),
123*cdf0e10cSrcweir    m_aIndex(aTheIndex),
124*cdf0e10cSrcweir    m_pMap(pTheMap),
125*cdf0e10cSrcweir    m_nList(nTheList),
126*cdf0e10cSrcweir    m_bEntrySet(false)
127*cdf0e10cSrcweir{}
128*cdf0e10cSrcweir
129*cdf0e10cSrcweir//============================================================================
130*cdf0e10cSrcweirtemplate< typename Val >
131*cdf0e10cSrcweirvoid RegexpMapIterImpl< Val >::setEntry() const
132*cdf0e10cSrcweir{
133*cdf0e10cSrcweir    if (!m_bEntrySet)
134*cdf0e10cSrcweir    {
135*cdf0e10cSrcweir        Entry< Val > const & rTheEntry
136*cdf0e10cSrcweir            = m_nList == -1 ? *m_pMap->m_pDefault : *m_aIndex;
137*cdf0e10cSrcweir        m_aEntry
138*cdf0e10cSrcweir            = RegexpMapEntry< Val >(rTheEntry.m_aRegexp.getRegexp(false),
139*cdf0e10cSrcweir                                    const_cast< Val * >(&rTheEntry.m_aValue));
140*cdf0e10cSrcweir        m_bEntrySet = true;
141*cdf0e10cSrcweir    }
142*cdf0e10cSrcweir}
143*cdf0e10cSrcweir
144*cdf0e10cSrcweir//============================================================================
145*cdf0e10cSrcweirtemplate< typename Val >
146*cdf0e10cSrcweirRegexpMapIterImpl< Val >::RegexpMapIterImpl(RegexpMapImpl< Val > * pTheMap,
147*cdf0e10cSrcweir                                            bool bBegin):
148*cdf0e10cSrcweir    m_aEntry(rtl::OUString(), 0),
149*cdf0e10cSrcweir    m_pMap(pTheMap),
150*cdf0e10cSrcweir    m_bEntrySet(false)
151*cdf0e10cSrcweir{
152*cdf0e10cSrcweir    if (bBegin)
153*cdf0e10cSrcweir    {
154*cdf0e10cSrcweir        m_nList = -1;
155*cdf0e10cSrcweir        m_aIndex = typename List< Val >::iterator();
156*cdf0e10cSrcweir        if (!m_pMap->m_pDefault)
157*cdf0e10cSrcweir            next();
158*cdf0e10cSrcweir    }
159*cdf0e10cSrcweir    else
160*cdf0e10cSrcweir    {
161*cdf0e10cSrcweir        m_nList = Regexp::KIND_DOMAIN;
162*cdf0e10cSrcweir        m_aIndex = m_pMap->m_aList[Regexp::KIND_DOMAIN].end();
163*cdf0e10cSrcweir    }
164*cdf0e10cSrcweir}
165*cdf0e10cSrcweir
166*cdf0e10cSrcweir//============================================================================
167*cdf0e10cSrcweirtemplate< typename Val >
168*cdf0e10cSrcweirbool RegexpMapIterImpl< Val >::operator ==(RegexpMapIterImpl const & rOther)
169*cdf0e10cSrcweir    const
170*cdf0e10cSrcweir{
171*cdf0e10cSrcweir    return m_pMap == rOther.m_pMap
172*cdf0e10cSrcweir           && m_nList == rOther.m_nList
173*cdf0e10cSrcweir           && m_aIndex == rOther.m_aIndex;
174*cdf0e10cSrcweir}
175*cdf0e10cSrcweir
176*cdf0e10cSrcweir//============================================================================
177*cdf0e10cSrcweirtemplate< typename Val >
178*cdf0e10cSrcweirvoid RegexpMapIterImpl< Val >::next()
179*cdf0e10cSrcweir{
180*cdf0e10cSrcweir    switch (m_nList)
181*cdf0e10cSrcweir    {
182*cdf0e10cSrcweir        case Regexp::KIND_DOMAIN:
183*cdf0e10cSrcweir            if (m_aIndex == m_pMap->m_aList[m_nList].end())
184*cdf0e10cSrcweir                return;
185*cdf0e10cSrcweir        default:
186*cdf0e10cSrcweir            ++m_aIndex;
187*cdf0e10cSrcweir            if (m_nList == Regexp::KIND_DOMAIN
188*cdf0e10cSrcweir                || m_aIndex != m_pMap->m_aList[m_nList].end())
189*cdf0e10cSrcweir                break;
190*cdf0e10cSrcweir        case -1:
191*cdf0e10cSrcweir            do
192*cdf0e10cSrcweir            {
193*cdf0e10cSrcweir                ++m_nList;
194*cdf0e10cSrcweir                m_aIndex = m_pMap->m_aList[m_nList].begin();
195*cdf0e10cSrcweir            }
196*cdf0e10cSrcweir            while (m_nList < Regexp::KIND_DOMAIN
197*cdf0e10cSrcweir                   && m_aIndex == m_pMap->m_aList[m_nList].end());
198*cdf0e10cSrcweir            break;
199*cdf0e10cSrcweir    }
200*cdf0e10cSrcweir    m_bEntrySet = false;
201*cdf0e10cSrcweir}
202*cdf0e10cSrcweir
203*cdf0e10cSrcweir//============================================================================
204*cdf0e10cSrcweirtemplate< typename Val >
205*cdf0e10cSrcweirRegexpMapEntry< Val > & RegexpMapIterImpl< Val >::get()
206*cdf0e10cSrcweir{
207*cdf0e10cSrcweir    setEntry();
208*cdf0e10cSrcweir    return m_aEntry;
209*cdf0e10cSrcweir}
210*cdf0e10cSrcweir
211*cdf0e10cSrcweir//============================================================================
212*cdf0e10cSrcweir//
213*cdf0e10cSrcweir//  RegexpMapConstIter
214*cdf0e10cSrcweir//
215*cdf0e10cSrcweir//============================================================================
216*cdf0e10cSrcweir
217*cdf0e10cSrcweirtemplate< typename Val >
218*cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapIterImpl< Val > *
219*cdf0e10cSrcweir                                                  pTheImpl):
220*cdf0e10cSrcweir    m_pImpl(pTheImpl)
221*cdf0e10cSrcweir{}
222*cdf0e10cSrcweir
223*cdf0e10cSrcweir//============================================================================
224*cdf0e10cSrcweirtemplate< typename Val >
225*cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter():
226*cdf0e10cSrcweir    m_pImpl(new RegexpMapIterImpl< Val >)
227*cdf0e10cSrcweir{}
228*cdf0e10cSrcweir
229*cdf0e10cSrcweir//============================================================================
230*cdf0e10cSrcweirtemplate< typename Val >
231*cdf0e10cSrcweirRegexpMapConstIter< Val >::RegexpMapConstIter(RegexpMapConstIter const &
232*cdf0e10cSrcweir                                                  rOther):
233*cdf0e10cSrcweir    m_pImpl(new RegexpMapIterImpl< Val >(*rOther.m_pImpl))
234*cdf0e10cSrcweir{}
235*cdf0e10cSrcweir
236*cdf0e10cSrcweir//============================================================================
237*cdf0e10cSrcweirtemplate< typename Val >
238*cdf0e10cSrcweirRegexpMapConstIter< Val >::~RegexpMapConstIter()
239*cdf0e10cSrcweir{
240*cdf0e10cSrcweir    delete m_pImpl;
241*cdf0e10cSrcweir}
242*cdf0e10cSrcweir
243*cdf0e10cSrcweir//============================================================================
244*cdf0e10cSrcweirtemplate< typename Val >
245*cdf0e10cSrcweirRegexpMapConstIter< Val > &
246*cdf0e10cSrcweirRegexpMapConstIter< Val >::operator =(RegexpMapConstIter const & rOther)
247*cdf0e10cSrcweir{
248*cdf0e10cSrcweir    *m_pImpl = *rOther.m_pImpl;
249*cdf0e10cSrcweir    return *this;
250*cdf0e10cSrcweir}
251*cdf0e10cSrcweir
252*cdf0e10cSrcweir//============================================================================
253*cdf0e10cSrcweirtemplate< typename Val >
254*cdf0e10cSrcweirRegexpMapConstIter< Val > & RegexpMapConstIter< Val >::operator ++()
255*cdf0e10cSrcweir{
256*cdf0e10cSrcweir    m_pImpl->next();
257*cdf0e10cSrcweir    return *this;
258*cdf0e10cSrcweir}
259*cdf0e10cSrcweir
260*cdf0e10cSrcweir//============================================================================
261*cdf0e10cSrcweirtemplate< typename Val >
262*cdf0e10cSrcweirRegexpMapConstIter< Val > RegexpMapConstIter< Val >::operator ++(int)
263*cdf0e10cSrcweir{
264*cdf0e10cSrcweir    RegexpMapConstIter aTemp(*this);
265*cdf0e10cSrcweir    m_pImpl->next();
266*cdf0e10cSrcweir    return aTemp;
267*cdf0e10cSrcweir}
268*cdf0e10cSrcweir
269*cdf0e10cSrcweir//============================================================================
270*cdf0e10cSrcweirtemplate< typename Val >
271*cdf0e10cSrcweirRegexpMapEntry< Val > const & RegexpMapConstIter< Val >::operator *() const
272*cdf0e10cSrcweir{
273*cdf0e10cSrcweir    return m_pImpl->get();
274*cdf0e10cSrcweir}
275*cdf0e10cSrcweir
276*cdf0e10cSrcweir//============================================================================
277*cdf0e10cSrcweirtemplate< typename Val >
278*cdf0e10cSrcweirRegexpMapEntry< Val > const * RegexpMapConstIter< Val >::operator ->() const
279*cdf0e10cSrcweir{
280*cdf0e10cSrcweir    return &m_pImpl->get();
281*cdf0e10cSrcweir}
282*cdf0e10cSrcweir
283*cdf0e10cSrcweir//============================================================================
284*cdf0e10cSrcweirtemplate< typename Val >
285*cdf0e10cSrcweirbool RegexpMapConstIter< Val >::equals(RegexpMapConstIter const & rOther)
286*cdf0e10cSrcweir    const
287*cdf0e10cSrcweir{
288*cdf0e10cSrcweir    return *m_pImpl == *rOther.m_pImpl;
289*cdf0e10cSrcweir}
290*cdf0e10cSrcweir
291*cdf0e10cSrcweir//============================================================================
292*cdf0e10cSrcweir//
293*cdf0e10cSrcweir//  RegexpMapIter
294*cdf0e10cSrcweir//
295*cdf0e10cSrcweir//============================================================================
296*cdf0e10cSrcweir
297*cdf0e10cSrcweirtemplate< typename Val >
298*cdf0e10cSrcweirRegexpMapIter< Val >::RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl):
299*cdf0e10cSrcweir    RegexpMapConstIter< Val >(pTheImpl)
300*cdf0e10cSrcweir{}
301*cdf0e10cSrcweir
302*cdf0e10cSrcweir//============================================================================
303*cdf0e10cSrcweirtemplate< typename Val >
304*cdf0e10cSrcweirRegexpMapIter< Val > & RegexpMapIter< Val >::operator ++()
305*cdf0e10cSrcweir{
306*cdf0e10cSrcweir    this->m_pImpl->next();
307*cdf0e10cSrcweir    return *this;
308*cdf0e10cSrcweir}
309*cdf0e10cSrcweir
310*cdf0e10cSrcweir//============================================================================
311*cdf0e10cSrcweirtemplate< typename Val >
312*cdf0e10cSrcweirRegexpMapIter< Val > RegexpMapIter< Val >::operator ++(int)
313*cdf0e10cSrcweir{
314*cdf0e10cSrcweir    RegexpMapIter aTemp(*this);
315*cdf0e10cSrcweir    this->m_pImpl->next();
316*cdf0e10cSrcweir    return aTemp;
317*cdf0e10cSrcweir}
318*cdf0e10cSrcweir
319*cdf0e10cSrcweir//============================================================================
320*cdf0e10cSrcweirtemplate< typename Val >
321*cdf0e10cSrcweirRegexpMapEntry< Val > & RegexpMapIter< Val >::operator *()
322*cdf0e10cSrcweir{
323*cdf0e10cSrcweir    return this->m_pImpl->get();
324*cdf0e10cSrcweir}
325*cdf0e10cSrcweir
326*cdf0e10cSrcweir//============================================================================
327*cdf0e10cSrcweirtemplate< typename Val >
328*cdf0e10cSrcweirRegexpMapEntry< Val > const & RegexpMapIter< Val >::operator *() const
329*cdf0e10cSrcweir{
330*cdf0e10cSrcweir    return this->m_pImpl->get();
331*cdf0e10cSrcweir}
332*cdf0e10cSrcweir
333*cdf0e10cSrcweir//============================================================================
334*cdf0e10cSrcweirtemplate< typename Val >
335*cdf0e10cSrcweirRegexpMapEntry< Val > * RegexpMapIter< Val >::operator ->()
336*cdf0e10cSrcweir{
337*cdf0e10cSrcweir    return &this->m_pImpl->get();
338*cdf0e10cSrcweir}
339*cdf0e10cSrcweir
340*cdf0e10cSrcweir//============================================================================
341*cdf0e10cSrcweirtemplate< typename Val >
342*cdf0e10cSrcweirRegexpMapEntry< Val > const * RegexpMapIter< Val >::operator ->() const
343*cdf0e10cSrcweir{
344*cdf0e10cSrcweir    return &this->m_pImpl->get();
345*cdf0e10cSrcweir}
346*cdf0e10cSrcweir
347*cdf0e10cSrcweir//============================================================================
348*cdf0e10cSrcweir//
349*cdf0e10cSrcweir//  RegexpMap
350*cdf0e10cSrcweir//
351*cdf0e10cSrcweir//============================================================================
352*cdf0e10cSrcweir
353*cdf0e10cSrcweirnamespace ucb_impl {
354*cdf0e10cSrcweir
355*cdf0e10cSrcweirtemplate< typename Val >
356*cdf0e10cSrcweirstruct RegexpMapImpl
357*cdf0e10cSrcweir{
358*cdf0e10cSrcweir    List< Val > m_aList[Regexp::KIND_DOMAIN + 1];
359*cdf0e10cSrcweir    Entry< Val > * m_pDefault;
360*cdf0e10cSrcweir
361*cdf0e10cSrcweir    RegexpMapImpl(): m_pDefault(0) {}
362*cdf0e10cSrcweir
363*cdf0e10cSrcweir    ~RegexpMapImpl() { delete m_pDefault; }
364*cdf0e10cSrcweir};
365*cdf0e10cSrcweir
366*cdf0e10cSrcweir}
367*cdf0e10cSrcweir
368*cdf0e10cSrcweir//============================================================================
369*cdf0e10cSrcweirtemplate< typename Val >
370*cdf0e10cSrcweirRegexpMap< Val >::RegexpMap():
371*cdf0e10cSrcweir    m_pImpl(new RegexpMapImpl< Val >)
372*cdf0e10cSrcweir{}
373*cdf0e10cSrcweir
374*cdf0e10cSrcweir//============================================================================
375*cdf0e10cSrcweirtemplate< typename Val >
376*cdf0e10cSrcweirRegexpMap< Val >::RegexpMap(RegexpMap const & rOther):
377*cdf0e10cSrcweir    m_pImpl(new RegexpMapImpl< Val >(*rOther.m_pImpl))
378*cdf0e10cSrcweir{}
379*cdf0e10cSrcweir
380*cdf0e10cSrcweir//============================================================================
381*cdf0e10cSrcweirtemplate< typename Val >
382*cdf0e10cSrcweirRegexpMap< Val >::~RegexpMap()
383*cdf0e10cSrcweir{
384*cdf0e10cSrcweir    delete m_pImpl;
385*cdf0e10cSrcweir}
386*cdf0e10cSrcweir
387*cdf0e10cSrcweir//============================================================================
388*cdf0e10cSrcweirtemplate< typename Val >
389*cdf0e10cSrcweirRegexpMap< Val > & RegexpMap< Val >::operator =(RegexpMap const & rOther)
390*cdf0e10cSrcweir{
391*cdf0e10cSrcweir    *m_pImpl = *rOther.m_pImpl;
392*cdf0e10cSrcweir    return *this;
393*cdf0e10cSrcweir}
394*cdf0e10cSrcweir
395*cdf0e10cSrcweir//============================================================================
396*cdf0e10cSrcweirtemplate< typename Val >
397*cdf0e10cSrcweirbool RegexpMap< Val >::add(rtl::OUString const & rKey, Val const & rValue,
398*cdf0e10cSrcweir                           bool bOverwrite, rtl::OUString * pReverse)
399*cdf0e10cSrcweir{
400*cdf0e10cSrcweir    Regexp aRegexp(Regexp::parse(rKey));
401*cdf0e10cSrcweir
402*cdf0e10cSrcweir    if (aRegexp.isDefault())
403*cdf0e10cSrcweir    {
404*cdf0e10cSrcweir        if (m_pImpl->m_pDefault)
405*cdf0e10cSrcweir        {
406*cdf0e10cSrcweir            if (!bOverwrite)
407*cdf0e10cSrcweir                return false;
408*cdf0e10cSrcweir            delete m_pImpl->m_pDefault;
409*cdf0e10cSrcweir        }
410*cdf0e10cSrcweir        m_pImpl->m_pDefault = new Entry< Val >(aRegexp, rValue);
411*cdf0e10cSrcweir    }
412*cdf0e10cSrcweir    else
413*cdf0e10cSrcweir    {
414*cdf0e10cSrcweir        List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()];
415*cdf0e10cSrcweir
416*cdf0e10cSrcweir        typename List< Val >::iterator aEnd(rTheList.end());
417*cdf0e10cSrcweir        for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt)
418*cdf0e10cSrcweir        {
419*cdf0e10cSrcweir            if (aIt->m_aRegexp == aRegexp)
420*cdf0e10cSrcweir            {
421*cdf0e10cSrcweir                if (bOverwrite)
422*cdf0e10cSrcweir                {
423*cdf0e10cSrcweir                    rTheList.erase(aIt);
424*cdf0e10cSrcweir                    break;
425*cdf0e10cSrcweir                }
426*cdf0e10cSrcweir                else
427*cdf0e10cSrcweir                    return false;
428*cdf0e10cSrcweir            }
429*cdf0e10cSrcweir        }
430*cdf0e10cSrcweir
431*cdf0e10cSrcweir        rTheList.push_back(Entry< Val >(aRegexp, rValue));
432*cdf0e10cSrcweir    }
433*cdf0e10cSrcweir
434*cdf0e10cSrcweir    if (pReverse)
435*cdf0e10cSrcweir        *pReverse = aRegexp.getRegexp(true);
436*cdf0e10cSrcweir
437*cdf0e10cSrcweir    return true;
438*cdf0e10cSrcweir}
439*cdf0e10cSrcweir
440*cdf0e10cSrcweir//============================================================================
441*cdf0e10cSrcweirtemplate< typename Val >
442*cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::find(rtl::OUString const & rKey,
443*cdf0e10cSrcweir                                                  rtl::OUString * pReverse)
444*cdf0e10cSrcweir{
445*cdf0e10cSrcweir    Regexp aRegexp(Regexp::parse(rKey));
446*cdf0e10cSrcweir
447*cdf0e10cSrcweir    if (pReverse)
448*cdf0e10cSrcweir        *pReverse = aRegexp.getRegexp(true);
449*cdf0e10cSrcweir
450*cdf0e10cSrcweir    if (aRegexp.isDefault())
451*cdf0e10cSrcweir    {
452*cdf0e10cSrcweir        if (m_pImpl->m_pDefault)
453*cdf0e10cSrcweir            return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
454*cdf0e10cSrcweir                                                                     true));
455*cdf0e10cSrcweir    }
456*cdf0e10cSrcweir    else
457*cdf0e10cSrcweir    {
458*cdf0e10cSrcweir        List< Val > & rTheList = m_pImpl->m_aList[aRegexp.getKind()];
459*cdf0e10cSrcweir
460*cdf0e10cSrcweir        typename List< Val > ::iterator aEnd(rTheList.end());
461*cdf0e10cSrcweir        for (typename List< Val >::iterator aIt(rTheList.begin()); aIt != aEnd; ++aIt)
462*cdf0e10cSrcweir            if (aIt->m_aRegexp == aRegexp)
463*cdf0e10cSrcweir                return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(
464*cdf0e10cSrcweir                                                    m_pImpl,
465*cdf0e10cSrcweir                                                    aRegexp.getKind(), aIt));
466*cdf0e10cSrcweir    }
467*cdf0e10cSrcweir
468*cdf0e10cSrcweir    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false));
469*cdf0e10cSrcweir}
470*cdf0e10cSrcweir
471*cdf0e10cSrcweir//============================================================================
472*cdf0e10cSrcweirtemplate< typename Val >
473*cdf0e10cSrcweirvoid RegexpMap< Val >::erase(iterator const & rPos)
474*cdf0e10cSrcweir{
475*cdf0e10cSrcweir    if (rPos.m_pImpl->getMap() == m_pImpl)
476*cdf0e10cSrcweir    {
477*cdf0e10cSrcweir        if (rPos.m_pImpl->getList() == -1)
478*cdf0e10cSrcweir        {
479*cdf0e10cSrcweir            if (m_pImpl->m_pDefault)
480*cdf0e10cSrcweir            {
481*cdf0e10cSrcweir                delete m_pImpl->m_pDefault;
482*cdf0e10cSrcweir                m_pImpl->m_pDefault = 0;
483*cdf0e10cSrcweir            }
484*cdf0e10cSrcweir        }
485*cdf0e10cSrcweir        else
486*cdf0e10cSrcweir            m_pImpl->m_aList[rPos.m_pImpl->getList()].
487*cdf0e10cSrcweir                         erase(rPos.m_pImpl->getIndex());
488*cdf0e10cSrcweir    }
489*cdf0e10cSrcweir}
490*cdf0e10cSrcweir
491*cdf0e10cSrcweir//============================================================================
492*cdf0e10cSrcweirtemplate< typename Val >
493*cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::begin()
494*cdf0e10cSrcweir{
495*cdf0e10cSrcweir    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, true));
496*cdf0e10cSrcweir}
497*cdf0e10cSrcweir
498*cdf0e10cSrcweir//============================================================================
499*cdf0e10cSrcweirtemplate< typename Val >
500*cdf0e10cSrcweirtypename RegexpMap< Val >::const_iterator RegexpMap< Val >::begin() const
501*cdf0e10cSrcweir{
502*cdf0e10cSrcweir    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
503*cdf0e10cSrcweir                                                                  true));
504*cdf0e10cSrcweir}
505*cdf0e10cSrcweir
506*cdf0e10cSrcweir//============================================================================
507*cdf0e10cSrcweirtemplate< typename Val >
508*cdf0e10cSrcweirtypename RegexpMap< Val >::iterator RegexpMap< Val >::end()
509*cdf0e10cSrcweir{
510*cdf0e10cSrcweir    return RegexpMapIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl, false));
511*cdf0e10cSrcweir}
512*cdf0e10cSrcweir
513*cdf0e10cSrcweir//============================================================================
514*cdf0e10cSrcweirtemplate< typename Val >
515*cdf0e10cSrcweirtypename RegexpMap< Val >::const_iterator RegexpMap< Val >::end() const
516*cdf0e10cSrcweir{
517*cdf0e10cSrcweir    return RegexpMapConstIter< Val >(new RegexpMapIterImpl< Val >(m_pImpl,
518*cdf0e10cSrcweir                                                                  false));
519*cdf0e10cSrcweir}
520*cdf0e10cSrcweir
521*cdf0e10cSrcweir//============================================================================
522*cdf0e10cSrcweirtemplate< typename Val >
523*cdf0e10cSrcweirbool RegexpMap< Val >::empty() const
524*cdf0e10cSrcweir{
525*cdf0e10cSrcweir    return !m_pImpl->m_pDefault
526*cdf0e10cSrcweir           && m_pImpl->m_aList[Regexp::KIND_PREFIX].empty()
527*cdf0e10cSrcweir           && m_pImpl->m_aList[Regexp::KIND_AUTHORITY].empty()
528*cdf0e10cSrcweir           && m_pImpl->m_aList[Regexp::KIND_DOMAIN].empty();
529*cdf0e10cSrcweir}
530*cdf0e10cSrcweir
531*cdf0e10cSrcweir//============================================================================
532*cdf0e10cSrcweirtemplate< typename Val >
533*cdf0e10cSrcweirtypename RegexpMap< Val >::size_type RegexpMap< Val >::size() const
534*cdf0e10cSrcweir{
535*cdf0e10cSrcweir    return (m_pImpl->m_pDefault ? 1 : 0)
536*cdf0e10cSrcweir               + m_pImpl->m_aList[Regexp::KIND_PREFIX].size()
537*cdf0e10cSrcweir               + m_pImpl->m_aList[Regexp::KIND_AUTHORITY].size()
538*cdf0e10cSrcweir               + m_pImpl->m_aList[Regexp::KIND_DOMAIN].size();
539*cdf0e10cSrcweir}
540*cdf0e10cSrcweir
541*cdf0e10cSrcweir//============================================================================
542*cdf0e10cSrcweirtemplate< typename Val >
543*cdf0e10cSrcweirVal const * RegexpMap< Val >::map(rtl::OUString const & rString,
544*cdf0e10cSrcweir                                  rtl::OUString * pTranslation,
545*cdf0e10cSrcweir                                  bool * pTranslated) const
546*cdf0e10cSrcweir{
547*cdf0e10cSrcweir    for (int n = Regexp::KIND_DOMAIN; n >= Regexp::KIND_PREFIX; --n)
548*cdf0e10cSrcweir    {
549*cdf0e10cSrcweir        List< Val > const & rTheList = m_pImpl->m_aList[n];
550*cdf0e10cSrcweir
551*cdf0e10cSrcweir        typename List< Val >::const_iterator aEnd(rTheList.end());
552*cdf0e10cSrcweir        for (typename List< Val >::const_iterator aIt(rTheList.begin()); aIt != aEnd;
553*cdf0e10cSrcweir             ++aIt)
554*cdf0e10cSrcweir            if (aIt->m_aRegexp.matches(rString, pTranslation, pTranslated))
555*cdf0e10cSrcweir                return &aIt->m_aValue;
556*cdf0e10cSrcweir    }
557*cdf0e10cSrcweir    if (m_pImpl->m_pDefault
558*cdf0e10cSrcweir        && m_pImpl->m_pDefault->m_aRegexp.matches(rString, pTranslation,
559*cdf0e10cSrcweir                                                  pTranslated))
560*cdf0e10cSrcweir        return &m_pImpl->m_pDefault->m_aValue;
561*cdf0e10cSrcweir    return 0;
562*cdf0e10cSrcweir}
563*cdf0e10cSrcweir
564*cdf0e10cSrcweir#endif // _UCB_REGEXPMAP_TPT_
565