summaryrefslogtreecommitdiff
path: root/libdbpp/dbTypes.h
blob: 6589784660d58c8f4bd3c3fe6773ed6944a4e536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef DB_TYPES_H
#define DB_TYPES_H

#include <visibility.h>
#include <cstdlib>
#include <vector>

namespace DB {
	/// Wrapper class for reference an existing block of binary data.
	class DLL_PUBLIC Blob {
		public:
			/// Construct a default blob pointing to no data.
			Blob() = default;
			/// Construct a reference using C-style pointer and length.
			Blob(const void * data, size_t len);
			/// Construct a reference using C++ template pointer to an object.
			template<typename T>
			explicit Blob(const T * t) :
				data(t),
				len(sizeof(T))
			{
			}
			/// Construct a reference using C++ vector pointer to a collection of objects.
			template<typename T>
			// NOLINTNEXTLINE(hicpp-explicit-conversions)
			Blob(const std::vector<T> & v) :
				data(&v.front()),
				len(sizeof(T) * v.size())
			{
			}

			/// Byte-wise equality operation.
			bool operator==(const DB::Blob b) const;

			/// The beginning of the binary data.
			const void * data { nullptr };
			/// The length of the binary data.
			size_t len { 0 };
	};
}

#endif