-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProjectFile.cpp
More file actions
126 lines (107 loc) · 3.16 KB
/
ProjectFile.cpp
File metadata and controls
126 lines (107 loc) · 3.16 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
#include "pch.h"
#include "ProjectFile.h"
#include "Project.h"
#include <filesystem>
#include <algorithm>
using namespace std;
using namespace pugi;
using namespace std::filesystem;
string lowercased( string s )
{
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
}
ProjectFile::ProjectFile()
{
ReflectConnectChildren(nullptr);
}
void ProjectFile::VisitTool(
std::function<void(PlatformConfigurationProperties*)> visitConf,
CppTypeInfo* confType,
const wchar_t* _configurationName, const wchar_t* _platform)
{
if(!project)
return;
function<void(const wchar_t*, const wchar_t*)> visitTool = [&]( const wchar_t* configurationName, const wchar_t* platform )
{
auto it = find_if(tools.begin(), tools.end(), [&](auto& t) { return t->platform == platform && t->configurationName == configurationName; });
if (it != tools.end())
{
if(visitConf)
visitConf((*it).get());
return;
}
if(!confType)
return;
shared_ptr<PlatformConfigurationProperties> props;
confType->ReflectCreateInstance(props);
props->platform = platform;
props->configurationName = configurationName;
props->projectFile = this;
tools.push_back(props);
if (visitConf)
visitConf(props.get());
};
if (_configurationName == nullptr || _platform == nullptr)
{
project->VisitConfigurations
(
[&](VCConfiguration& c)
{
visitTool(c.configurationName.c_str(), c.platform.c_str());
},
_configurationName, _platform
);
}
else
{
visitTool(_configurationName, _platform);
}
}
//
// Generic autoprobe - file extension to guessed type.
//
EItemType ProjectFile::GetFromPath(const wchar_t* file)
{
string ext = lowercased(path(file).extension().string().substr(1));
struct TypeInfoStr
{
const char* ext;
EItemType type;
} types [] =
{
{"properties", AntProjectPropertiesFile},
{"h", ClInclude},
{"c", ClCompile},
{"cxx", ClCompile},
{"cpp", ClCompile},
{"cc", ClCompile},
{"java", JavaCompile},
{"template", GradleTemplate},
{"rc", ResourceCompile},
{"ico", Image},
{"txt", Text},
{"natvis", Natvis},
{"?", None}
};
TypeInfoStr* end = types + _countof(types) - 1;
return find_if(types, end, [ext](TypeInfoStr& ti) { return ti.ext == ext; } )->type;
}
void ProjectFile::OnAfterSetProperty(ReflectPath& path)
{
if(path.steps.size() == 1)
{
auto step = path.steps.front();
if(strcmp(step.propertyName, "ItemType") == 0)
{
FieldInfo* fi = step.typeInfo->GetField(step.propertyName);
CStringW newName = fi->fieldType->ToString((char*)step.instance->ReflectGetInstance() + fi->offset);
if(newName != node.name())
{
for(auto childnode: node.children())
node.remove_child(childnode);
node.set_name(newName);
}
}
}
}