Browse Source

Gmt module: generate parameter name from template.

gmtdatadir
Michael Uleysky 8 years ago
parent
commit
8a24425a16
  1. 6
      modules/gmt/modgmt_param.h
  2. 28
      modules/gmt/modgmt_strcomp.h

6
modules/gmt/modgmt_param.h

@ -75,14 +75,12 @@ class Parameter
// Class for parameter which must be in named pair // Class for parameter which must be in named pair
template <class Converter, bool O> template <class Converter, bool O>
class NamedParameter: public Parameter<Converter,O>, public TemplateComparator class NamedParameter: public TemplateComparator, public Parameter<Converter,O>
{ {
public: public:
using AcceptableObject=void; using AcceptableObject=void;
template<class... Args> template<class... Args>
NamedParameter(const std::string& t, Args... args):Parameter<Converter,O>(t,args...),TemplateComparator(t) {} NamedParameter(const std::string& t, Args... args):TemplateComparator(t),Parameter<Converter,O>(Template2Name(),args...) {}
template<class... Args>
NamedParameter(std::pair<std::string,std::string>&& t, Args... args):Parameter<Converter,O>(std::move(t.first),args...),TemplateComparator(std::move(t.second)) {}
}; };

28
modules/gmt/modgmt_strcomp.h

@ -65,6 +65,34 @@ class TemplateComparator
for(size_t pos=0; pos<str.length(); ++pos) if(!CmpSmb(str[pos])) return false; for(size_t pos=0; pos<str.length(); ++pos) if(!CmpSmb(str[pos])) return false;
return true; return true;
} }
std::string Template2Name() const
{
const struct Block* b=root.get();
std::string res;
while(true)
{
// Processing current block
switch(b->type)
{
case(Block::TEXT): {res+=s.substr(b->b,b->e-b->b); break;}
case(Block::OPTIONAL): {b=b->child.get(); goto next;}
case(Block::VARIANTS): {b=b->child.get(); goto next;}
case(Block::DELIM): {b=b->parent; break;}
default: {}
}
// Go to next block
while(true)
{
if(nullptr!=b->next) {b=b->next.get(); goto next;}
if(nullptr!=b->parent) b=b->parent;
else break;
}
if(nullptr==b->next && nullptr==b->parent) break;
next: ;
}
return res;
}
}; };
#endif #endif

Loading…
Cancel
Save