LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/cosv/tpl - tpltools.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 18 100.0 %
Date: 2012-12-27 Functions: 13 15 86.7 %
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 CSV_TPLTOOLS_HXX
      21             : #define CSV_TPLTOOLS_HXX
      22             : 
      23             : #include <vector>
      24             : #include <map>
      25             : 
      26             : 
      27             : 
      28             : 
      29             : namespace csv
      30             : {
      31             : 
      32             : 
      33             : template <class COLLECTION>
      34             : inline void         erase_container(
      35             :                         COLLECTION &        o_rCollection );
      36             : 
      37             : /// Version for other containers than std::map, with non-pair value_type.
      38             : template <class COLLECTION>
      39             : void                erase_container_of_heap_ptrs(
      40             :                         COLLECTION &        o_rCollection );
      41             : 
      42             : 
      43             : template <class KEY, class VAL>
      44             : const VAL *         find_in_map(            /// Usable for all kinds of values
      45             :                         const std::map< KEY, VAL > &
      46             :                                             i_rMap,
      47             :                         const KEY &         i_rKey );
      48             : 
      49             : 
      50             : /** @return the value in the map, if it is in there, else 0.
      51             :     @precond VAL has to be convertable to "0".
      52             : */
      53             : template <class KEY, class VAL>
      54             : VAL                 value_from_map(
      55             :                         const std::map< KEY, VAL > &
      56             :                                             i_rMap,
      57             :                         const KEY &         i_rKey );
      58             : 
      59             : /** @return the value in the map, if it is in there, else i_notFound.
      60             : */
      61             : template <class KEY, class VAL>
      62             : VAL                 value_from_map(
      63             :                         const std::map< KEY, VAL > &
      64             :                                             i_rMap,
      65             :                         const KEY &         i_rKey,
      66             :                         VAL                 i_notFound );
      67             : 
      68             : template <class COLLECTION, class VALUE>
      69             : bool                contains(
      70             :                         const COLLECTION &  i_collection,
      71             :                         const VALUE &       i_value );
      72             : 
      73             : 
      74             : 
      75             : 
      76             : // IMPLEMENTATION
      77             : template <class COLLECTION>
      78             : inline void
      79      251798 : erase_container( COLLECTION & o_rCollection )
      80             : {
      81      251798 :     o_rCollection.erase( o_rCollection.begin(),
      82             :                          o_rCollection.end() );
      83      251798 : }
      84             : 
      85             : template <class COLLECTION>
      86             : void
      87       27361 : erase_container_of_heap_ptrs( COLLECTION & o_rCollection )
      88             : {
      89       27361 :     typename COLLECTION::iterator itEnd = o_rCollection.end();
      90       92807 :     for ( typename COLLECTION::iterator it = o_rCollection.begin();
      91             :           it != itEnd;
      92             :           ++it )
      93             :     {
      94       65446 :         delete *it;
      95             :     }
      96             : 
      97       27361 :     o_rCollection.erase( o_rCollection.begin(),
      98             :                          o_rCollection.end() );
      99       27361 : }
     100             : 
     101             : template <class KEY, class VAL>
     102             : const VAL *
     103       10735 : find_in_map( const std::map< KEY, VAL > & i_rMap,
     104             :              const KEY &                  i_rKey )
     105             : {
     106             :     typename std::map< KEY, VAL >::const_iterator
     107       10735 :             ret =  i_rMap.find(i_rKey);
     108             :     return ret != i_rMap.end()
     109             :                 ?   & (*ret).second
     110       10735 :                 :   (const VAL*)0;
     111             : }
     112             : 
     113             : template <class KEY, class VAL>
     114             : VAL
     115        1125 : value_from_map( const std::map< KEY, VAL > & i_rMap,
     116             :                 const KEY &                  i_rKey )
     117             : {
     118             :     typename std::map< KEY, VAL >::const_iterator
     119        1125 :             ret =  i_rMap.find(i_rKey);
     120             :     return ret != i_rMap.end()
     121             :                 ?   (*ret).second
     122        1125 :                 :   VAL(0);
     123             : }
     124             : 
     125             : template <class KEY, class VAL>
     126             : VAL
     127      161347 : value_from_map( const std::map< KEY, VAL > & i_rMap,
     128             :                 const KEY &                  i_rKey,
     129             :                 VAL                          i_notFound )
     130             : {
     131             :     typename std::map< KEY, VAL >::const_iterator
     132      161347 :             ret =  i_rMap.find(i_rKey);
     133             :     return ret != i_rMap.end()
     134             :                 ?   (*ret).second
     135      161347 :                 :   i_notFound;
     136             : }
     137             : 
     138             : template <class COLLECTION, class VALUE>
     139             : bool
     140             : contains( const COLLECTION &  i_collection,
     141             :           const VALUE &       i_value )
     142             : {
     143             :     return std::find(i_collection.begin(), i_collection.end(), i_value)
     144             :            !=
     145             :            i_collection.end();
     146             : }
     147             : 
     148             : 
     149             : 
     150             : 
     151             : }   // namespace csv
     152             : #endif
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10