LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/inc - ContainerHelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 18 55.6 %
Date: 2012-12-27 Functions: 16 40 40.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             : #ifndef CHART2_CONTAINERHELPER_HXX
      20             : #define CHART2_CONTAINERHELPER_HXX
      21             : 
      22             : #include <vector>
      23             : #include <set>
      24             : #include <map>
      25             : 
      26             : #include <algorithm>
      27             : #include <functional>
      28             : #include <o3tl/compat_functional.hxx>
      29             : 
      30             : namespace chart
      31             : {
      32             : namespace ContainerHelper
      33             : {
      34             : 
      35             : /** converts a standard container into a sequence of the same type
      36             : 
      37             :     input:   standard container
      38             :     output:  css::uno::Sequence< container::value_type >
      39             : 
      40             :     example:
      41             : 
      42             :     ::std::vector< sal_Int32 > aVector;
      43             :     Sequence< sal_Int32 > aSequence( ContainerHelper::ContainerToSequence( aVector ));
      44             :  */
      45             : template< class Container >
      46             :     ::com::sun::star::uno::Sequence< typename Container::value_type >
      47        5203 :     ContainerToSequence( const Container & rCont )
      48             : {
      49        5203 :     ::com::sun::star::uno::Sequence< typename Container::value_type > aResult( rCont.size());
      50        5203 :     ::std::copy( rCont.begin(), rCont.end(), aResult.getArray());
      51        5203 :     return aResult;
      52             : }
      53             : 
      54             : /** converts a UNO sequence into a standard "Sequence" container. For
      55             :     convenience see the methods SequenceToVector, etc. below.
      56             : 
      57             :     input:  uno::Sequence
      58             :     output: a standard container of the same value type implementing the Concept
      59             :             of a Sequence (vector, deque, list, slist)
      60             : 
      61             :     example:
      62             : 
      63             :     Sequence< sal_Int32 > aSequence;
      64             :     ::std::vector< sal_Int32 > aVector(
      65             :         ContainerToSequence::SequenceToSTLSequenceContainer< ::std::vector< sal_Int32 > >( aSequence );
      66             : */
      67             : template< class Container >
      68             :     Container
      69         308 :     SequenceToSTLSequenceContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
      70             : {
      71         308 :     Container aResult( rSeq.getLength());
      72         308 :     ::std::copy( rSeq.getConstArray(), rSeq.getConstArray() + rSeq.getLength(),
      73             :                  aResult.begin() );
      74         308 :     return aResult;
      75             : }
      76             : 
      77             : /** converts a UNO sequence into a standard container. For convenience see the
      78             :     methods SequenceToVector, etc. below. (In contrast to
      79             :     SequenceToSTLSequenceContainer this works for all standard containers)
      80             : 
      81             :     input:  uno::Sequence
      82             :     output: a standard container that has an insert( iterator, key ) method (all
      83             :             standard containers)
      84             :     note:   for containers implementing the Concept of a Sequence (vector, deque,
      85             :             list, slist) use SequenceToSTLSequenceContainer for better speed
      86             : 
      87             :     example:
      88             : 
      89             :     Sequence< sal_Int32 > aSequence;
      90             :     ::std::set< sal_Int32 > aVector(
      91             :         ContainerToSequence::SequenceToSTLContainer< ::std::set< sal_Int32 > >( aSequence );
      92             : */
      93             : template< class Container >
      94             :     Container
      95             :     SequenceToSTLContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
      96             : {
      97             :     Container aResult;
      98             :     ::std::copy( rSeq.getConstArray(), rSeq.getConstArray() + rSeq.getLength(),
      99             :                  ::std::inserter< Container >( aResult, aResult.begin()));
     100             :     return aResult;
     101             : }
     102             : 
     103             : // concrete container methods for convenience
     104             : 
     105             : /** converts a UNO sequence into a standard vector of same value type
     106             : 
     107             :     example:
     108             : 
     109             :     Sequence< sal_Int32 > aSequence;
     110             :     ::std::vector< sal_Int32 > aVector( ContainerHelper::SequenceToVector( aSequence ));
     111             :  */
     112             : template< typename T >
     113             :     ::std::vector< T >
     114         308 :     SequenceToVector( const ::com::sun::star::uno::Sequence< T > & rSeq )
     115             : {
     116         308 :     return SequenceToSTLSequenceContainer< ::std::vector< T > >( rSeq );
     117             : }
     118             : 
     119             : /** converts a UNO sequence into a standard set of same value type
     120             : 
     121             :     example:
     122             : 
     123             :     Sequence< sal_Int32 > aSequence;
     124             :     ::std::set< sal_Int32 > aVector( ContainerHelper::SequenceToSet( aSequence ));
     125             :  */
     126             : template< typename T >
     127             :     ::std::set< T >
     128             :     SequenceToSet( const ::com::sun::star::uno::Sequence< T > & rSeq )
     129             : {
     130             :     return SequenceToSTLContainer< ::std::set< T > >( rSeq );
     131             : }
     132             : 
     133             : // ----------------------------------------
     134             : 
     135             : /** converts the keys of a Pair Associative Container into a UNO sequence
     136             : 
     137             :     example:
     138             : 
     139             :     ::std::multimap< sal_Int32, ::rtl::OUString > aMyMultiMap;
     140             :     uno::Sequence< sal_Int32 > aMyKeys( ContainerHelper::MapKeysToSequence( aMyMultiMap ));
     141             :     // note: aMyKeys may contain duplicate keys here
     142             :  */
     143             : template< class Map >
     144           0 : ::com::sun::star::uno::Sequence< typename Map::key_type > MapKeysToSequence(
     145             :     const Map & rCont )
     146             : {
     147           0 :     ::com::sun::star::uno::Sequence< typename Map::key_type > aResult( rCont.size());
     148           0 :     ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
     149             :                       ::o3tl::select1st< typename Map::value_type >());
     150           0 :     return aResult;
     151             : }
     152             : 
     153             : /** converts the values of a Pair Associative Container into a UNO sequence
     154             : 
     155             :     example:
     156             : 
     157             :     ::std::map< sal_Int32, ::rtl::OUString > aMyMultiMap;
     158             :     uno::Sequence< ::rtl::OUString > aMyValues( ContainerHelper::MapValuesToSequence( aMyMultiMap ));
     159             :  */
     160             : template< class Map >
     161           0 : ::com::sun::star::uno::Sequence< typename Map::mapped_type > MapValuesToSequence(
     162             :     const Map & rCont )
     163             : {
     164           0 :     ::com::sun::star::uno::Sequence< typename Map::mapped_type > aResult( rCont.size());
     165           0 :     ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
     166             :                       ::o3tl::select2nd< typename Map::value_type >());
     167           0 :     return aResult;
     168             : }
     169             : 
     170             : } // namespace ContainerHelper
     171             : } //  namespace chart
     172             : 
     173             : // CHART2_CONTAINERHELPER_HXX
     174             : #endif
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10