LTP GCOV extension - code coverage report
Current view: | directory - usr/include/tagcoll-2.0.11/tagcoll/stream - sink.h
Test: | lcov.info
Date: | 2008-08-14 |  | Instrumented lines: | 8
Code covered: | 100.0 % |  | Executed lines: | 8

           1                 : #ifndef TAGCOLL_STREAM_SINK_H
           2                 : #define TAGCOLL_STREAM_SINK_H
           3                 :
           4                 : /** \file
           5                 :  * Consumer interface for a stream of tagged items
           6                 :  */
           7                 :
           8                 : /*
           9                 :  * Copyright (C) 2003,2004,2005,2006  Enrico Zini <enrico@debian.org>
          10                 :  *
          11                 :  * This library is free software; you can redistribute it and/or
          12                 :  * modify it under the terms of the GNU Lesser General Public
          13                 :  * License as published by the Free Software Foundation; either
          14                 :  * version 2.1 of the License, or (at your option) any later version.
          15                 :  *
          16                 :  * This library is distributed in the hope that it will be useful,
          17                 :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
          18                 :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
          19                 :  * Lesser General Public License for more details.
          20                 :  *
          21                 :  * You should have received a copy of the GNU Lesser General Public
          22                 :  * License along with this library; if not, write to the Free Software
          23                 :  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
          24                 :  */
          25                 :
          26                 : #include <wibble/mixin.h>
          27                 : #include <utility>
          28                 :
          29                 : namespace tagcoll {
          30                 : namespace stream {
          31                 :
          32                 : /**
          33                 :  * Consumer that discards its input
          34                 :  */
          35                 : class Sink : public wibble::mixin::OutputIterator<Sink>
          36                 : {
          37                 : public:
          38                 :         template<typename Data>
          39                 :         const Sink& operator=(const Data&) const { return *this; }
          40                 : };
          41                 :
          42                 : inline Sink sink()
          43                 : {
          44                 :         return Sink();
          45                 : }
          46                 :
          47                 :
          48                 : /**
          49                 :  * Consumer that discards its input
          50                 :  */
          51                 : template<typename COUNTER>
          52                 : class CountingSink : public wibble::mixin::OutputIterator< CountingSink<COUNTER> >
          53                 : {
          54                 :         COUNTER& countItems;
          55                 :         COUNTER& countTags;
          56                 :
          57                 : public:
          58               2 :         CountingSink(COUNTER& countItems, COUNTER& countTags) :
          59               2 :                 countItems(countItems), countTags(countTags) {}
          60                 :
          61                 :         // TODO: see if there's a way of implementing the count using size() when
          62                 :         // the method actually exists
          63                 :         template<typename ITEMS, typename TAGS>
          64           42266 :         CountingSink& operator=(const std::pair<ITEMS, TAGS>& data)
          65                 :         {
          66           42266 :                 countItems += data.first.size();
          67           42266 :                 countTags += data.second.size();
          68           42266 :                 return *this;
          69                 :         }
          70                 : };
          71                 :
          72                 : template<typename COUNTER>
          73               2 : inline CountingSink<COUNTER> countingSink(COUNTER& countItems, COUNTER& countTags)
          74                 : {
          75               2 :         return CountingSink<COUNTER>(countItems, countTags);
          76                 : }
          77                 :
          78                 :
          79                 : }
          80                 : }
          81                 :
          82                 : // vim:set ts=4 sw=4:
          83                 : #endif

Generated by: LTP GCOV extension version 1.6