summaryrefslogtreecommitdiff
path: root/libdbpp/dbTypes.h
blob: 5fd0e7be3bc00f7adeaf416c2ed29a3a7f73d4d0 (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
#ifndef DB_TYPES_H
#define DB_TYPES_H

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

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>
		// cppcheck-suppress noExplicitConstructor
		// 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