FACT++  1.0
Converter Class Reference

A compiler for the DIM data format string. More...

#include <Converter.h>

+ Collaboration diagram for Converter:

Classes

struct  O
 
struct  W
 

Public Types

typedef std::pair< const std::type_info *, int > Type
 
typedef std::pair< int, int > Offset
 
typedef std::pair< Type, OffsetFormat
 
typedef std::vector< FormatFormatList
 

Public Member Functions

 Converter (std::ostream &out, const std::string &fmt, bool strict=true)
 
 Converter (const std::string &fmt, bool strict=true)
 
bool empty () const
 
bool valid () const
 
bool operator! () const
 
const FormatListGetList () const
 
size_t GetSize () const
 
std::string GetString (const void *d, size_t size) const
 
std::vector< char > GetVector (const void *d, size_t size) const
 
std::vector< boost::any > GetAny (const void *d, size_t size) const
 
std::vector< boost::any > GetAny (const std::string &str) const
 
std::vector< char > GetVector (const std::string &str) const
 
std::vector< std::string > ToStrings (const void *src) const
 
void ToFits (void *dest, const void *src, size_t size) const
 
std::vector< char > ToFits (const void *src, size_t size) const
 
std::vector< std::string > GetFitsFormat () const
 
void Print (std::ostream &out) const
 
void Print () const
 
template<class T >
string GetString (const char *&ptr) const
 
template<class T >
vector< T > Get (const std::string &str) const
 

Static Public Member Functions

static std::string Clean (std::string s)
 
static FormatList Compile (std::ostream &out, const std::string &fmt, bool strict=false)
 
static FormatList Compile (const std::string &fmt, bool strict=false)
 
static std::string ToFormat (const std::vector< std::string > &fits)
 
template<typename T >
static std::string GetHex (const void *dat, size_t size, size_t col=0, bool prefix=true)
 
template<typename T , typename S >
static std::string GetHex (const S &s, size_t col=0, bool prefix=true)
 
static std::vector< std::string > Regex (const std::string &expr, const std::string &line)
 

Private Member Functions

template<class T >
Get (std::stringstream &line) const
 Compiled format description. More...
 
bool GetBool (std::stringstream &line) const
 
std::string GetString (std::stringstream &line) const
 
std::string GetStringEol (std::stringstream &line) const
 
template<class T >
void GetBinImp (std::vector< char > &v, const T &val) const
 
template<class T >
void GetBinImp (std::vector< boost::any > &v, const T &val) const
 
void GetBinString (std::vector< char > &v, const std::string &val) const
 
void GetBinString (std::vector< boost::any > &v, const std::string &val) const
 
template<class T >
std::string GetString (const char *&data) const
 
template<char >
std::string GetString (const char *&ptr) const
 
template<class T >
std::vector< T > Get (const std::string &str) const
 
template<class T >
Get (const void *d, size_t size) const
 
template<class T >
void Add (std::string &str, const char *&ptr) const
 
void AddString (std::string &str, const char *&ptr) const
 
template<class T >
void Add (std::vector< boost::any > &vec, const char *&ptr) const
 
void AddString (std::vector< boost::any > &vec, const char *&ptr) const
 

Static Private Member Functions

template<class T >
static Type GetType ()
 
template<class T >
static Type GetVoid ()
 

Private Attributes

std::ostream & wout
 
const std::string fFormat
 ostream to which output is redirected More...
 
const FormatList fList
 Original format string. More...
 

Detailed Description

A compiler for the DIM data format string.

The Converter class interprets arguments in a string accoring to the given format definition and produces a corresponding memory block from it which can be attached to an event later.

The format is given according to the Dim format description:

The format parameter specifies the contents of the structure in the form T:N[;T:N]*[;T] where T is the item type: (I)nteger, (C)haracter, (L)ong, (S)hort, (F)loat, (D)ouble, X(tra long) and N is the number of such items. The type alone at the end means all following items are of the same type. Example: "I:3;F:2;C" means 3 Integers, 2 Floats and characters until the end. The format parameter is used for communicating between different platforms.

Note, that the strange notation T:N[;T:N]*[;T] is meant to be a regular expression. An Xtra-long is a 'long long'.

Since Dim itself never really interpretes the format string, the programmer is responsible to make sure that the delivered data and the interpretation is consistent. Therefore the provided class can be of some help.

For example:

Converter c(cout, "I:1;F:2;I:2", );
vector<char> v = c.GetVector("COMMAND 1 2.5 4.2 3 4");

would produce a 20 byte data block with the integers 1, the floats 2.5 and 4.2, and the intergers 3 and 4, in this order.

The opposite direction is also possible

Converter c(cout, "I:1;F:2;I:2");
cout << c.GetString(pointer, size) << endl;

Other conversion functions also exist.

To check if the compilation of the format string was successfull the valid() member functio is provided.

The format parameter W(ord) is dedicated to this kind of conversion and not understood by Dim. In addition there are O(ptions) which are like Words but can be omitted. They should only be used at the end of the string. Both can be encapsulated in quotationmarks '"'. Nested quotationmarks are not supported. B(ool) is also special. It evaluates true/false, yes/no, on/off, 1/0.

The non-DIM like format options can be switched on and off by using the strict argument in the constructor. In general DimCommands can use these options, but DimServices not.

Remarks
Note that all values are interpreted as signed, except the single char (e.g. C:5)

Definition at line 16 of file Converter.h.


The documentation for this class was generated from the following files: