BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
padding_ostream.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 namespace graphene { namespace utilities {
27 
28 template<size_t BlockSize=16, char PaddingChar=' '>
30 public:
31  padding_ostream( fc::ostream_ptr o, size_t bufsize = 4096 ) : buffered_ostream(o, bufsize) {}
32  virtual ~padding_ostream() {}
33 
34  virtual size_t writesome( const char* buffer, size_t len ) {
35  auto out = buffered_ostream::writesome(buffer, len);
36  bytes_out += out;
37  bytes_out %= BlockSize;
38  return out;
39  }
40  virtual size_t writesome( const std::shared_ptr<const char>& buf, size_t len, size_t offset ) {
41  auto out = buffered_ostream::writesome(buf, len, offset);
42  bytes_out += out;
43  bytes_out %= BlockSize;
44  return out;
45  }
46  virtual void flush() {
47  static const char pad = PaddingChar;
48  while( bytes_out % BlockSize )
49  writesome(&pad, 1);
50  buffered_ostream::flush();
51  }
52 
53 private:
54  size_t bytes_out = 0;
55 };
56 
57 } } //graphene::utilities
58 
graphene::utilities::padding_ostream::writesome
virtual size_t writesome(const char *buffer, size_t len)
Definition: padding_ostream.hpp:34
graphene::utilities::padding_ostream::~padding_ostream
virtual ~padding_ostream()
Definition: padding_ostream.hpp:32
graphene::utilities::padding_ostream::flush
virtual void flush()
Definition: padding_ostream.hpp:46
graphene::utilities::padding_ostream::padding_ostream
padding_ostream(fc::ostream_ptr o, size_t bufsize=4096)
Definition: padding_ostream.hpp:31
graphene::utilities::padding_ostream::writesome
virtual size_t writesome(const std::shared_ptr< const char > &buf, size_t len, size_t offset)
Definition: padding_ostream.hpp:40
fc::buffered_ostream::buffered_ostream
buffered_ostream(ostream_ptr o, size_t bufsize=4096)
Definition: buffered_iostream.cpp:153
graphene::utilities::padding_ostream
Definition: padding_ostream.hpp:29
fc::buffered_ostream
Definition: buffered_iostream.hpp:52
graphene
Definition: api.cpp:48
fc::ostream_ptr
std::shared_ptr< ostream > ostream_ptr
Definition: iostream.hpp:59