LCOV - code coverage report
Current view: top level - include/connectivity - dbcharset.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 4 5 80.0 %
Date: 2014-11-03 Functions: 4 5 80.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_CONNECTIVITY_DBCHARSET_HXX
      21             : #define INCLUDED_CONNECTIVITY_DBCHARSET_HXX
      22             : 
      23             : #include <sal/config.h>
      24             : 
      25             : #include <cstddef>
      26             : #include <set>
      27             : 
      28             : #include <rtl/textenc.h>
      29             : #include <rtl/tencinfo.h>
      30             : #include <rtl/ustring.hxx>
      31             : #include <connectivity/dbtoolsdllapi.hxx>
      32             : 
      33             : 
      34             : namespace dbtools
      35             : {
      36             : 
      37             : 
      38             : 
      39             :     //= OCharsetMap
      40             : 
      41             :     /** is a class which translates between different charset representations.
      42             : 
      43             :         <p>The set of recognized charsets is very limited: only the ones which are database relevant are
      44             :         implemented at the moment</p>
      45             : 
      46             :         <p>Possible representations are:
      47             :         <ul>
      48             :             <li><b>IANA names.</b>
      49             :             Have a look at <A href="http://www.iana.org/assignments/character-sets">this document</A> for
      50             :             more details</li>
      51             :             <li><b>rtl_TextEncoding</b></li>
      52             :         </ul>
      53             :         </p>
      54             :     */
      55             :     class OOO_DLLPUBLIC_DBTOOLS OCharsetMap
      56             :     {
      57             :     protected:
      58             :         typedef std::set<rtl_TextEncoding> TextEncBag;
      59             : 
      60             :         TextEncBag  m_aEncodings;
      61             : 
      62             :     public:
      63             :         class CharsetIterator;
      64             :         friend class OCharsetMap::CharsetIterator;
      65             :         typedef CharsetIterator iterator;
      66             :         typedef CharsetIterator const_iterator;
      67             : 
      68             :         OCharsetMap();
      69             :         virtual ~OCharsetMap();
      70             : 
      71             :         struct IANA { };
      72             : 
      73             :         /** find the given text encoding in the map.
      74             :             @return the <em>end</em> iterator if the encoding could not be found.
      75             :         */
      76             :         CharsetIterator find(const rtl_TextEncoding _eEncoding) const;
      77             :         /** find the given IANA name in the map.
      78             :             @return the <em>end</em> iterator if the IANA name could not be found.
      79             :         */
      80             :         CharsetIterator find(const OUString& _rIanaName, const IANA&) const;
      81             : 
      82             :         std::size_t   size() const { ensureConstructed( ); return m_aEncodings.size(); }
      83             : 
      84             :         /// get access to the first element of the charset collection
      85             :         CharsetIterator begin() const;
      86             :         /// get access to the (last + 1st) element of the charset collection
      87             :         CharsetIterator end() const;
      88             : 
      89             :     protected:
      90             :         // needed because we want to call a virtual method during construction
      91             :                 void lateConstruct();
      92         178 :         inline  void ensureConstructed( ) const { if ( m_aEncodings.empty() ) const_cast< OCharsetMap* >( this )->lateConstruct(); }
      93             : 
      94             :         virtual bool approveEncoding( const rtl_TextEncoding _eEncoding, const rtl_TextEncodingInfo& _rInfo ) const;
      95             :     };
      96             : 
      97             : 
      98             :     //- CharsetIteratorDerefHelper
      99             : 
     100         172 :     class OOO_DLLPUBLIC_DBTOOLS CharsetIteratorDerefHelper
     101             :     {
     102             :         friend class OCharsetMap::CharsetIterator;
     103             : 
     104             :         rtl_TextEncoding    m_eEncoding;
     105             :         OUString     m_aIanaName;
     106             : 
     107             :     public:
     108             :         CharsetIteratorDerefHelper(const CharsetIteratorDerefHelper& _rSource);
     109             : 
     110         172 :         rtl_TextEncoding    getEncoding() const { return m_eEncoding; }
     111           0 :         OUString     getIanaName() const { return m_aIanaName; }
     112             : 
     113             :     protected:
     114             :         CharsetIteratorDerefHelper( const rtl_TextEncoding _eEncoding, const OUString& _rIanaName );
     115             : 
     116             :     };
     117             : 
     118             : 
     119             : 
     120             :     //- OCharsetMap::CharsetIterator
     121             : 
     122             :     class OOO_DLLPUBLIC_DBTOOLS OCharsetMap::CharsetIterator
     123             :     {
     124             :         friend class OCharsetMap;
     125             : 
     126             :         friend OOO_DLLPUBLIC_DBTOOLS bool operator==(const CharsetIterator& lhs, const CharsetIterator& rhs);
     127         174 :         friend bool operator!=(const CharsetIterator& lhs, const CharsetIterator& rhs) { return !(lhs == rhs); }
     128             : 
     129             : //      friend sal_Int32 operator-(const CharsetIterator& lhs, const CharsetIterator& rhs);
     130             : 
     131             :     protected:
     132             :         const OCharsetMap*                      m_pContainer;
     133             :         OCharsetMap::TextEncBag::const_iterator m_aPos;
     134             : 
     135             :     public:
     136             :         CharsetIterator(const CharsetIterator& _rSource);
     137             :         ~CharsetIterator();
     138             : 
     139             :         CharsetIteratorDerefHelper operator*() const;
     140             :         // no -> operator
     141             :         // this would require us to a) store CharsetIteratorDerefHelper instances ourself so that we
     142             :         // can return a pointer or b) introduce a -> operator on the CharsetIteratorDerefHelper, too.
     143             : 
     144             :         /// prefix increment
     145             :         const CharsetIterator&  operator++();
     146             :         /// postfix increment
     147             :         const CharsetIterator   operator++(int) { CharsetIterator hold(*this); ++*this; return hold; }
     148             : 
     149             :         /// prefix decrement
     150             :         const CharsetIterator&  operator--();
     151             :         /// postfix decrement
     152             :         const CharsetIterator   operator--(int) { CharsetIterator hold(*this); --*this; return hold; }
     153             : 
     154             :     protected:
     155             :         CharsetIterator(const OCharsetMap* _pContainer, OCharsetMap::TextEncBag::const_iterator _aPos );
     156             :     };
     157             : 
     158             : 
     159             : }   // namespace dbtools
     160             : 
     161             : 
     162             : #endif // INCLUDED_CONNECTIVITY_DBCHARSET_HXX
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10