Tawara  0.1.0
vint.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 2012, Geoffrey Biggs, geoffrey.biggs@aist.go.jp
5  * RT-Synthesis Research Group
6  * Intelligent Systems Research Institute,
7  * National Institute of Advanced Industrial Science and Technology (AIST),
8  * Japan
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of Geoffrey Biggs nor AIST, nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #if !defined(TAWARA_VINT_H_)
40 #define TAWARA_VINT_H_
41 
42 #include <cstddef>
43 #include <istream>
44 #include <ostream>
45 #include <stdint.h>
46 #include <utility>
47 #include <vector>
48 
51 
52 namespace tawara
53 {
67  namespace vint
68  {
80  std::streamsize size(uint64_t integer);
81 
88  typedef std::pair<uint64_t, std::streamsize> OffsetInt;
103  OffsetInt s_to_u(int64_t integer);
104 
119  int64_t u_to_s(OffsetInt integer);
120 
142  std::vector<char> encode(uint64_t integer, std::streamsize req_size=0);
143 
148  typedef std::pair<uint64_t, std::vector<char>::const_iterator> DecodeResult;
149 
162  DecodeResult decode(std::vector<char> const& buffer);
163 
183  std::streamsize write(uint64_t integer, std::ostream& output,
184  std::streamsize req_size=0);
185 
189  typedef std::pair<uint64_t, std::streamsize> ReadResult;
190 
204  ReadResult read(std::istream& input);
205  }; // namespace vint
206 }; // namespace tawara
207 
209 // group utilities
210 
211 #endif // TAWARA_VINT_H_
212 
std::vector< char > encode(uint64_t integer, std::streamsize req_size=0)
Encode an unsigned integer into a buffer.
std::pair< uint64_t, std::streamsize > ReadResult
The result of a read operation is a pair of the integer read and the number of bytes read...
Definition: vint.h:189
std::streamsize size(uint64_t integer)
Get the size of an integer after encoding.
DecodeResult decode(std::vector< char > const &buffer)
Decode an unsigned variable-length integer from a buffer.
OffsetInt s_to_u(int64_t integer)
Offsets a signed integer into unsigned territory.
ReadResult read(std::istream &input)
Decode an unsigned integer from an input stream.
std::streamsize write(uint64_t integer, std::ostream &output, std::streamsize req_size=0)
Encode an unsigned integer and write it to an output stream.
std::pair< uint64_t, std::streamsize > OffsetInt
The result type of s_to_u().
Definition: vint.h:88
int64_t u_to_s(OffsetInt integer)
Offsets an unsigned integer into signed territory.
std::pair< uint64_t, std::vector< char >::const_iterator > DecodeResult
The result of a decode operation is a pair of the integer decoded and an iterator pointing to the fir...
Definition: vint.h:148