From 42f97b0aa106881e00a2ce63c4cc704ebc34b707 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 9 Dec 2015 17:43:05 +0000 Subject: Allow poassing options to conversions --- slicer/slicer/parser.cpp | 22 +++++++++++++++++----- slicer/slicer/parser.h | 5 ++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 607ff36..ab0bc88 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -5,11 +5,13 @@ #include #include #include +#include #include #include #include #include #include +#include namespace fs = boost::filesystem; @@ -527,13 +529,13 @@ namespace Slicer { auto conversions = metaDataValues("slicer:conversion:", dm); for (const auto & conversion : conversions) { auto split = metaDataSplit(conversion); - if (split.size() != 3) { - throw std::runtime_error("conversion needs 3 parts type:toModelFunc:toExchangeFunc"); + if (split.size() < 3) { + throw std::runtime_error("conversion needs at least 3 parts type:toModelFunc:toExchangeFunc[:options]"); } - for (auto & p : split) { - boost::algorithm::replace_all(p, ".", "::"); + for (auto & pi : {0, 1, 2}) { + boost::algorithm::replace_all(split[pi], ".", "::"); } - rtn.push_back(ConversionSpec({split[0], split[1], split[2]})); + rtn.push_back(split); } return rtn; } @@ -597,5 +599,15 @@ namespace Slicer { return s.Components(); } + + Slicer::ConversionSpec::ConversionSpec(const Slicer::Args & s) : + ExchangeType(s[0]), + ConvertToModelFunc(s[1]), + ConvertToExchangeFunc(s[2]) + { + if (s.size() >= 4) { + boost::algorithm::split(Options, s[3], boost::algorithm::is_any_of(","), boost::algorithm::token_compress_off); + } + } }; diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index 744ffa7..322476f 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -11,14 +11,17 @@ namespace Slicer { class DLL_PUBLIC Slicer : public Slice::ParserVisitor { public: + typedef std::vector Args; class ConversionSpec { public: + ConversionSpec(const Args &); + std::string ExchangeType; std::string ConvertToModelFunc; std::string ConvertToExchangeFunc; + Args Options; }; typedef std::vector Conversions; - typedef std::vector Args; Slicer(FILE * c); -- cgit v1.2.3