-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathArchiveBuilder.cpp
More file actions
70 lines (60 loc) · 1.47 KB
/
ArchiveBuilder.cpp
File metadata and controls
70 lines (60 loc) · 1.47 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
/**
* Copyright (c) 2017 HERE Europe B.V.
* See the LICENSE file in the root of this project for license details.
*/
#include <flatdata/ArchiveBuilder.h>
#include <flatdata/internal/ArchiveUtils.h>
namespace flatdata
{
ArchiveBuilder::operator bool( ) const
{
return is_open( );
}
bool
ArchiveBuilder::is_open( ) const
{
return static_cast< bool >( m_storage );
}
ArchiveBuilder::ArchiveBuilder( std::shared_ptr< flatdata::ResourceStorage > storage )
: m_storage( std::move( storage ) )
{
}
flatdata::ResourceStorage&
ArchiveBuilder::storage( )
{
return *m_storage;
}
const flatdata::ResourceStorage&
ArchiveBuilder::storage( ) const
{
return *m_storage;
}
bool
ArchiveBuilder::is_created( ) const
{
return m_created;
}
void
ArchiveBuilder::check_created( ) const
{
if ( !is_created( ) )
{
throw std::runtime_error(
"Attempting to modify existing archive. Only subarchive creation is allowed" );
}
}
bool
ArchiveBuilder::initialize( )
{
const auto signature_name = internal::signature_name( name( ) );
if ( !storage( ).exists( signature_name.c_str( ) ) )
{
m_created = true;
return m_storage->write< flatdata::MemoryDescriptor >(
signature_name.c_str( ), schema( ), flatdata::MemoryDescriptor{ "", 0 } );
}
auto signature
= storage( ).read< flatdata::MemoryDescriptor >( signature_name.c_str( ), schema( ) );
return static_cast< bool >( signature );
}
} // namespace flatdata