FACT++  1.0
template<class T >
T Converter::Get ( const void *  dat,
size_t  size 
) const
private

Converts the provided data block into a vector of boost::any or a string.

Template Parameters
TKind of data to be returned. This can either be boost::any objects or a string
Returns
A vector of the given template type containing the arguments. In case of failure an empty vector is returned.
Exceptions
std::runtime_errorif the conversion was not successfull

Definition at line 656 of file Converter.cc.

References AddString(), fFormat, fList, GetSize(), i, and valid().

657 {
658  if (!valid())
659  throw runtime_error("Compiled format invalid!");
660 
661  if (dat==0)
662  throw runtime_error("Data pointer == NULL!");
663 
664  const char *ptr = reinterpret_cast<const char *>(dat);
665 
666  T text;
667  for (Converter::FormatList::const_iterator i=fList.begin(); i<fList.end()-1; i++)
668  {
669  if (ptr-size>dat)
670  {
671  ostringstream err;
672  err << "Format description [fmt=" << fFormat << "|size=" << GetSize() << "] exceeds available data size (" << size << ")";
673  throw runtime_error(err.str());
674  }
675 
676  if (*i->first.first == typeid(string))
677  {
678  if (size>0)
679  AddString(text, ptr);
680  if (ptr-size<=dat)
681  return text;
682  break;
683  }
684 
685  // Get as many items from the input line as requested
686  for (int j=0; j<i->second.first; j++)
687  {
688  switch (i->first.first->name()[0])
689  {
690  case 'b': Add<bool> (text, ptr); break;
691  case 'c': Add<char> (text, ptr); break;
692  case 's': Add<short> (text, ptr); break;
693  case 'i': Add<int> (text, ptr); break;
694  case 'l': Add<long> (text, ptr); break;
695  case 'f': Add<float> (text, ptr); break;
696  case 'd': Add<double> (text, ptr); break;
697  case 'x': Add<long long>(text, ptr); break;
698  case 'N': AddString(text, ptr); break;
699 
700  case 'v':
701  // This should never happen!
702  throw runtime_error("Type 'void' not supported!");
703  default:
704  throw runtime_error("TypeId '"+string(i->first.first->name())+"' not known!");
705  }
706  }
707  }
708 
709  if (ptr-size!=dat)
710  {
711  ostringstream err;
712  err << "Data block size (" << size << ") doesn't fit format description [fmt=" << fFormat << "|size=" << GetSize() <<"]";
713  throw runtime_error(err.str());
714  }
715 
716  return text;
717 }
int i
Definition: db_dim_client.c:21
bool valid() const
Definition: Converter.h:83
int size
Definition: db_dim_server.c:17
const FormatList fList
Original format string.
Definition: Converter.h:33
void AddString(std::string &str, const char *&ptr) const
Definition: Converter.cc:442
size_t GetSize() const
Definition: Converter.h:89
const std::string fFormat
ostream to which output is redirected
Definition: Converter.h:32

+ Here is the call graph for this function: