-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmi_file_impl.cpp
More file actions
147 lines (114 loc) · 3.58 KB
/
mi_file_impl.cpp
File metadata and controls
147 lines (114 loc) · 3.58 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
139
140
141
142
143
144
145
146
147
#include "model_includes/impl/mi_file_impl.hpp"
#include "model_includes/api/mi_include.hpp"
#include "exception/ih/exc_internal_error.hpp"
#include <functional>
#include <list>
#include <std_fs>
#include <unordered_set>
//------------------------------------------------------------------------------
namespace model_includes
{
//------------------------------------------------------------------------------
FileImpl::FileImpl( Path _path, FileType _type )
: m_path{ std::move( _path ) }
, m_type{ _type }
{
}
//------------------------------------------------------------------------------
const FileImpl::Path & FileImpl::getPath() const
{
return m_path;
}
//------------------------------------------------------------------------------
FileType FileImpl::getType() const
{
return m_type;
}
//------------------------------------------------------------------------------
void FileImpl::addInclude( const Include & _include )
{
if( &_include.getSourceFile() == this )
{
m_includes.push_back( &_include );
}
else if( &_include.getDestinationFile() == this )
{
m_includedBy.push_back( &_include );
}
else
INTERNAL_CHECK_WARRING( false );
}
//------------------------------------------------------------------------------
File::IncludeIndex FileImpl::getIncludesCount() const
{
return m_includes.size();
}
//------------------------------------------------------------------------------
File::IncludeIndex FileImpl::getIncludeFilesCountRecursive() const
{
return getCountRecursive(
&File::getIncludesCount, &File::getInclude,
&Include::getDestinationFile );
}
//------------------------------------------------------------------------------
const Include & FileImpl::getInclude( IncludeIndex _index ) const
{
const Include * include = m_includes.at( _index );
INTERNAL_CHECK_ERROR( include );
return *include;
}
//------------------------------------------------------------------------------
File::IncludeIndex FileImpl::getIncludedByCount() const
{
return m_includedBy.size();
}
//------------------------------------------------------------------------------
File::IncludeIndex FileImpl::getIncludedByFilesCountRecursive() const
{
return getCountRecursive(
&File::getIncludedByCount, &File::getIncludedBy,
&Include::getSourceFile );
}
//------------------------------------------------------------------------------
const Include & FileImpl::getIncludedBy( IncludeIndex _index ) const
{
const Include * include = m_includedBy.at( _index );
INTERNAL_CHECK_ERROR( include );
return *include;
}
//------------------------------------------------------------------------------
FileImpl::IncludeIndex FileImpl::getCountRecursive(
IncludeIndex ( File::*_getCount )() const,
const Include & ( File::*_getInclude )( IncludeIndex _index ) const,
const File & ( Include::*_getFile )() const ) const
{
IncludeIndex result = 0;
std::list< const File * > files;
std::unordered_set< const File * > uniqFiles;
files.push_back( this );
uniqFiles.insert( this );
while( !files.empty() )
{
const File * currentFilePtr = files.front();
files.pop_front();
INTERNAL_CHECK_WARRING( currentFilePtr );
if( currentFilePtr == nullptr )
{
continue;
}
const IncludeIndex count = ( *currentFilePtr.*_getCount )();
for( IncludeIndex i = 0; i < count; ++i )
{
const Include & include = ( *currentFilePtr.*_getInclude )( i );
const File & file = ( include.*_getFile )();
if( auto pair = uniqFiles.insert( &file ); pair.second )
{
++result;
files.push_back( &file );
}
}
}
return result;
}
//------------------------------------------------------------------------------
}