-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathMemoryDescriptor.h
More file actions
77 lines (66 loc) · 1.33 KB
/
MemoryDescriptor.h
File metadata and controls
77 lines (66 loc) · 1.33 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) 2017 HERE Europe B.V.
* See the LICENSE file in the root of this project for license details.
*/
#pragma once
#include <cstddef>
#include <cstdint>
#include <sstream>
namespace flatdata
{
struct MemoryDescriptor
{
public:
MemoryDescriptor( ) = default;
MemoryDescriptor( const uint8_t* ptr, size_t size )
: m_ptr( ptr )
, m_size( size )
{
}
MemoryDescriptor( const char* ptr, size_t size )
: MemoryDescriptor( reinterpret_cast< const uint8_t* >( ptr ), size )
{
}
explicit operator bool( ) const
{
return m_ptr != nullptr;
}
std::string
describe( size_t /*nest_level*/ = 0 ) const
{
std::ostringstream ss;
if ( this->operator bool( ) )
{
ss << "Raw data of size " << m_size;
}
else
{
ss << "Uninitialized Raw data";
}
return ss.str( );
}
const uint8_t*
data( ) const
{
return m_ptr;
}
const char*
char_ptr( ) const
{
return reinterpret_cast< const char* >( m_ptr );
}
size_t
size_in_bytes( ) const
{
return m_size;
}
size_t
size( ) const
{
return m_size;
}
private:
const uint8_t* m_ptr = nullptr;
size_t m_size = 0;
};
} // namespace flatdata