Skip to content

Commit b7f3d62

Browse files
Initial support for add new configurations & platforms.
1 parent 28ab9df commit b7f3d62

3 files changed

Lines changed: 64 additions & 21 deletions

File tree

SolutionProjectModel/Project.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Project.h"
22
#include <stdio.h>
33
using namespace pugi;
4+
using namespace std;
45

56
//
67
// Expose over .dll boundary
@@ -9,6 +10,42 @@ template class __declspec(dllexport) std::allocator<char>;
910
template class __declspec(dllexport) std::basic_string<char, std::char_traits<char>, std::allocator<char> >;
1011

1112

13+
template <class T, class I >
14+
bool vectorContains(const vector<T>& v, I& t)
15+
{
16+
bool found = (std::find(v.begin(), v.end(), t) != v.end());
17+
return found;
18+
}
19+
20+
21+
void Project::AddPlatform(const char* platform)
22+
{
23+
if (!vectorContains(platforms, platform))
24+
platforms.push_back(platform);
25+
}
26+
27+
28+
void Project::AddPlatforms(initializer_list<string> _platforms)
29+
{
30+
platforms.reserve(_platforms.size());
31+
for (initializer_list<string>::iterator i = _platforms.begin(); i != _platforms.end(); i++)
32+
AddPlatform(i->c_str());
33+
}
34+
35+
void Project::AddConfiguration(const char* configuration)
36+
{
37+
if (!vectorContains(configurations, configuration))
38+
configurations.push_back(configuration);
39+
}
40+
41+
void Project::AddConfigurations(std::initializer_list<std::string> _configurations)
42+
{
43+
configurations.reserve(_configurations.size());
44+
for (initializer_list<string>::iterator i = _configurations.begin(); i != _configurations.end(); i++)
45+
AddConfiguration(i->c_str());
46+
}
47+
48+
1249
bool Project::Load(const wchar_t* file)
1350
{
1451
xml_parse_result res = load_file(file, parse_default | parse_declaration | parse_ws_pcdata_single);
@@ -20,10 +57,11 @@ bool Project::Load(const wchar_t* file)
2057

2158
for (xml_node conf : node.children())
2259
{
23-
Configuration c;
24-
c.ConfigurationName = as_utf8(conf.child(L"Configuration").text().get());
25-
c.PlatformName = as_utf8(conf.child(L"Platform").text().get());
26-
Configurations.push_back(c);
60+
const wchar_t* xmltag[] = { L"Configuration" , L"Platform" };
61+
void (Project::*func [])(const char*) = { &Project::AddConfiguration, &Project::AddPlatform };
62+
63+
for( int i = 0; i < _countof(xmltag); i++)
64+
(this->*func[i])( as_utf8(conf.child(xmltag[i]).text().get()).c_str() );
2765
}
2866

2967
return true;

SolutionProjectModel/Project.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "../pugixml/pugixml.hpp"
33
#include <string>
44
#include <vector>
5+
#include <initializer_list>
56

67
#ifdef SPM_EXPORT
78
#define SPM_DLLEXPORT __declspec(dllexport)
@@ -15,27 +16,29 @@
1516
#pragma warning( disable: 4275 )
1617

1718
//---------------------------------------------------------
18-
// Project configuration
19+
// Project
1920
//---------------------------------------------------------
20-
class SPM_DLLEXPORT Configuration
21+
class SPM_DLLEXPORT Project : pugi::xml_document
2122
{
2223
public:
23-
// "Debug", "Release", user defined
24-
std::string ConfigurationName;
25-
2624
// "Win32", "х64", ...
27-
std::string PlatformName;
28-
};
25+
std::vector<std::string> platforms;
2926

27+
// "Debug", "Release", user defined
28+
std::vector<std::string> configurations;
3029

31-
//---------------------------------------------------------
32-
// Project
33-
//---------------------------------------------------------
34-
class SPM_DLLEXPORT Project : pugi::xml_document
35-
{
36-
public:
37-
std::vector<Configuration> Configurations;
30+
//
31+
// Add support for platform or configuration, if not yet added.
32+
//
33+
void AddPlatform(const char* platform);
34+
void AddPlatforms(std::initializer_list<std::string> _platforms);
35+
36+
void AddConfiguration(const char* configuration);
37+
void AddConfigurations(std::initializer_list<std::string> _configuration);
3838

39+
//
40+
// Loads .vcxproj file.
41+
//
3942
bool Load(const wchar_t* file);
4043
};
4144

SolutionProjectModel/testCppApp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
void main(void)
44
{
55
Project p;
6-
p.Load(L"testCppApp.vcxproj");
76

8-
printf("%s", p.Configurations[0].ConfigurationName.c_str());
9-
p.Configurations[0].ConfigurationName = "x64";
7+
//p.Load(L"testCppApp.vcxproj");
8+
//printf("%s", p.configurations[0].c_str());
9+
10+
p.AddPlatforms( { "Win32", "x64", "x64" } );
11+
1012
}
1113

0 commit comments

Comments
 (0)