Skip to content

Commit

Permalink
feat: Adding option to specify delimiter for hierarchy store to allow…
Browse files Browse the repository at this point in the history
… multi level nesting
  • Loading branch information
optdcw committed Oct 29, 2023
1 parent 0f93e42 commit c18e678
Showing 1 changed file with 53 additions and 12 deletions.
65 changes: 53 additions & 12 deletions storage/basic/hiearchyflowstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,45 @@ class FSHiearchyWrapper : public FlowStore<FSHierarchyPacketInfo<Fs...>, FSHiera
F* m_fstore;
};

class ParserDelimiter
{
public:
virtual char get() = 0;
};

class ParserDelimiterPipe : ParserDelimiter
{
public:
char get() {
return '|';
}
};

template <typename ...Fs>
class ParserDelimiterColon : ParserDelimiter
{
public:
char get() {
return ':';
}
};

class ParserDelimiterComma : ParserDelimiter
{
public:
char get() {
return ',';
}
};

class ParserDelimiterTilda : ParserDelimiter
{
public:
char get() {
return '~';
}
};

template <typename ParserDelimiter = ParserDelimiterPipe, typename ...Fs>
class FlowStoreHiearchyParser : public OptionsParser {
public:
typedef std::tuple<
Expand Down Expand Up @@ -387,12 +423,14 @@ class FlowStoreHiearchyParser : public OptionsParser {
auto &p = std::get<I>(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;
Expand Down Expand Up @@ -430,8 +468,7 @@ class FlowStoreHiearchyParser : public OptionsParser {
}
};


template <typename ...Fs>
template <typename ParserDelim, typename ...Fs>
struct FSHTypes
{
typedef std::tuple<
Expand All @@ -451,7 +488,7 @@ struct FSHTypes
typedef typename range::iterator iter;
typedef FSHierarchyPacketInfo<Fs...> info;
typedef FSHierarchyAccessor<Fs...> access;
typedef FlowStoreHiearchyParser<Fs...> parser;
typedef FlowStoreHiearchyParser<ParserDelim, Fs...> parser;
typedef FlowStore
<
info,
Expand Down Expand Up @@ -557,12 +594,12 @@ struct FSHTypes
}
};

template <typename ...Fs>
class FlowStoreHiearchy : public FSHTypes<Fs...>::Base
template <typename ParserDelim, typename ...Fs>
class FlowStoreHiearchyFull : public FSHTypes<ParserDelim, Fs...>::Base
{
protected:
typedef FSHTypes<Fs...> Types;
typedef typename FSHTypes<Fs...>::Base Base;
typedef FSHTypes<ParserDelim, Fs...> Types;
typedef typename FSHTypes<ParserDelim, Fs...>::Base Base;
public:
typedef typename Types::range range;
typedef typename Types::wrap_stores wrap_stores;
Expand All @@ -582,7 +619,7 @@ class FlowStoreHiearchy : public FSHTypes<Fs...>::Base
}
};

FlowStoreHiearchy() : Base()
FlowStoreHiearchyFull() : Base()
{
for_each(m_fstores, ConstuctVisitor());
}
Expand Down Expand Up @@ -872,7 +909,11 @@ class FlowStoreHiearchy : public FSHTypes<Fs...>::Base
wrap_stores m_fstores;
};

}
/* Create a default hiearchy class without the Parser delimiter argument */
template <typename ...Fs>
class FlowStoreHiearchy : public FlowStoreHiearchyFull<ParserDelimiterPipe, Fs...> {
};

}

#endif //IPXP_HIEARCHY_STORE_HPP

0 comments on commit c18e678

Please sign in to comment.