LCOV - code coverage report
Current view: top level - chart2/source/inc - ContainerHelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 20 20 100.0 %
Date: 2015-06-13 12:38:46 Functions: 26 40 65.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 INCLUDED_CHART2_SOURCE_INC_CONTAINERHELPER_HXX
      20             : #define INCLUDED_CHART2_SOURCE_INC_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      888343 :     ContainerToSequence( const Container & rCont )
      48             : {
      49      888343 :     ::com::sun::star::uno::Sequence< typename Container::value_type > aResult( rCont.size());
      50      888343 :     ::std::copy( rCont.begin(), rCont.end(), aResult.getArray());
      51      888343 :     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        4494 :     SequenceToSTLSequenceContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
      70             : {
      71        4494 :     Container aResult( rSeq.getLength());
      72        4494 :     ::std::copy( rSeq.begin(), rSeq.end(), aResult.begin() );
      73        4494 :     return aResult;
      74             : }
      75             : 
      76             : /** converts a UNO sequence into a standard container. For convenience see the
      77             :     methods SequenceToVector, etc. below. (In contrast to
      78             :     SequenceToSTLSequenceContainer this works for all standard containers)
      79             : 
      80             :     input:  uno::Sequence
      81             :     output: a standard container that has an insert( iterator, key ) method (all
      82             :             standard containers)
      83             :     note:   for containers implementing the Concept of a Sequence (vector, deque,
      84             :             list, slist) use SequenceToSTLSequenceContainer for better speed
      85             : 
      86             :     example:
      87             : 
      88             :     Sequence< sal_Int32 > aSequence;
      89             :     ::std::set< sal_Int32 > aVector(
      90             :         ContainerToSequence::SequenceToSTLContainer< ::std::set< sal_Int32 > >( aSequence );
      91             : */
      92             : template< class Container >
      93             :     Container
      94             :     SequenceToSTLContainer( const ::com::sun::star::uno::Sequence< typename Container::value_type > & rSeq )
      95             : {
      96             :     Container aResult;
      97             :     ::std::copy( rSeq.begin(), rSeq.end(),
      98             :                  ::std::inserter< Container >( aResult, aResult.begin()));
      99             :     return aResult;
     100             : }
     101             : 
     102             : // concrete container methods for convenience
     103             : 
     104             : /** converts a UNO sequence into a standard vector of same value type
     105             : 
     106             :     example:
     107             : 
     108             :     Sequence< sal_Int32 > aSequence;
     109             :     ::std::vector< sal_Int32 > aVector( ContainerHelper::SequenceToVector( aSequence ));
     110             :  */
     111             : template< typename T >
     112             :     ::std::vector< T >
     113        4494 :     SequenceToVector( const ::com::sun::star::uno::Sequence< T > & rSeq )
     114             : {
     115        4494 :     return SequenceToSTLSequenceContainer< ::std::vector< T > >( rSeq );
     116             : }
     117             : 
     118             : /** converts a UNO sequence into a standard set of same value type
     119             : 
     120             :     example:
     121             : 
     122             :     Sequence< sal_Int32 > aSequence;
     123             :     ::std::set< sal_Int32 > aVector( ContainerHelper::SequenceToSet( aSequence ));
     124             :  */
     125             : template< typename T >
     126             :     ::std::set< T >
     127             :     SequenceToSet( const ::com::sun::star::uno::Sequence< T > & rSeq )
     128             : {
     129             :     return SequenceToSTLContainer< ::std::set< T > >( rSeq );
     130             : }
     131             : 
     132             : /** converts the keys of a Pair Associative Container into a UNO sequence
     133             : 
     134             :     example:
     135             : 
     136             :     ::std::multimap< sal_Int32, OUString > aMyMultiMap;
     137             :     uno::Sequence< sal_Int32 > aMyKeys( ContainerHelper::MapKeysToSequence( aMyMultiMap ));
     138             :     // note: aMyKeys may contain duplicate keys here
     139             :  */
     140             : template< class Map >
     141         112 : ::com::sun::star::uno::Sequence< typename Map::key_type > MapKeysToSequence(
     142             :     const Map & rCont )
     143             : {
     144         112 :     ::com::sun::star::uno::Sequence< typename Map::key_type > aResult( rCont.size());
     145         112 :     ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
     146         224 :                       ::o3tl::select1st< typename Map::value_type >());
     147         112 :     return aResult;
     148             : }
     149             : 
     150             : /** converts the values of a Pair Associative Container into a UNO sequence
     151             : 
     152             :     example:
     153             : 
     154             :     ::std::map< sal_Int32, OUString > aMyMultiMap;
     155             :     uno::Sequence< OUString > aMyValues( ContainerHelper::MapValuesToSequence( aMyMultiMap ));
     156             :  */
     157             : template< class Map >
     158         112 : ::com::sun::star::uno::Sequence< typename Map::mapped_type > MapValuesToSequence(
     159             :     const Map & rCont )
     160             : {
     161         112 :     ::com::sun::star::uno::Sequence< typename Map::mapped_type > aResult( rCont.size());
     162         112 :     ::std::transform( rCont.begin(), rCont.end(), aResult.getArray(),
     163         224 :                       ::o3tl::select2nd< typename Map::value_type >());
     164         112 :     return aResult;
     165             : }
     166             : 
     167             : } // namespace ContainerHelper
     168             : } //  namespace chart
     169             : 
     170             : // INCLUDED_CHART2_SOURCE_INC_CONTAINERHELPER_HXX
     171             : #endif
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11