forked from heremaps/flatdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStruct.h
More file actions
66 lines (53 loc) · 1.52 KB
/
Struct.h
File metadata and controls
66 lines (53 loc) · 1.52 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
/**
* Copyright (c) 2017 HERE Europe B.V.
* See the LICENSE file in the root of this project for license details.
*/
#pragma once
#include "internal/Constants.h"
#include <array>
#include <type_traits>
namespace flatdata
{
/*
* A class that owns the memory of a single flatdata structure (+neccessary padding)
* Useful for creating individual struct that are to be stored in an archive one their own
* (as opposed to being stored in a vector/multi_vector)
*/
template < typename T >
class Struct
{
public:
using ValueType = typename T::MutatorType;
using ConstValueType = typename T::AccessorType;
using StreamType = typename T::MutatorType::StreamType;
using ConstStreamType = typename T::AccessorType::StreamType;
static_assert( !T::IS_OVERLAPPING_WITH_NEXT,
"Cannot use range/overlapping structs standalone" );
public:
Struct( );
ValueType operator*( );
ConstValueType operator*( ) const;
private:
std::array< typename std::remove_pointer< StreamType >::type,
T::size_in_bytes( ) + PADDING_SIZE >
m_data;
};
// -----------------------------------------------------------------------------
template < typename T >
Struct< T >::Struct( )
{
m_data.fill( 0 );
}
template < typename T >
typename Struct< T >::ConstValueType
Struct< T >::operator*( ) const
{
return ConstValueType{ m_data.data( ) };
}
template < typename T >
typename Struct< T >::ValueType
Struct< T >::operator*( )
{
return ValueType{ m_data.data( ) };
}
} // namespace flatdata