1 #ifndef FLASHMATCHFHICL_CXX 
    2 #define FLASHMATCHFHICL_CXX 
    9              const std::string data)
 
   12       std::cerr << 
"Cannot make PSet with an empty name!" << std::endl;
 
   13       throw std::exception();
 
   16     if(!data.empty()) this->
add(data);
 
   24     std::vector<std::string> res;
 
   26     for(
auto const& key_value : 
_data_value) res.push_back(key_value.first);
 
   27     for(
auto const& key_value : 
_data_pset ) res.push_back(key_value.first);
 
   33     std::vector<std::string> res;
 
   35     for(
auto const& key_value : 
_data_value) res.push_back(key_value.first);
 
   40     std::vector<std::string> res;
 
   42     for(
auto const& key_value : 
_data_pset) res.push_back(key_value.first);
 
   56     if(str.find(key) != 0) 
return;
 
   57     while(str.find(key) == 0)
 
   58       str = str.substr(key.size(),str.size());
 
   63     size_t index = str.rfind(key);
 
   64     if(index >= str.size()) 
return;
 
   65     while(key.size() == (str.size() - index)) {
 
   66       str = str.substr(0,index);
 
   67       index = str.rfind(key);
 
   68       if(index >= str.size()) 
break;
 
   83     if(txt.find(
" ") < txt.size()) {
 
   85       std::cerr << 
" Processing: " << txt.c_str() << 
" ... Space not allowed!" << std::endl;
 
   86       throw std::exception();
 
   88     if(txt.find(
"\t") < txt.size()) {
 
   89       std::cerr << 
"Tab not allowed!" << std::endl;
 
   90       throw std::exception();
 
   94   std::pair<PSet::KeyChar_t,size_t> 
PSet::search(
const std::string& txt, 
const size_t start)
 const 
   96     std::pair<KeyChar_t,size_t> res(
kNone,
size_t(-1));
 
  102     index = txt.find(
":",start);
 
  103     if(index != std::string::npos && index < res.second) {
 
  107     index = txt.find(
"{",start);
 
  108     if(index != std::string::npos && index < res.second) {
 
  112     index = txt.find(
"}",start);
 
  113     if(index != std::string::npos && index < res.second) {
 
  134       std::cerr << 
" Duplicate key: \"" << key << 
"\"" << std::endl;
 
  135       throw std::exception();
 
  139       std::cerr << 
"Empty key cannot be registered!" << std::endl;
 
  140       throw std::exception();
 
  152       std::cerr << 
" Duplicate key: \"" << p.
name() << 
"\"" << std::endl;
 
  153       throw std::exception();
 
  164       std::cerr << 
" Duplicate key: \"" << key << 
"\"" << std::endl;
 
  165       throw std::exception(); 
 
  169       std::cerr << 
"Empty key cannot be registered!" << std::endl;
 
  170       throw std::exception();
 
  179     if(contents.size()<1) 
return;
 
  181     while(contents.find(
" ",index) == index)
 
  183     if(index >= contents.size()) 
return;
 
  185     size_t end_index=contents.size()-1;
 
  186     while(contents.rfind(
" ",end_index) == end_index)
 
  189     if(end_index <= index || end_index > contents.size()) 
return;
 
  191     std::string key,
value,tmp;
 
  194     while(index <= end_index) {
 
  196       auto next_marker = this->
search(contents,index);
 
  198       if(next_marker.first == 
kString) {
 
  202         while(next_marker.second < end_index+1) {
 
  204           next_marker = this->
search(contents,next_marker.second+1);
 
  206           if(next_marker.first == 
kString) {
 
  207             next_marker = this->
search(contents,next_marker.second+1);
 
  214       if(next_marker.second > end_index) 
break;
 
  215       if(next_marker.first == 
kNone) 
break;
 
  225           key = contents.substr(index,(next_marker.second-index));
 
  229           tmp = contents.substr(index,(next_marker.second-index));
 
  233           size_t sep_index = tmp.rfind(
" ");
 
  234           if(sep_index >= tmp.size()) {
 
  235             std::cerr << 
"Invalid format (key:value)" << std::endl;
 
  236             throw std::exception();
 
  238           value = tmp.substr(0,sep_index);
 
  243           key = tmp.substr(sep_index+1,(tmp.size()-sep_index-1));
 
  247       }
else if(next_marker.first == 
kBlockEnd) {
 
  248         std::cerr << 
"Block end logic error!" << std::endl;
 
  249         throw std::exception();
 
  255           std::cerr << 
"Invalid paramter set start!" << std::endl;
 
  256           throw std::exception();
 
  261         index = next_marker.second + 1;
 
  262         while(start_ctr && next_marker.second <= end_index) {
 
  264           next_marker = this->
search(contents,next_marker.second+1);
 
  266           if(next_marker.first == 
kString) {
 
  268             while(next_marker.second < end_index+1) {
 
  270               next_marker = this->
search(contents,next_marker.second+1);
 
  272               auto tmp_next_marker = this->
search(contents,next_marker.second+1);
 
  274               if(next_marker.first == 
kString && tmp_next_marker.second != 
kString) {
 
  276                 next_marker = tmp_next_marker;
 
  284           switch(next_marker.first){
 
  297           std::cerr << 
"Invalid block:\n" << contents.substr(index,next_marker.second-index) << 
"\n" << std::endl;
 
  298           throw std::exception();
 
  300         value = contents.substr(index,next_marker.second-index);
 
  309         std::cerr << 
"Unknown error!" << std::endl;
 
  310         throw std::exception();
 
  313       index = next_marker.second+1;
 
  314       last_mark = next_marker.first;
 
  317     if(index <= end_index) {
 
  319       if(!value.empty()) { 
std::cerr << 
"Non-empty value @ process-end!" << std::endl; 
throw std::exception(); }
 
  320       if(key.empty()) { 
std::cerr << 
"Empty key @ process-end!" << std::endl; 
throw std::exception(); }
 
  322       tmp = contents.substr(index+1,end_index-index);
 
  325       if(tmp.empty()) { 
std::cerr << 
"Empty value @ end!" << std::endl; 
throw std::exception(); }
 
  333     if(!key.empty() || !value.empty()) {
 
  334       std::cerr << 
"Unpaired key:value!" << std::endl;
 
  335       throw std::exception();
 
  343     std::string res,in_indent,out_indent;
 
  344     for(
size_t i=0; i<indent_size; ++i) out_indent += 
" ";
 
  345     res = out_indent + 
_name + 
" : {\n";
 
  346     in_indent = out_indent + 
"  ";
 
  349       res += in_indent + key_value.first + 
" : " + key_value.second + 
"\n";
 
  353       res += key_value.second.dump(in_indent.size()) + 
"\n";
 
  355     res += out_indent + 
"}\n";
 
  366       res += key_value.first + 
": " + key_value.second + 
" ";
 
  370       res += key_value.second.data_string();
 
  381       std::cerr << 
"Key does not exist: \"" << key << 
"\"" << std::endl;
 
  382       throw std::exception();
 
  384     return (*iter).second;
 
  389   PSet PSet::get<flashmatch::PSet>(
const std::string& key) 
const 
  390   { 
return this->get_pset(key); }
 
bool contains_pset(const std::string &key) const 
Check if a specified key exists for key-PSet pairs. 
std::map< std::string, std::string > _data_value
Key-Value pairs. 
const std::vector< std::string > pset_keys() const 
Returns a vector of keys for key-PSet pairs. 
BEGIN_PROLOG could also be cerr
void no_space(std::string &txt)
void add_pset(const PSet &p)
Insert method for a PSet rep. 
const std::vector< std::string > keys() const 
Returns a vector of all parameter keys. 
void add_value(std::string key, std::string value)
Insert method for a simple param. 
const std::string & name() const 
name getter 
std::map< std::string,::flashmatch::PSet > _data_pset
Key-PSet pairs. 
const std::vector< std::string > value_keys() const 
Returns a vector of keys for key-value pairs. 
void rstrip(std::string &str, const std::string &key)
void trim_space(std::string &txt)
std::string _name
The name of this flashmatch::PSet. 
bool contains_value(const std::string &key) const 
Check if a specified key exists for key-value pairs. 
std::string data_string() const 
Dump data string. 
std::string dump(size_t indent_size=0) const 
Dump into a text format. 
void add(const std::string &data)
Set data contents. 
std::pair< PSet::KeyChar_t, size_t > search(const std::string &txt, const size_t start) const 
PSet(const std::string name="", const std::string data="")
Default constructor. 
size_t size() const 
Returns # of parameters. 
void strip(std::string &str, const std::string &key)
Class def header for a class flashmatch::PSet. 
const PSet & get_pset(const std::string &key) const 
None-template function to retrieve parameter set (deprecated) 
A nested configuration parameter set holder for flashmatch framework.