From 5345ca742dee7adc1049db63f5086250a18b6b83 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Sat, 3 Mar 2012 13:12:34 +0100 Subject: [PATCH] Added: #1440 Pipeline project value parsing initial code --HG-- branch : build_pipeline_v3 --- .../pipeline/service/pipeline_project.cpp | 92 +++++++++++++++++++ .../tools/pipeline/service/pipeline_project.h | 9 ++ .../pipeline/service/pipeline_workspace.h | 2 + 3 files changed, 103 insertions(+) diff --git a/code/nel/tools/pipeline/service/pipeline_project.cpp b/code/nel/tools/pipeline/service/pipeline_project.cpp index df00cca9a..5fb842316 100644 --- a/code/nel/tools/pipeline/service/pipeline_project.cpp +++ b/code/nel/tools/pipeline/service/pipeline_project.cpp @@ -29,9 +29,11 @@ #include "pipeline_project.h" // STL includes +#include // NeL includes // #include +#include // Project includes @@ -50,6 +52,96 @@ CPipelineProject::~CPipelineProject() } +bool CPipelineProject::getValue(std::string &result, const std::string &name) +{ + std::string value; + if (!m_Form->getRootNode().getValueByName(value, name.c_str())) + { + nlwarning("Value '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + parseValue(result, value); + return true; +} + +bool CPipelineProject::getValues(std::vector &resultAppend, const std::string &name) +{ + NLGEORGES::UFormElm *elm; + if (!m_Form->getRootNode().getNodeByName(&elm, name.c_str())) + { + nlwarning("Node '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + uint size; + if (!elm->getArraySize(size)) + { + nlwarning("Array size of node '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + std::vector::size_type originalSize = resultAppend.size(); + resultAppend.reserve(resultAppend.size() + (std::vector::size_type)size); + for (uint i = 0; i < size; ++i) + { + std::string value; + if (!elm->getArrayValue(value, i)) + { + nlwarning("Array value of node '%s' at '%i' not found in '%s'", name.c_str(), i, m_Form->getFilename().c_str()); + resultAppend.resize(originalSize); + return false; + } + std::string parsed; + parseValue(parsed, value); + resultAppend.push_back(parsed); + } + return true; +} + +bool CPipelineProject::getValueNb(uint &result, const std::string &name) +{ + NLGEORGES::UFormElm *elm; + if (!m_Form->getRootNode().getNodeByName(&elm, name.c_str())) + { + nlwarning("Node '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + if (!elm->getArraySize(result)) + { + nlwarning("Array size of node '%s' not found in '%s'", name.c_str(), m_Form->getFilename().c_str()); + return false; + } + return true; +} + +void CPipelineProject::parseValue(std::string &result, const std::string &value) +{ + std::stringstream ss; + + std::string::const_iterator lastEnd = value.begin(); + std::string::const_iterator findOpen = find(lastEnd, value.end(), '['); + ss << std::string(lastEnd, findOpen); + while (findOpen != value.end()) + { + ++findOpen; + switch (*findOpen) + { + case '$': + // TODO + break; + case '@': + // TODO + break; + case '#': + // TODO + break; + default: + // TODO + break; + } + } + + result = ss.str(); +} + } /* namespace PIPELINE */ /* end of file */ diff --git a/code/nel/tools/pipeline/service/pipeline_project.h b/code/nel/tools/pipeline/service/pipeline_project.h index 1d0f939cc..0f44cd25f 100644 --- a/code/nel/tools/pipeline/service/pipeline_project.h +++ b/code/nel/tools/pipeline/service/pipeline_project.h @@ -51,10 +51,19 @@ class CPipelineProject protected: CPipelineWorkspace *m_Workspace; NLMISC::CRefPtr m_Form; + public: CPipelineProject(CPipelineWorkspace *workspace, NLGEORGES::UForm *form); virtual ~CPipelineProject(); + bool getValue(std::string &result, const std::string &name); + bool getValues(std::vector &resultAppend, const std::string &name); + bool getValueNb(uint &result, const std::string &name); + +private: + // Strip all macros and turn all macro paths into real paths. + void parseValue(std::string &result, const std::string &value); + }; /* class CPipelineProject */ } /* namespace PIPELINE */ diff --git a/code/nel/tools/pipeline/service/pipeline_workspace.h b/code/nel/tools/pipeline/service/pipeline_workspace.h index 7360bab90..ec9a34d67 100644 --- a/code/nel/tools/pipeline/service/pipeline_workspace.h +++ b/code/nel/tools/pipeline/service/pipeline_workspace.h @@ -64,6 +64,8 @@ struct CProcessPluginInfo */ class CPipelineWorkspace { + friend class CPipelineProject; + protected: NLGEORGES::UFormLoader *m_FormLoader; NLMISC::CRefPtr m_Form;