mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Parsing of test masterlist words.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
# Settings passed on the command line:
|
||||
#
|
||||
# LIBSTR_LIBS_DIR = the directory which all external libraries may be referenced from.
|
||||
# LIBSTR_ARCH = the build architecture
|
||||
# LIBSTR_LINK = whether to build a static or dynamic library.
|
||||
|
||||
##############################
|
||||
# General Settings
|
||||
##############################
|
||||
|
||||
cmake_minimum_required (VERSION 2.8.9)
|
||||
project (boss)
|
||||
|
||||
set (BOSS_SRC )
|
||||
|
||||
# Include source and library directories.
|
||||
include_directories ("${BOSS_LIBS_DIR}/boost" "${BOSS_LIBS_DIR}/yaml-cpp/include" "${CMAKE_SOURCE_DIR}/src")
|
||||
|
||||
##############################
|
||||
# Platform-Specific Settings
|
||||
##############################
|
||||
|
||||
# Settings when compiling for Windows.
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
#IF (${BOSS_LINK} MATCHES "STATIC")
|
||||
# add_definitions (-DBOSS_STATIC)
|
||||
#ELSE ()
|
||||
# add_definitions (-DBOSS_EXPORT)
|
||||
#ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
# Settings when compiling on Windows.
|
||||
IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
|
||||
#set (BOSS_LIBS libboost_filesystem-vc110-mt-1_52 libboost_system-vc110-mt-1_52)
|
||||
set (CMAKE_CXX_FLAGS "/EHsc")
|
||||
ENDIF ()
|
||||
|
||||
# Settings when compiling and cross-compiling on Linux.
|
||||
IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
|
||||
set (BOSS_LIBS yaml-cpp)
|
||||
set (CMAKE_C_FLAGS "-m${BOSS_ARCH}")
|
||||
set (CMAKE_CXX_FLAGS "-m${BOSS_ARCH}")
|
||||
set (CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static-libgcc")
|
||||
set (CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++ -static-libgcc")
|
||||
set (CMAKE_MODULE_LINKER_FLAGS "-static-libstdc++ -static-libgcc")
|
||||
|
||||
link_directories ("${BOSS_LIBS_DIR}/yaml-cpp/build/")
|
||||
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||
link_directories ("${BOSS_LIBS_DIR}/yaml-cpp/build/")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
# Settings when not cross-compiling.
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES CMAKE_HOST_SYSTEM_NAME)
|
||||
link_directories ("${BOSS_LIBS_DIR}/yaml-cpp/build/")
|
||||
ENDIF ()
|
||||
|
||||
##############################
|
||||
# Actual Building
|
||||
##############################
|
||||
|
||||
# Build tester.
|
||||
add_executable (parser-tester "${CMAKE_SOURCE_DIR}/src/tester.cpp")
|
||||
target_link_libraries (parser-tester ${BOSS_LIBS})
|
||||
+11
-8
@@ -27,10 +27,13 @@ using namespace std;
|
||||
|
||||
namespace boss {
|
||||
|
||||
ConditionalData::ConditionalData(string in) : condition(in) {}
|
||||
ConditionalData::ConditionalData() {}
|
||||
|
||||
ConditionalData::ConditionalData(const string in) : condition(in) {}
|
||||
|
||||
bool ConditionalData::EvalCondition() const {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Tag::Tag() : addTag(true) {}
|
||||
@@ -60,37 +63,37 @@ namespace boss {
|
||||
}
|
||||
|
||||
void Plugin::EvalAllConditions() {
|
||||
for (list::iterator it = loadAfter.begin(), endIt = loadAfter.end(); it != endIt; ++it) {
|
||||
for (list<File>::iterator it = loadAfter.begin(); it != loadAfter.end(); ++it) {
|
||||
if (!it->EvalCondition()) {
|
||||
it = loadAfter.erase(it);
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
for (list::iterator it = requirements.begin(), endIt = requirements.end(); it != endIt; ++it) {
|
||||
for (list<File>::iterator it = requirements.begin(); it != requirements.end(); ++it) {
|
||||
if (!it->EvalCondition()) {
|
||||
it = requirements.erase(it);
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
for (set::iterator it = incompatibilities.begin(), endIt = incompatibilities.end(); it != endIt; ++it) {
|
||||
for (set<File>::iterator it = incompatibilities.begin(); it != incompatibilities.end(); ++it) {
|
||||
if (!it->EvalCondition()) {
|
||||
it = incompatibilities.erase(it);
|
||||
// it = incompatibilities.erase(it);
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
for (list::iterator it = messages.begin(), endIt = messages.end(); it != endIt; ++it) {
|
||||
for (list<Message>::iterator it = messages.begin(); it != messages.end(); ++it) {
|
||||
if (!it->EvalCondition()) {
|
||||
it = messages.erase(it);
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
for (set::iterator it = tags.begin(), endIt = tags.end(); it != endIt; ++it) {
|
||||
for (set<Tag>::iterator it = tags.begin(); it != tags.end(); ++it) {
|
||||
if (!it->EvalCondition()) {
|
||||
it = tags.erase(it);
|
||||
// it = tags.erase(it);
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
+160
-2
@@ -31,6 +31,8 @@ namespace boss {
|
||||
|
||||
class ConditionalData {
|
||||
public:
|
||||
ConditionalData();
|
||||
ConditionalData(const std::string s);
|
||||
std::string condition;
|
||||
|
||||
bool EvalCondition() const;
|
||||
@@ -61,6 +63,18 @@ namespace boss {
|
||||
bool IsAddition() const;
|
||||
};
|
||||
|
||||
struct file_comp {
|
||||
bool operator() (const File& lhs, const File& rhs) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct tag_comp {
|
||||
bool operator() (const Tag& lhs, const Tag& rhs) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class Plugin {
|
||||
public:
|
||||
std::string name;
|
||||
@@ -68,12 +82,156 @@ namespace boss {
|
||||
int priority;
|
||||
std::list<File> loadAfter;
|
||||
std::list<File> requirements;
|
||||
std::set<File> incompatibilities;
|
||||
std::set<File, file_comp> incompatibilities;
|
||||
std::list<Message> messages;
|
||||
std::set<Tag> tags;
|
||||
std::set<Tag, tag_comp> tags;
|
||||
|
||||
void EvalAllConditions();
|
||||
};
|
||||
|
||||
struct plugin_comp {
|
||||
bool operator() (const Plugin& lhs, const Plugin& rhs) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace YAML {
|
||||
template<>
|
||||
struct convert<boss::Message> {
|
||||
static Node encode(const boss::Message& rhs) {
|
||||
Node node;
|
||||
node["condition"] = rhs.condition;
|
||||
node["type"] = rhs.type;
|
||||
node["content"] = rhs.content;
|
||||
node["lang"] = rhs.language;
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, boss::Message& rhs) {
|
||||
if(!node.IsMap())
|
||||
return false;
|
||||
|
||||
if (node["condition"])
|
||||
rhs.condition = node["condition"].as<std::string>();
|
||||
if (node["type"])
|
||||
rhs.type = node["type"].as<std::string>();
|
||||
if (node["content"])
|
||||
rhs.content = node["content"].as<std::string>();
|
||||
if (node["lang"])
|
||||
rhs.language = node["lang"].as<std::string>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<boss::File> {
|
||||
static Node encode(const boss::File& rhs) {
|
||||
Node node;
|
||||
node["condition"] = rhs.condition;
|
||||
node["name"] = rhs.name;
|
||||
node["display"] = rhs.display;
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, boss::File& rhs) {
|
||||
if(!node.IsMap())
|
||||
return false;
|
||||
|
||||
if (node["condition"])
|
||||
rhs.condition = node["condition"].as<std::string>();
|
||||
if (node["name"])
|
||||
rhs.name = node["name"].as<std::string>();
|
||||
if (node["display"])
|
||||
rhs.name = node["display"].as<std::string>();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<boss::Tag> {
|
||||
static Node encode(const boss::Tag& rhs) {
|
||||
Node node;
|
||||
node["condition"] = rhs.condition;
|
||||
node["name"] = rhs.name;
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, boss::Tag& rhs) {
|
||||
if(node.IsMap()) {
|
||||
if (node["condition"])
|
||||
rhs.condition = node["condition"].as<std::string>();
|
||||
if (node["name"])
|
||||
rhs.name = node["name"].as<std::string>();
|
||||
} else if (node.IsScalar()) {
|
||||
rhs.condition = "";
|
||||
rhs.name = node.as<std::string>();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, class Compare>
|
||||
struct convert< std::set<T, Compare> > {
|
||||
static Node encode(const std::set<T, Compare>& rhs) {
|
||||
Node node;
|
||||
for (typename std::set<T, Compare>::const_iterator it=rhs.begin(), endIt=rhs.end(); it != endIt; ++it) {
|
||||
node.push_back(*it);
|
||||
}
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, std::set<T, Compare>& rhs) {
|
||||
if(!node.IsSequence())
|
||||
return false;
|
||||
|
||||
rhs.clear();
|
||||
for(YAML::const_iterator it=node.begin();it!=node.end();++it) {
|
||||
rhs.insert(it->as<T>());
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct convert<boss::Plugin> {
|
||||
static Node encode(const boss::Plugin& rhs) {
|
||||
Node node;
|
||||
node["name"] = rhs.name;
|
||||
node["enabled"] = rhs.enabled;
|
||||
node["priority"] = rhs.priority;
|
||||
node["after"] = rhs.loadAfter;
|
||||
node["req"] = rhs.requirements;
|
||||
node["inc"] = rhs.incompatibilities;
|
||||
node["msg"] = rhs.messages;
|
||||
node["tag"] = rhs.tags;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static bool decode(const Node& node, boss::Plugin& rhs) {
|
||||
if(!node.IsMap())
|
||||
return false;
|
||||
|
||||
if (node["name"])
|
||||
rhs.name = node["name"].as<std::string>();
|
||||
if (node["enabled"])
|
||||
rhs.enabled = node["enabled"].as<bool>();
|
||||
if (node["priority"])
|
||||
rhs.priority = node["priority"].as<int>();
|
||||
if (node["after"])
|
||||
rhs.loadAfter = node["after"].as< std::list<boss::File> >();
|
||||
if (node["req"])
|
||||
rhs.requirements = node["req"].as< std::list<boss::File> >();
|
||||
if (node["inc"])
|
||||
rhs.incompatibilities = node["inc"].as< std::set<boss::File, boss::file_comp> >();
|
||||
if (node["msg"])
|
||||
rhs.messages = node["msg"].as< std::list<boss::Message> >();
|
||||
if (node["tag"])
|
||||
rhs.tags = node["tag"].as< std::set<boss::Tag, boss::tag_comp> >();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include "metadata.cpp"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
|
||||
cout << "Testing masterlist parser." << endl;
|
||||
|
||||
YAML::Node test = YAML::LoadFile("masterlist-example.yaml");
|
||||
|
||||
list<boss::Message> globalMessages;
|
||||
if (test["globals"]) {
|
||||
YAML::Node globals = test["globals"];
|
||||
for (YAML::const_iterator it=globals.begin(); it != globals.end(); ++it) {
|
||||
globalMessages.push_back(it->as<boss::Message>());
|
||||
}
|
||||
}
|
||||
|
||||
set<boss::Plugin, boss::plugin_comp> pluginData;
|
||||
if (test["plugins"]) {
|
||||
YAML::Node plugins = test["plugins"];
|
||||
for (YAML::const_iterator it=plugins.begin(); it != plugins.end(); ++it) {
|
||||
pluginData.insert(it->as<boss::Plugin>());
|
||||
}
|
||||
}
|
||||
|
||||
for (list<boss::Message>::const_iterator it=globalMessages.begin(), endIt=globalMessages.end(); it != endIt; ++it) {
|
||||
cout << "Message data:" << endl
|
||||
<< "\tCondition: " << it->condition << endl
|
||||
<< "\tType: " << it->type << endl
|
||||
<< "\tLanguage: " << it->language << endl
|
||||
<< "\tContent: " << it->content << endl;
|
||||
}
|
||||
|
||||
for (set<boss::Plugin, boss::plugin_comp>::const_iterator it=pluginData.begin(), endIt=pluginData.end(); it != endIt; ++it) {
|
||||
cout << it->name << endl;
|
||||
for (list<boss::Message>::const_iterator jt=it->messages.begin(), endJt=it->messages.end(); jt != endJt; ++jt) {
|
||||
cout << "\tMessage:" << endl
|
||||
<< "\t\tCondition: " << jt->condition << endl
|
||||
<< "\t\tType: " << jt->type << endl
|
||||
<< "\t\tLanguage: " << jt->language << endl
|
||||
<< "\t\tContent: " << jt->content << endl;
|
||||
}
|
||||
for (set<boss::Tag, boss::tag_comp>::const_iterator jt=it->tags.begin(), endJt=it->tags.end(); jt != endJt; ++jt) {
|
||||
cout << "\tTag:" << endl
|
||||
<< "\t\tCondition: " << jt->condition << endl
|
||||
<< "\t\tName: " << jt->name << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user