From c18e67822c7f07914f8664b619e9bfb7dd25c959 Mon Sep 17 00:00:00 2001 From: Tomas Benes Date: Sun, 29 Oct 2023 06:58:03 +0100 Subject: [PATCH] feat: Adding option to specify delimiter for hierarchy store to allow multi level nesting --- storage/basic/hiearchyflowstore.hpp | 65 +++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/storage/basic/hiearchyflowstore.hpp b/storage/basic/hiearchyflowstore.hpp index ced3d0b8..cf530fd3 100644 --- a/storage/basic/hiearchyflowstore.hpp +++ b/storage/basic/hiearchyflowstore.hpp @@ -355,9 +355,45 @@ class FSHiearchyWrapper : public FlowStore, FSHiera F* m_fstore; }; +class ParserDelimiter +{ +public: + virtual char get() = 0; +}; +class ParserDelimiterPipe : ParserDelimiter +{ +public: + char get() { + return '|'; + } +}; -template +class ParserDelimiterColon : ParserDelimiter +{ +public: + char get() { + return ':'; + } +}; + +class ParserDelimiterComma : ParserDelimiter +{ +public: + char get() { + return ','; + } +}; + +class ParserDelimiterTilda : ParserDelimiter +{ +public: + char get() { + return '~'; + } +}; + +template class FlowStoreHiearchyParser : public OptionsParser { public: typedef std::tuple< @@ -387,12 +423,14 @@ class FlowStoreHiearchyParser : public OptionsParser { auto &p = std::get(t); auto &destStr = std::get<0>(p); auto &parser = std::get<1>(p); - parser.setDelim('|'); + char parserDelim = ParserDelimiter().get(); + parser.setDelim(parserDelim); + std::string helpString = std::string("ARG1") + parserDelim + std::string("ARG2") + parserDelim + std::string("ARG3"); std::stringstream ss; ss << std::endl; parser.usage(ss, 8); - register_option((std::to_string(I)), ("--" + std::to_string(I)), std::string("ARG1|ARG2|ARG3"), std::string(ss.str()), + register_option((std::to_string(I)), ("--" + std::to_string(I)), helpString, std::string(ss.str()), [&](const char *arg) { destStr = std::string(arg); return true; @@ -430,8 +468,7 @@ class FlowStoreHiearchyParser : public OptionsParser { } }; - -template +template struct FSHTypes { typedef std::tuple< @@ -451,7 +488,7 @@ struct FSHTypes typedef typename range::iterator iter; typedef FSHierarchyPacketInfo info; typedef FSHierarchyAccessor access; - typedef FlowStoreHiearchyParser parser; + typedef FlowStoreHiearchyParser parser; typedef FlowStore < info, @@ -557,12 +594,12 @@ struct FSHTypes } }; -template -class FlowStoreHiearchy : public FSHTypes::Base +template +class FlowStoreHiearchyFull : public FSHTypes::Base { protected: - typedef FSHTypes Types; - typedef typename FSHTypes::Base Base; + typedef FSHTypes Types; + typedef typename FSHTypes::Base Base; public: typedef typename Types::range range; typedef typename Types::wrap_stores wrap_stores; @@ -582,7 +619,7 @@ class FlowStoreHiearchy : public FSHTypes::Base } }; - FlowStoreHiearchy() : Base() + FlowStoreHiearchyFull() : Base() { for_each(m_fstores, ConstuctVisitor()); } @@ -872,7 +909,11 @@ class FlowStoreHiearchy : public FSHTypes::Base wrap_stores m_fstores; }; -} +/* Create a default hiearchy class without the Parser delimiter argument */ +template +class FlowStoreHiearchy : public FlowStoreHiearchyFull { +}; +} #endif //IPXP_HIEARCHY_STORE_HPP