-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmi_model_impl.cpp
More file actions
138 lines (107 loc) · 3.39 KB
/
mi_model_impl.cpp
File metadata and controls
138 lines (107 loc) · 3.39 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "model_includes/impl/mi_model_impl.hpp"
#include "model_includes/impl/mi_file_impl.hpp"
#include "model_includes/impl/mi_include_impl.hpp"
#include "model_includes/impl/mi_include_location_impl.hpp"
#include "exception/ih/exc_internal_error.hpp"
#include <functional>
#include <memory>
//------------------------------------------------------------------------------
namespace model_includes
{
//------------------------------------------------------------------------------
ModelImpl::ModelImpl() = default;
ModelImpl::~ModelImpl() = default;
//------------------------------------------------------------------------------
std::size_t ModelImpl::getFilesCount() const
{
return m_files.size();
}
//------------------------------------------------------------------------------
void ModelImpl::forEachFile( FileCallback _callback ) const
{
for( const auto & pair: m_files )
{
const File * file = pair.second.get();
INTERNAL_CHECK_WARRING( file );
if( file != nullptr )
{
if( !_callback( *file ) )
{
break;
}
}
}
}
//------------------------------------------------------------------------------
void ModelImpl::setProjectDir( const Path & _path )
{
m_projectDir = _path;
}
//------------------------------------------------------------------------------
const ModelImpl::Path & ModelImpl::getProjectDir() const
{
return m_projectDir;
}
//------------------------------------------------------------------------------
File & ModelImpl::ensureFile( const Path & _filePath, FileType _fileType )
{
const auto path = stdfs::lexically_normal( _filePath );
auto pair = m_files.try_emplace( path, new FileImpl{ path, _fileType } );
auto it = pair.first;
FilePtr & filePtr = it->second;
INTERNAL_CHECK_ERROR( filePtr );
return *filePtr;
}
//------------------------------------------------------------------------------
const File * ModelImpl::findFile( const Path & _filePath ) const
{
if( auto it = m_files.find( _filePath ); it != m_files.end() )
{
return it->second.get();
}
return nullptr;
}
//------------------------------------------------------------------------------
void ModelImpl::forEachInclude( IncludeCallback _callback ) const
{
for( const IncludePtr & includePtr: m_includes )
{
INTERNAL_CHECK_WARRING( includePtr );
if( !includePtr )
{
continue;
}
if( !_callback( *includePtr ) )
{
break;
}
}
}
//------------------------------------------------------------------------------
const Include & ModelImpl::createInclude(
const IncludeLocationInfo & _location,
File & _sourceFile,
File & _destinationFile,
IncludeStatus _status,
IncludeType _type )
{
IncludeLocationPtr location = createIncludeLocation( _location );
IncludePtr includePtr{ new IncludeImpl{
std::move( location ), _sourceFile, _destinationFile, _status,
_type } };
INTERNAL_CHECK_WARRING( includePtr );
const Include & include = *includePtr;
m_includes.emplace_back( std::move( includePtr ) );
_sourceFile.addInclude( include );
_destinationFile.addInclude( include );
return include;
}
//------------------------------------------------------------------------------
ModelImpl::IncludeLocationPtr
ModelImpl::createIncludeLocation( const IncludeLocationInfo & _location ) const
{
return IncludeLocationPtr{ new IncludeLocationImpl{
_location.m_line, _location.m_begin, _location.m_end } };
}
//------------------------------------------------------------------------------
}