cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / include / connectivity / dbcharset.hxx
blobe8e10f9f1d240531b64074cf81950c302bfd4715
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 INCLUDED_CONNECTIVITY_DBCHARSET_HXX
21 #define INCLUDED_CONNECTIVITY_DBCHARSET_HXX
23 #include <config_options.h>
24 #include <sal/config.h>
26 #include <set>
28 #include <rtl/textenc.h>
29 #include <rtl/tencinfo.h>
30 #include <rtl/ustring.hxx>
31 #include <connectivity/dbtoolsdllapi.hxx>
34 namespace dbtools
38 //= OCharsetMap
40 /** is a class which translates between different charset representations.
42 <p>The set of recognized charsets is very limited: only the ones which are database relevant are
43 implemented at the moment</p>
45 <p>Possible representations are:
46 <ul>
47 <li><b>IANA names.</b>
48 Have a look at <A href="http://www.iana.org/assignments/character-sets">this document</A> for
49 more details</li>
50 <li><b>rtl_TextEncoding</b></li>
51 </ul>
52 </p>
54 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_DBTOOLS) OCharsetMap
56 protected:
57 typedef std::set<rtl_TextEncoding> TextEncBag;
59 TextEncBag m_aEncodings;
61 public:
62 class CharsetIterator;
63 friend class OCharsetMap::CharsetIterator;
64 typedef CharsetIterator iterator;
65 typedef CharsetIterator const_iterator;
67 OCharsetMap();
68 virtual ~OCharsetMap();
70 /** find the given text encoding in the map.
71 @return the <em>end</em> iterator if the encoding could not be found.
73 CharsetIterator find(const rtl_TextEncoding _eEncoding) const;
74 /** find the given IANA name in the map.
75 @return the <em>end</em> iterator if the IANA name could not be found.
77 CharsetIterator findIanaName(std::u16string_view _rIanaName) const;
79 /// get access to the first element of the charset collection
80 CharsetIterator begin() const;
81 /// get access to the (last + 1st) element of the charset collection
82 CharsetIterator end() const;
84 protected:
85 // needed because we want to call a virtual method during construction
86 void lateConstruct();
87 void ensureConstructed( ) const { if ( m_aEncodings.empty() ) const_cast< OCharsetMap* >( this )->lateConstruct(); }
89 virtual bool approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const;
93 //- CharsetIteratorDerefHelper
95 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_DBTOOLS) CharsetIteratorDerefHelper
97 friend class OCharsetMap::CharsetIterator;
99 rtl_TextEncoding m_eEncoding;
100 OUString m_aIanaName;
102 public:
103 CharsetIteratorDerefHelper(const CharsetIteratorDerefHelper& _rSource);
105 rtl_TextEncoding getEncoding() const { return m_eEncoding; }
106 const OUString& getIanaName() const { return m_aIanaName; }
108 protected:
109 CharsetIteratorDerefHelper( const rtl_TextEncoding _eEncoding, OUString _sIanaName );
114 //- OCharsetMap::CharsetIterator
116 class UNLESS_MERGELIBS_MORE(OOO_DLLPUBLIC_DBTOOLS) OCharsetMap::CharsetIterator
118 friend class OCharsetMap;
120 friend OOO_DLLPUBLIC_DBTOOLS bool operator==(const CharsetIterator& lhs, const CharsetIterator& rhs);
121 friend bool operator!=(const CharsetIterator& lhs, const CharsetIterator& rhs) { return !(lhs == rhs); }
123 // friend sal_Int32 operator-(const CharsetIterator& lhs, const CharsetIterator& rhs);
125 const OCharsetMap* m_pContainer;
126 OCharsetMap::TextEncBag::const_iterator m_aPos;
128 public:
129 CharsetIteratorDerefHelper operator*() const;
130 // no -> operator
131 // this would require us to a) store CharsetIteratorDerefHelper instances ourself so that we
132 // can return a pointer or b) introduce a -> operator on the CharsetIteratorDerefHelper, too.
134 /// prefix increment
135 const CharsetIterator& operator++();
137 /// prefix decrement
138 const CharsetIterator& operator--();
140 protected:
141 CharsetIterator(const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator _aPos );
145 } // namespace dbtools
148 #endif // INCLUDED_CONNECTIVITY_DBCHARSET_HXX
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */