LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/cosv - bstream.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 19 19 100.0 %
Date: 2012-12-27 Functions: 13 16 81.2 %
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_BSTREAM_HXX
      21             : #define CSV_BSTREAM_HXX
      22             : 
      23             : #include <string.h>
      24             : #include <cosv/string.hxx>
      25             : 
      26             : 
      27             : namespace csv
      28             : {
      29             : 
      30             : 
      31             : enum seek_dir
      32             : {
      33             :     beg = 0,
      34             :     cur = 1,
      35             :     end = 2
      36             : };
      37             : 
      38             : 
      39       11971 : class bistream
      40             : {
      41             :   public:
      42             :     // LIFECYCLE
      43       11971 :     virtual             ~bistream() {}
      44             : 
      45             :     //  OPERATIONS
      46             :         /// @return Number of actually read bytes.
      47             :     uintt               read(
      48             :                             void *          out_pDest,
      49             :                             uintt           i_nNrofBytes);
      50             :     // INQUIRY
      51             :         /**  @return True, if already one try to read had failed.
      52             :              There is no guarantee, that it returns true, if end of data
      53             :              is just reached.
      54             :              Though it will return false, if there is still somemething
      55             :              to read.
      56             :         */
      57             :     bool                eod() const;
      58             : 
      59             :   private:
      60             :     virtual uintt       do_read(
      61             :                             void *          out_pDest,
      62             :                             uintt           i_nNrofBytes) = 0;
      63             :     virtual bool        inq_eod() const = 0;
      64             : };
      65             : 
      66             : 
      67       24560 : class bostream
      68             : {
      69             :   public:
      70             :     // LIFECYCLE
      71       24560 :     virtual             ~bostream() {}
      72             : 
      73             :     //  OPERATIONS
      74             :         /// @return Number of actually written bytes.
      75             :     uintt               write(
      76             :                             const void *    i_pSrc,
      77             :                             uintt           i_nNrofBytes);
      78             :         /// @return Number of actually written bytes.
      79             :     uintt               write(
      80             :                             const char *    i_pSrc );
      81             :         /// @return Number of actually written bytes.
      82             :     uintt               write(
      83             :                             const String &  i_pSrc );
      84             :   private:
      85             :     virtual uintt       do_write(
      86             :                             const void *    i_pSrc,
      87             :                             uintt           i_nNrofBytes) = 0;
      88             : };
      89             : 
      90             : 
      91       23942 : class bstream : public bistream,
      92             :                 public bostream
      93             : {
      94             :   public:
      95             :     uintt               seek(
      96             :                             intt            i_nDistanceFromBegin,
      97             :                             seek_dir        i_eStartPoint = ::csv::beg );
      98             :     uintt               position() const;
      99             : 
     100             :   private:
     101             :     virtual uintt       do_seek(
     102             :                             intt            i_nDistance,
     103             :                             seek_dir        i_eStartPoint = ::csv::beg ) = 0;
     104             :     virtual uintt       inq_position() const = 0;
     105             : };
     106             : 
     107             : 
     108             : // IMPLEMENTATION
     109             : inline uintt
     110      230127 : bistream::read( void *         o_pDest,
     111             :                uintt           i_nNrofBytes)
     112      230127 :     { return do_read(o_pDest, i_nNrofBytes); }
     113             : inline bool
     114        7337 : bistream::eod() const
     115        7337 :     { return inq_eod(); }
     116             : 
     117             : inline uintt
     118    13104129 : bostream::write( const void *   i_pSrc,
     119             :                  uintt          i_nNrofBytes)
     120    13104129 :     { return do_write( i_pSrc, i_nNrofBytes ); }
     121             : inline uintt
     122      385520 : bostream::write( const char * i_sSrc )
     123      385520 :     { return write( i_sSrc, strlen(i_sSrc) ); }
     124             : inline uintt
     125    10733291 : bostream::write( const String & i_sSrc )
     126    10733291 :     { return write( i_sSrc.c_str(), i_sSrc.length() ); }
     127             : 
     128             : inline uintt
     129       15609 : bstream::seek( intt     i_nDistance,
     130             :                seek_dir i_eStartPoint )
     131       15609 :     { return do_seek( i_nDistance, i_eStartPoint ); }
     132             : inline uintt
     133      480000 : bstream::position() const
     134      480000 :     { return inq_position(); }
     135             : 
     136             : 
     137             : 
     138             : }   // namespace csv
     139             : 
     140             : 
     141             : #endif
     142             : 
     143             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10