update credits
[LibreOffice.git] / ucb / source / inc / regexpmap.hxx
blob3e960d1bd93bb00857de2005b609a64bfcaff9ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _UCB_REGEXPMAP_HXX_
21 #define _UCB_REGEXPMAP_HXX_
23 #include <rtl/ustring.hxx>
24 #include <sal/types.h>
26 namespace ucb_impl {
28 template< typename Val > class RegexpMap;
29 template< typename Val > class RegexpMapIter;
31 //============================================================================
32 template< typename Val >
33 class RegexpMapEntry
35 public:
36 inline RegexpMapEntry(OUString const & rTheRegexp,
37 Val * pTheValue):
38 m_aRegexp(rTheRegexp), m_pValue(pTheValue) {}
40 OUString getRegexp() const { return m_aRegexp; }
42 Val const & getValue() const { return *m_pValue; }
44 Val & getValue() { return *m_pValue; }
46 private:
47 OUString m_aRegexp;
48 Val * m_pValue;
51 //============================================================================
52 template< typename Val > class RegexpMapIterImpl;
53 // MSC doesn't like this to be a private RegexpMapConstIter member
54 // class...
56 template< typename Val >
57 class RegexpMapConstIter
59 friend class RegexpMap< Val >; // to access m_pImpl, ctor
60 friend class RegexpMapIter< Val >; // to access m_pImpl, ctor
62 public:
63 RegexpMapConstIter();
65 RegexpMapConstIter(RegexpMapConstIter const & rOther);
67 ~RegexpMapConstIter();
69 RegexpMapConstIter & operator =(RegexpMapConstIter const & rOther);
71 RegexpMapConstIter & operator ++();
73 RegexpMapConstIter operator ++(int);
75 RegexpMapEntry< Val > const & operator *() const;
77 RegexpMapEntry< Val > const * operator ->() const;
79 bool equals(RegexpMapConstIter const & rOther) const;
80 // for free operator ==(), operator !=()
82 private:
83 RegexpMapIterImpl< Val > * m_pImpl;
85 RegexpMapConstIter(RegexpMapIterImpl< Val > * pTheImpl);
88 //============================================================================
89 template< typename Val >
90 class RegexpMapIter: public RegexpMapConstIter< Val >
92 friend class RegexpMap< Val >; // to access ctor
94 public:
95 RegexpMapIter() {}
97 RegexpMapIter & operator ++();
99 RegexpMapIter operator ++(int);
101 RegexpMapEntry< Val > & operator *();
103 RegexpMapEntry< Val > const & operator *() const;
105 RegexpMapEntry< Val > * operator ->();
107 RegexpMapEntry< Val > const * operator ->() const;
109 private:
110 RegexpMapIter(RegexpMapIterImpl< Val > * pTheImpl);
113 //============================================================================
114 template< typename Val > struct RegexpMapImpl;
115 // MSC doesn't like this to be a RegexpMap member class...
117 template< typename Val >
118 class RegexpMap
120 public:
121 typedef sal_uInt32 size_type;
122 typedef RegexpMapIter< Val > iterator;
123 typedef RegexpMapConstIter< Val > const_iterator;
125 RegexpMap();
127 RegexpMap(RegexpMap const & rOther);
129 ~RegexpMap();
131 RegexpMap & operator =(RegexpMap const & rOther);
133 bool add(OUString const & rKey, Val const & rValue, bool bOverwrite,
134 OUString * pReverse = 0);
135 // throws com::sun::star::lang::IllegalArgumentException
137 iterator find(OUString const & rKey, OUString * pReverse = 0);
138 // throws com::sun::star::lang::IllegalArgumentException
140 void erase(iterator const & rPos);
142 iterator begin();
144 const_iterator begin() const;
146 iterator end();
148 const_iterator end() const;
150 bool empty() const;
152 size_type size() const;
154 Val const * map(OUString const & rString,
155 OUString * pTranslation = 0, bool * pTranslated = 0)
156 const;
158 private:
159 RegexpMapImpl< Val > * m_pImpl;
164 //============================================================================
165 template< typename Val >
166 inline bool operator ==(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
167 ucb_impl::RegexpMapConstIter< Val > const & rIter2)
169 return rIter1.equals(rIter2);
172 template< typename Val >
173 inline bool operator !=(ucb_impl::RegexpMapConstIter< Val > const & rIter1,
174 ucb_impl::RegexpMapConstIter< Val > const & rIter2)
176 return !rIter1.equals(rIter2);
179 #endif // _UCB_REGEXPMAP_HXX_
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */