FACT++  1.0
Converter::FormatList Converter::Compile ( std::ostream &  out,
const std::string &  fmt,
bool  strict = false 
)
static

static function to compile a format string.

Parameters
outOutput stream to which possible logging is redirected
fmtFormat to be compiled. For details see class reference
strictSetting this to true allows non DIM options, whiel false will restrict the possible format strings to the ones also understood by DIM.

Definition at line 774 of file Converter.cc.

References buffer, kRed, and t.

Referenced by Compile(), and GetSize().

775 {
776  ostringstream text;
777 
778  // Access both, the data and the format through a stringstream
779  stringstream stream(fmt);
780 
781  // For better performance we could use sregex
782  static const boost::regex expr1("^([CSILFDXBOW])(:([1-9]+[0-9]*))?$");
783  static const boost::regex expr2("^([CSILFDX])(:([1-9]+[0-9]*))?$");
784 
785  FormatList list;
786  Format format;
787 
788  // Tokenize the format
789  string buffer;
790  while (getline(stream, buffer, ';'))
791  {
792  boost::smatch what;
793  if (!boost::regex_match(buffer, what, strict?expr2:expr1))
794  {
795  out << kRed << "Wrong format string '" << buffer << "'!" << endl;
796  return FormatList();
797  }
798 
799  const string t = what[1]; // type id
800  const string n = what[3]; // counter
801 
802  const int cnt = n.empty() ? 0 : stoi(n);
803 
804  // if the :N part was not given assume 1
805  format.second.first = cnt == 0 ? 1 : cnt;
806 
807  /*
808  if (strict && t[0]=='C' && cnt>0)
809  {
810  out << kRed << "Dim doesn't support the format C with N>0!" << endl;
811  return FormatList();
812  }*/
813 
814  // Check if the format is just C (without a number)
815  // That would mean that it is a \0 terminated string
816  if (t[0]=='C' && cnt==0)
817  {
818  format.first = GetType<string>();
819  list.push_back(format);
820  format.second.second = 0; // end position not known
821  break;
822  }
823 
824  // Get as many items from the input line as requested
825  switch (t[0])
826  {
827  case 'B': format.first = GetType<bool>(); break;
828  case 'C': format.first = GetType<char>(); break;
829  case 'S': format.first = GetType<short>(); break;
830  case 'I': format.first = GetType<int>(); break;
831  case 'L': format.first = GetType<long>(); break;
832  case 'F': format.first = GetType<float>(); break;
833  case 'D': format.first = GetType<double>(); break;
834  case 'X': format.first = GetType<long long>(); break;
835  case 'O': format.first = GetVoid<O>(); break;
836  case 'W': format.first = GetVoid<W>(); break;
837  default:
838  // This should never happen!
839  out << kRed << "Format '" << t[0] << " not known!" << endl;
840  return list;
841  }
842 
843  list.push_back(format);
844  format.second.second += format.first.second * format.second.first;
845  }
846 
847  format.first = GetVoid<void>();
848  format.second.first = 0;
849 
850  list.push_back(format);
851 
852  return list;
853 }
std::vector< Format > FormatList
Definition: Converter.h:22
Set color Red.
Definition: WindowLog.h:17
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
std::pair< Type, Offset > Format
Definition: Converter.h:21
TT t
Definition: test_client.c:26

+ Here is the caller graph for this function: