LCOV - code coverage report
Current view: top level - src - zipios_common.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 5 100.0 %
Date: 2019-04-24 14:10:30 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : #ifndef ZIPIOS_COMMON_HPP
       3             : #define ZIPIOS_COMMON_HPP
       4             : 
       5             : /*
       6             :   Zipios -- a small C++ library that provides easy access to .zip files.
       7             : 
       8             :   Copyright (C) 2000-2007  Thomas Sondergaard
       9             :   Copyright (C) 2015-2019  Made to Order Software Corporation
      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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      24             : */
      25             : 
      26             : /** \file
      27             :  * \brief Various functions used throughout the library.
      28             :  *
      29             :  * This file defines a small set of functions that do not really have
      30             :  * another place to live.
      31             :  */
      32             : 
      33             : #include "zipios/zipios-config.hpp"
      34             : 
      35             : #include <vector>
      36             : #include <sstream>
      37             : #include <stdint.h>
      38             : 
      39             : #if defined( ZIPIOS_WINDOWS )
      40             : typedef int32_t ssize_t;
      41             : #endif
      42             : 
      43             : 
      44             : /** \brief Contatenate two vectors together.
      45             :  *
      46             :  * This function appends vector v2 to vector v1 using a push_back()
      47             :  * of all the elements of v2.
      48             :  *
      49             :  * Note that the function fails to append anything is you write something
      50             :  * like this:
      51             :  *
      52             :  * \code
      53             :  *      v1 += v1;
      54             :  * \endcode
      55             :  *
      56             :  * Instead, create a new vector and then add the source twice, something
      57             :  * like this:
      58             :  *
      59             :  * \code
      60             :  *      vector<std::string> temp;
      61             :  *      temp += v1;
      62             :  *      v1 += temp;
      63             :  * \endcode
      64             :  *
      65             :  * \warning
      66             :  * This template is not put in the namespace because in some situation
      67             :  * it may not be visible (particularly in tests/catch_common.cpp,
      68             :  * somehow.) If you know of a fix for that then it would be great.
      69             :  * (I tried "using zipios;" but it did not work, maybe a specialization?)
      70             :  *
      71             :  * \param[in,out] v1  The vector which receives a copy of v2.
      72             :  * \param[in]  v2  The vector to concatenate at the end of v1.
      73             :  */
      74             : template<class Type>
      75          44 : void operator += (std::vector<Type>& v1, std::vector<Type> const& v2)
      76             : {
      77             :     // make sure these are not the same vector or the insert()
      78             :     // is not unlikely to fail badly; it is expected that the
      79             :     // user does not try to duplicate an array...
      80          44 :     if(&v1 != &v2)
      81             :     {
      82          44 :         v1.reserve(v1.size() + v2.size());
      83          44 :         v1.insert(v1.end(), v2.begin(), v2.end());
      84             :     }
      85          44 : }
      86             : 
      87             : 
      88             : namespace zipios
      89             : {
      90             : 
      91             : 
      92             : extern char const g_separator;
      93             : 
      94             : 
      95             : typedef std::ostringstream OutputStringStream;
      96             : 
      97             : 
      98             : typedef std::vector<unsigned char>      buffer_t;
      99             : 
     100             : 
     101             : void     zipRead(std::istream& is, uint32_t& value);
     102             : void     zipRead(std::istream& is, uint16_t& value);
     103             : void     zipRead(std::istream& is, uint8_t&  value);
     104             : void     zipRead(std::istream& is, buffer_t& buffer, ssize_t const count);
     105             : void     zipRead(std::istream& is, std::string& str, ssize_t const count);
     106             : 
     107             : void     zipRead(buffer_t const& is, size_t& pos, uint32_t& value);
     108             : void     zipRead(buffer_t const& is, size_t& pos, uint16_t& value);
     109             : void     zipRead(buffer_t const& is, size_t& pos, uint8_t&  value);
     110             : void     zipRead(buffer_t const& is, size_t& pos, buffer_t& buffer, ssize_t const count);
     111             : void     zipRead(buffer_t const& is, size_t& pos, std::string& str, ssize_t const count);
     112             : 
     113             : void     zipWrite(std::ostream& os, uint32_t const& value);
     114             : void     zipWrite(std::ostream& os, uint16_t const& value);
     115             : void     zipWrite(std::ostream& os, uint8_t const&  value);
     116             : void     zipWrite(std::ostream& os, buffer_t const& buffer);
     117             : void     zipWrite(std::ostream& os, std::string const& str);
     118             : 
     119             : 
     120             : } // zipios namespace
     121             : 
     122             : // Local Variables:
     123             : // mode: cpp
     124             : // indent-tabs-mode: nil
     125             : // c-basic-offset: 4
     126             : // tab-width: 4
     127             : // End:
     128             : 
     129             : // vim: ts=4 sw=4 et
     130             : #endif

Generated by: LCOV version 1.12