84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#include "tinyxml2.h"
|
|
|
|
#if defined(_MSC_VER) && !defined(__MINGW__)
|
|
#define CPP_STANDARD _MSVC_LANG
|
|
#else
|
|
#define CPP_STANDARD __cplusplus
|
|
#endif
|
|
|
|
#if CPP_STANDARD >= 201703L // 检查C++17或更高版本支持
|
|
#include <filesystem>
|
|
namespace fs = std::filesystem;
|
|
#elif CPP_STANDARD >= 201402L // 检查C++14或更高版本支持
|
|
#include <filesystem>
|
|
namespace fs = std::experimental::filesystem;
|
|
#else
|
|
#error "不支持的C++标准版本"
|
|
#endif
|
|
|
|
struct ProjectInfo {
|
|
std::string proj_root_{};
|
|
std::string path_{};
|
|
std::string name_{};
|
|
std::string guid_{};
|
|
// addtion_ ; 分隔
|
|
std::string addtion_{};
|
|
// predefinitaion ; 分隔
|
|
std::string predefinition_{};
|
|
// 关联的工程名称
|
|
std::vector<std::string> relate_{};
|
|
// 关联的GUID
|
|
std::vector<std::string> guid_relate_{};
|
|
};
|
|
|
|
class VsParseSln {
|
|
public:
|
|
VsParseSln();
|
|
~VsParseSln() = default;
|
|
|
|
public:
|
|
bool parse(const std::string& path);
|
|
std::vector<ProjectInfo> get_project() const;
|
|
|
|
private:
|
|
// 解析关联
|
|
void parse_relate();
|
|
|
|
private:
|
|
std::vector<ProjectInfo> projs_{};
|
|
std::unordered_map<std::string, std::string> hashmap_{};
|
|
};
|
|
|
|
class VsParsePro {
|
|
private:
|
|
tinyxml2::XMLDocument m_doc_{};
|
|
std::string addition_dir_{};
|
|
ProjectInfo* current_proj_{};
|
|
|
|
public:
|
|
VsParsePro() = default;
|
|
~VsParsePro() = default;
|
|
|
|
private:
|
|
void handle_include(tinyxml2::XMLElement* node, const std::string& key) const;
|
|
void additon_include_and_predefine(tinyxml2::XMLElement* node,
|
|
const std::string& key) const;
|
|
static tinyxml2::XMLElement* get_child_element(tinyxml2::XMLElement* node,
|
|
const std::string& key);
|
|
// 对初步解析出的工程进行整理
|
|
void tidy(ProjectInfo* proj);
|
|
// 补充其他信息
|
|
static void supplement(ProjectInfo* proj);
|
|
|
|
public:
|
|
// 对给定的工程初步解析
|
|
bool parse(ProjectInfo* proj, const std::string& key);
|
|
};
|