zookeeper-cpp
ZooKeeper Client for C++
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups
buffer.hpp
Go to the documentation of this file.
1 #pragma once
4 
5 #include <zk/config.hpp>
6 
7 #include <type_traits>
8 
11 
12 // \def ZKPP_BUFFER_USE_STD_STRING
13 // Set this to 1 to use \c std::string as the backing type for zk::buffer.
14 //
15 #ifndef ZKPP_BUFFER_USE_STD_STRING
16 # define ZKPP_BUFFER_USE_STD_STRING 0
17 #endif
18 
30 #ifndef ZKPP_BUFFER_USE_CUSTOM
31 # define ZKPP_BUFFER_USE_CUSTOM 0
32 #endif
33 
36 #ifndef ZKPP_BUFFER_USE_STD_VECTOR
37 # if ZKPP_BUFFER_USE_STD_STRING || ZKPP_BUFFER_USE_CUSTOM
38 # define ZKPP_BUFFER_USE_STD_VECTOR 0
39 # else
40 # define ZKPP_BUFFER_USE_STD_VECTOR 1
41 # endif
42 #endif
43 
44 #if ZKPP_BUFFER_USE_STD_VECTOR
45 # define ZKPP_BUFFER_INCLUDE <vector>
46 # define ZKPP_BUFFER_TYPE std::vector<char>
47 #elif ZKPP_BUFFER_USE_STD_STRING
48 # define ZKPP_BUFFER_INCLUDE <string>
49 # define ZKPP_BUFFER_TYPE std::string
50 #elif ZKPP_BUFFER_USE_CUSTOM
51 # if !defined ZKPP_BUFFER_INCLUDE || !defined ZKPP_BUFFER_TYPE
52 # error "When ZKPP_BUFFER_USE_CUSTOM is set, you must also define ZKPP_BUFFER_INCLUDE and ZKPP_BUFFER_TYPE"
53 # endif
54 #else
55 # error "Unknown type to use for zk::buffer"
56 #endif
57 
59 
60 #include ZKPP_BUFFER_INCLUDE
61 
62 namespace zk
63 {
64 
67 
80 
81 // Check through static_assert:
82 static_assert(sizeof(buffer::value_type) == 1, "buffer::value_type must be single-byte elements");
83 static_assert(std::is_same<std::size_t, buffer::size_type>::value, "buffer::size_type must be std::size_t");
84 static_assert(std::is_constructible<buffer, ptr<const buffer::value_type>, ptr<const buffer::value_type>>::value,
85  "buffer must be constructible with two pointers"
86  );
87 static_assert(std::is_move_constructible<buffer>::value, "buffer must be move-constructible");
88 static_assert(std::is_same<decltype(std::declval<const buffer&>().size()), buffer::size_type>::value,
89  "buffer::size() must return buffer::size_type"
90  );
91 static_assert(std::is_constructible<ptr<const buffer::value_type>,
92  decltype(std::declval<const buffer&>().data())
93  >::value,
94  "buffer::data() must return ptr<const buffer::value_type>"
95  );
96 
98 
99 }
T * ptr
A simple, unowned pointer.
Definition: config.hpp:37
#define ZKPP_BUFFER_TYPE
The type name to use for the buffer type.
Definition: buffer.hpp:46
ZKPP_BUFFER_TYPE buffer
The buffer type.
Definition: buffer.hpp:79