From 47199a38d11c86f90a28b40ee21b3e5ec2b1aea2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 4 Jan 2015 14:28:11 +0000 Subject: Split metadata helpers into their own file --- slicer/slicer/metadata.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ slicer/slicer/metadata.h | 20 +++++++++++++++++++ slicer/slicer/parser.cpp | 33 +------------------------------ slicer/slicer/parser.h | 3 --- 4 files changed, 69 insertions(+), 35 deletions(-) create mode 100644 slicer/slicer/metadata.cpp create mode 100644 slicer/slicer/metadata.h diff --git a/slicer/slicer/metadata.cpp b/slicer/slicer/metadata.cpp new file mode 100644 index 0000000..da861ca --- /dev/null +++ b/slicer/slicer/metadata.cpp @@ -0,0 +1,48 @@ +#include "metadata.h" +#include +#include +#include + +bool +Slicer::metaDataFlagSet(const std::list & md, const std::string & flag) +{ + return std::find(md.cbegin(), md.cend(), flag) != md.cend(); +} + +bool +Slicer::metaDataFlagNotSet(const std::list & md, const std::string & flag) +{ + return std::find(md.cbegin(), md.cend(), flag) == md.cend(); +} + +std::list +Slicer::metaDataValues(const std::string & prefix, const std::list & metadata) +{ + std::list mds; + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, prefix)) { + mds.push_back(md.substr(prefix.length())); + } + } + return mds; +} + +std::vector +Slicer::metaDataSplit(const std::string & metadata) +{ + std::vector parts; + boost::algorithm::split(parts, metadata, boost::algorithm::is_any_of(":"), boost::algorithm::token_compress_off); + return parts; +} + +boost::optional +Slicer::metaDataValue(const std::string & prefix, const std::list & metadata) +{ + for (const auto & md : metadata) { + if (boost::algorithm::starts_with(md, prefix)) { + return md.substr(prefix.length()); + } + } + return boost::optional(); +} + diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h new file mode 100644 index 0000000..2ed26b8 --- /dev/null +++ b/slicer/slicer/metadata.h @@ -0,0 +1,20 @@ +#ifndef SLICER_METADATA_H +#define SLICER_METADATA_H + +#include +#include +#include +#include + +namespace Slicer { + // Flags + bool metaDataFlagSet(const std::list &, const std::string & flag); + bool metaDataFlagNotSet(const std::list &, const std::string & flag); + // Values + boost::optional metaDataValue(const std::string & prefix, const std::list & metadata); + std::list metaDataValues(const std::string & prefix, const std::list & metadata); + std::vector metaDataSplit(const std::string & metadata); +} + +#endif + diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp index 9c72d09..bdd42ec 100644 --- a/slicer/slicer/parser.cpp +++ b/slicer/slicer/parser.cpp @@ -1,9 +1,8 @@ #include "parser.h" +#include "metadata.h" #include #include #include -#include -#include #include #include #include @@ -428,36 +427,6 @@ namespace Slicer { fprintf(cpp, "};\n\n"); } - boost::optional - Slicer::metaDataValue(const std::string & prefix, const std::list & metadata) - { - for (const auto & md : metadata) { - if (boost::algorithm::starts_with(md, prefix)) { - return md.substr(prefix.length()); - } - } - return boost::optional(); - } - - std::list - Slicer::metaDataValues(const std::string & prefix, const std::list & metadata) - { - std::list mds; - for (const auto & md : metadata) { - if (boost::algorithm::starts_with(md, prefix)) { - mds.push_back(md.substr(prefix.length())); - } - } - return mds; - } - - std::vector - Slicer::metaDataSplit(const std::string & metadata) - { - std::vector parts; - boost::algorithm::split(parts, metadata, boost::algorithm::is_any_of(":"), boost::algorithm::token_compress_off); - return parts; - } std::vector Slicer::getConversions(Slice::DataMemberPtr dm) diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h index f53e62e..9be2465 100644 --- a/slicer/slicer/parser.h +++ b/slicer/slicer/parser.h @@ -48,9 +48,6 @@ namespace Slicer { void defineConversions(Slice::DataMemberPtr dm) const; void copyMetadata(const std::list & metadata) const; - static boost::optional metaDataValue(const std::string & prefix, const std::list & metadata); - static std::list metaDataValues(const std::string & prefix, const std::list & metadata); - static std::vector metaDataSplit(const std::string & metadata); static std::vector getConversions(Slice::DataMemberPtr); unsigned int components; -- cgit v1.2.3