FACT++  1.0
vector< MyColumn > FitsDumper::InitColumnsRoot ( vector< string > &  list)
private

Definition at line 542 of file fitsdump.cc.

References MyColumn::col, DumpRoot(), MyColumn::first, fits::GetColumns(), id, MyColumn::last, MyColumn::name, MyColumn::ptr, fits::SetPtrAddress(), and str.

Referenced by DumpRoot().

543 {
544  static const boost::regex expr("[^\\[]([[:word:].]+)(\\[([[:digit:]]+)\\])?");
545 
546  const fits::Table::Columns &cols = GetColumns();
547 
548  vector<MyColumn> vec;
549 
550  for (auto it=names.begin(); it!=names.end(); it++)
551  {
552  if (it->empty())
553  continue;
554 
555  *it = ' '+*it;
556 
557  string::const_iterator ibeg = it->begin();
558  string::const_iterator iend = it->end();
559 
560  boost::smatch what;
561  while (boost::regex_search(ibeg, iend, what, expr, boost::match_extra))
562  {
563  const string all = what[0];
564  const string name = what[1];
565  const size_t idx = atol(string(what[3]).c_str());
566 
567  // Check if found colum is valid
568  const auto ic = cols.find(name);
569  if (ic==cols.end())
570  {
571  ibeg++;
572  //cout << "Column '" << name << "' does not exist." << endl;
573  //return vector<MyColumn>();
574  continue;
575  }
576  if (idx>=ic->second.num)
577  {
578  cout << "Column '" << name << "' has no index " << idx << "." << endl;
579  return vector<MyColumn>();
580  }
581 
582  // find index if column already exists
583  size_t p = 0;
584  for (; p<vec.size(); p++)
585  if (vec[p].name==name)
586  break;
587 
588  const string id = '['+to_string(p)+']';
589 
590  // Replace might reallocate the memory. Therefore, we cannot use what[0].first
591  // directly but have to store the offset
592  const size_t offset = what[0].first - it->begin();
593 
594  it->replace(ibeg-it->begin()+what.position(1), what.length()-1, id);
595 
596  ibeg = it->begin() + offset + id.size();
597  iend = it->end();
598 
599  if (p<vec.size())
600  continue;
601 
602  // Column not found, add new column
603  MyColumn mycol;
604 
605  mycol.name = name;
606  mycol.col = ic->second;
607  mycol.first = idx;
608  mycol.last = idx;
609  mycol.ptr = SetPtrAddress(name);
610 
611  vec.push_back(mycol);
612  }
613  }
614 
615  ostringstream id;
616  id << '[' << vec.size() << ']';
617 
618  for (auto it=names.begin(); it!=names.end(); it++)
619  {
620  while (1)
621  {
622  auto p = it->find_first_of('#');
623  if (p==string::npos)
624  break;
625 
626  it->replace(p, 1, id.str());
627  }
628  }
629 
630  //cout << endl;
631  //for (size_t i=0; i<vec.size(); i++)
632  // cout << "val[" << i << "] = " << vec[i].name << '[' << vec[i].first << ']' << endl;
633  //cout << endl;
634 
635  return vec;
636 }
void * SetPtrAddress(const std::string &name)
Definition: fits.h:886
std::map< std::string, Column > Columns
Definition: fits.h:113
uint32_t last
Definition: fitsdump.cc:34
char str[80]
Definition: test_client.c:7
string name
Definition: fitsdump.cc:29
char id[4]
Definition: FITS.h:71
uint32_t first
Definition: fitsdump.cc:33
const Table::Columns & GetColumns() const
Definition: fits.h:1004
void * ptr
Definition: fitsdump.cc:36
fits::Table::Column col
Definition: fitsdump.cc:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function: