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 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 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 : /** \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 :
38 :
39 : /** \brief Contatenate two vectors together.
40 : *
41 : * This function appends vector v2 to vector v1 using a push_back()
42 : * of all the elements of v2.
43 : *
44 : * Note that the function fails to append anything is you write something
45 : * like this:
46 : *
47 : * \code
48 : * v1 += v1;
49 : * \endcode
50 : *
51 : * Instead, create a new vector and then add the source twice, something
52 : * like this:
53 : *
54 : * \code
55 : * vector<std::string> temp;
56 : * temp += v1;
57 : * v1 += temp;
58 : * \endcode
59 : *
60 : * \warning
61 : * This template is not put in the namespace because in some situation
62 : * it may not be visible (particularly in tests/catch_common.cpp,
63 : * somehow.) If you know of a fix for that then it would be great.
64 : * (I tried "using zipios;" but it did not work, maybe a specialization?)
65 : *
66 : * \param[in,out] v1 The vector which receives a copy of v2.
67 : * \param[in] v2 The vector to concatenate at the end of v1.
68 : */
69 : template<class Type>
70 64 : void operator += (std::vector<Type>& v1, std::vector<Type> const& v2)
71 : {
72 : // make sure these are not the same vector or the insert()
73 : // is not unlikely to fail badly; it is expected that the
74 : // user does not try to duplicate an array...
75 64 : if(&v1 != &v2)
76 : {
77 64 : v1.reserve(v1.size() + v2.size());
78 64 : v1.insert(v1.end(), v2.begin(), v2.end());
79 : }
80 64 : }
81 :
82 :
83 : namespace zipios
84 : {
85 :
86 :
87 : extern char const g_separator;
88 :
89 :
90 : typedef std::ostringstream OutputStringStream;
91 :
92 :
93 : typedef std::vector<unsigned char> buffer_t;
94 :
95 :
96 : void zipRead(std::istream& is, uint32_t& value);
97 : void zipRead(std::istream& is, uint16_t& value);
98 : void zipRead(std::istream& is, uint8_t& value);
99 : void zipRead(std::istream& is, buffer_t& buffer, ssize_t const count);
100 : void zipRead(std::istream& is, std::string& str, ssize_t const count);
101 :
102 : void zipRead(buffer_t const& is, size_t& pos, uint32_t& value);
103 : void zipRead(buffer_t const& is, size_t& pos, uint16_t& value);
104 : void zipRead(buffer_t const& is, size_t& pos, uint8_t& value);
105 : void zipRead(buffer_t const& is, size_t& pos, buffer_t& buffer, ssize_t const count);
106 : void zipRead(buffer_t const& is, size_t& pos, std::string& str, ssize_t const count);
107 :
108 : void zipWrite(std::ostream& os, uint32_t const& value);
109 : void zipWrite(std::ostream& os, uint16_t const& value);
110 : void zipWrite(std::ostream& os, uint8_t const& value);
111 : void zipWrite(std::ostream& os, buffer_t const& buffer);
112 : void zipWrite(std::ostream& os, std::string const& str);
113 :
114 :
115 : } // zipios namespace
116 :
117 : // Local Variables:
118 : // mode: cpp
119 : // indent-tabs-mode: nil
120 : // c-basic-offset: 4
121 : // tab-width: 4
122 : // End:
123 :
124 : // vim: ts=4 sw=4 et
125 : #endif
|