-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcdb_loader_impl.cpp
More file actions
102 lines (80 loc) · 2.33 KB
/
cdb_loader_impl.cpp
File metadata and controls
102 lines (80 loc) · 2.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "compilation_db/impl/cdb_loader_impl.hpp"
#include "compilation_db/impl/cdb_database_impl.hpp"
#include "compilation_db/resources/cdb_resources.hpp"
#include "json/api/json_array.hpp"
#include "json/api/json_object.hpp"
#include "json/api/json_value.hpp"
#include "exception/ih/exc_internal_error.hpp"
#include <memory>
#include <string_view>
//------------------------------------------------------------------------------
namespace compilation_db
{
//------------------------------------------------------------------------------
LoaderImpl::DatabasePtr LoaderImpl::load( const json::JsonObject & _json )
{
DatabasePtr result{ createEmptyDb() };
auto valueObjectPtr = _json.asValue();
if( !valueObjectPtr )
{
INTERNAL_CHECK_WARRING( false );
return result;
}
auto arrayPtr = valueObjectPtr->asArray();
if( !arrayPtr )
{
INTERNAL_CHECK_WARRING( false );
return result;
}
const json::JsonArray & array = *arrayPtr;
const json::JsonArray::ArrayIndex size = array.getSize();
for( json::JsonArray::ArrayIndex i = 0; i < size; ++i )
{
auto itemPtr = array.at( i );
INTERNAL_CHECK_WARRING( itemPtr );
if( itemPtr )
{
loadItem( *itemPtr, *result );
}
}
return result;
}
//------------------------------------------------------------------------------
LoaderImpl::DatabasePtr LoaderImpl::createEmptyDb()
{
return DatabasePtr{ new DatabaseImpl };
}
//------------------------------------------------------------------------------
void LoaderImpl::loadItem( const json::JsonValue & _value, Database & _db )
{
auto objectPtr = _value.asObject();
if( !objectPtr )
{
INTERNAL_CHECK_WARRING( false );
return;
}
auto directoryPtr = objectPtr->getAttributeValue( resources::Directory );
if( !directoryPtr )
{
INTERNAL_CHECK_WARRING( false );
return;
}
auto commandPtr = objectPtr->getAttributeValue( resources::Command );
if( !commandPtr )
{
INTERNAL_CHECK_WARRING( false );
return;
}
auto filePtr = objectPtr->getAttributeValue( resources::File );
if( !filePtr )
{
INTERNAL_CHECK_WARRING( false );
return;
}
const std::string directory = directoryPtr->asString();
const std::string command = commandPtr->asString();
const std::string file = filePtr->asString();
_db.addCommand( directory, command, file );
}
//------------------------------------------------------------------------------
}