diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..cc579d72 --- /dev/null +++ b/CMakeLists.txt @@ -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}) diff --git a/src/metadata.cpp b/src/metadata.cpp index 41a80667..282276a1 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -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::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::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::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::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::iterator it = tags.begin(); it != tags.end(); ++it) { if (!it->EvalCondition()) { - it = tags.erase(it); + // it = tags.erase(it); --it; } } diff --git a/src/metadata.h b/src/metadata.h index 94484cde..9afc7ee4 100644 --- a/src/metadata.h +++ b/src/metadata.h @@ -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 loadAfter; std::list requirements; - std::set incompatibilities; + std::set incompatibilities; std::list messages; - std::set tags; + std::set tags; void EvalAllConditions(); }; + struct plugin_comp { + bool operator() (const Plugin& lhs, const Plugin& rhs) const { + return true; + } + }; } + +namespace YAML { + template<> + struct convert { + 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(); + if (node["type"]) + rhs.type = node["type"].as(); + if (node["content"]) + rhs.content = node["content"].as(); + if (node["lang"]) + rhs.language = node["lang"].as(); + return true; + } + }; + + template<> + struct convert { + 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(); + if (node["name"]) + rhs.name = node["name"].as(); + if (node["display"]) + rhs.name = node["display"].as(); + return true; + } + }; + + template<> + struct convert { + 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(); + if (node["name"]) + rhs.name = node["name"].as(); + } else if (node.IsScalar()) { + rhs.condition = ""; + rhs.name = node.as(); + } + return true; + } + }; + + template + struct convert< std::set > { + static Node encode(const std::set& rhs) { + Node node; + for (typename std::set::const_iterator it=rhs.begin(), endIt=rhs.end(); it != endIt; ++it) { + node.push_back(*it); + } + } + + static bool decode(const Node& node, std::set& rhs) { + if(!node.IsSequence()) + return false; + + rhs.clear(); + for(YAML::const_iterator it=node.begin();it!=node.end();++it) { + rhs.insert(it->as()); + } + return true; + + } + }; + + template<> + struct convert { + 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(); + if (node["enabled"]) + rhs.enabled = node["enabled"].as(); + if (node["priority"]) + rhs.priority = node["priority"].as(); + if (node["after"]) + rhs.loadAfter = node["after"].as< std::list >(); + if (node["req"]) + rhs.requirements = node["req"].as< std::list >(); + if (node["inc"]) + rhs.incompatibilities = node["inc"].as< std::set >(); + if (node["msg"]) + rhs.messages = node["msg"].as< std::list >(); + if (node["tag"]) + rhs.tags = node["tag"].as< std::set >(); + return true; + } + }; +} + #endif diff --git a/src/tester.cpp b/src/tester.cpp new file mode 100644 index 00000000..03e5f0f2 --- /dev/null +++ b/src/tester.cpp @@ -0,0 +1,56 @@ + +#include +#include "metadata.cpp" + +#include + +using namespace std; + +int main() { + + cout << "Testing masterlist parser." << endl; + + YAML::Node test = YAML::LoadFile("masterlist-example.yaml"); + + list 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()); + } + } + + set pluginData; + if (test["plugins"]) { + YAML::Node plugins = test["plugins"]; + for (YAML::const_iterator it=plugins.begin(); it != plugins.end(); ++it) { + pluginData.insert(it->as()); + } + } + + for (list::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::const_iterator it=pluginData.begin(), endIt=pluginData.end(); it != endIt; ++it) { + cout << it->name << endl; + for (list::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::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; +}