fastcgi++
A C++ FastCGI/Web API
block.hpp
Go to the documentation of this file.
1 
10 /*******************************************************************************
11 * Copyright (C) 2017 Eddie Carle [eddie@isatec.ca] *
12 * *
13 * This file is part of fastcgi++. *
14 * *
15 * fastcgi++ is free software: you can redistribute it and/or modify it under *
16 * the terms of the GNU Lesser General Public License as published by the Free *
17 * Software Foundation, either version 3 of the License, or (at your option) *
18 * any later version. *
19 * *
20 * fastcgi++ is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for *
23 * more details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with fastcgi++. If not, see <http://www.gnu.org/licenses/>. *
27 *******************************************************************************/
28 
29 #ifndef BLOCK_HPP
30 #define BLOCK_HPP
31 
32 #include <memory>
33 
34 namespace Fastcgipp
35 {
37 
44  class Block
45  {
46  private:
48  size_t m_reserve;
49 
51  size_t m_size;
52 
54  std::unique_ptr<char[]> m_data;
55 
56  public:
58  Block();
59 
61  Block(const size_t size_);
62 
64  Block(const char* const data, const size_t size_);
65 
67 
71  void assign(const char* const data, const size_t size_);
72 
74  Block(Block&& x);
75 
77  Block& operator=(Block&& x);
78 
80  size_t reserve() const
81  {
82  return m_reserve;
83  }
84 
86 
91  void reserve(size_t x);
92 
94  size_t size() const
95  {
96  return m_size;
97  }
98 
100  void size(size_t x);
101 
103  char* begin()
104  {
105  return m_data.get();
106  }
107 
109  const char* begin() const
110  {
111  return m_data.get();
112  }
113 
115  char* end()
116  {
117  return m_data.get()+m_size;
118  }
119 
121  const char* end() const
122  {
123  return m_data.get()+m_size;
124  }
125 
127  void clear();
128 
129  Block(const Block&) =delete;
130  Block& operator=(const Block&) =delete;
131  };
132 }
133 
134 #endif
Topmost namespace for the fastcgi++ library.
void assign(const char *const data, const size_t size_)
Assign a sequence a data to the block.
Definition: block.cpp:105
size_t size() const
See the relevant data size.
Definition: block.hpp:94
size_t m_reserve
Total bytes allocated.
Definition: block.hpp:48
size_t m_size
Size of relevant part of data allocation.
Definition: block.hpp:51
std::unique_ptr< char[]> m_data
Point to allocated data.
Definition: block.hpp:54
size_t reserve() const
See the reserve size.
Definition: block.hpp:80
const char * end() const
Constant pointer to 1+ the last element.
Definition: block.hpp:121
void clear()
Deallocate memory and set size and reserve to zero.
Definition: block.cpp:98
Block & operator=(Block &&x)
Steal the data from another block.
Definition: block.cpp:78
char * end()
Pointer to 1+ the last element.
Definition: block.hpp:115
Block()
Initialize an empty block.
Definition: block.cpp:50
Data structure to hold a block of raw data.
Definition: block.hpp:44
const char * begin() const
Constant pointer to the first element.
Definition: block.hpp:109
char * begin()
Pointer to the first element.
Definition: block.hpp:103