00001
#ifndef REGEXCONVERTER_BOX_H
00002
#define REGEXCONVERTER_BOX_H
00003
00004
#include "SimpleConverterBox.h"
00005
#include <sys/types.h>
00006
#include <regex.h>
00007
00008
BOREALIS_NAMESPACE_BEGIN
00009
00010
00013 class RegexConverterBox :
public SimpleConverterBox
00014 {
00015
protected:
00023
RegexConverterBox( TupleDescription schema,
00024
char delim,
00025 string regex
00026 )
00027
throw(
AuroraException );
00028
00029
public:
00031
~RegexConverterBox();
00032
00035 struct Subexpr
00036 {
00038 Subexpr() {}
00039
00041 Subexpr(
const char *begin,
const char *end) : begin(begin), end(end) {}
00042
00044 const char *
begin;
00045
00047 const char *
end;
00048
00050 string
as_string()
const {
return string(
begin,
end ); }
00051
00058
template <
typename CharArray>
00059 bool toStringField(CharArray& buf)
const
00060
{
00061
return toStringField( buf,
sizeof buf /
sizeof buf[0] );
00062 }
00063
00070
bool toStringField(
char *field,
unsigned int size )
const;
00071
00076 int32
toInt() const throw(
AuroraException );
00077
00082 int64 toLong() const throw( AuroraException );
00083
00088 single toSingle() const throw( AuroraException );
00089
00094
double toDouble() const throw( AuroraException );
00095 };
00096
00101 virtual
bool convertTuple(const
char *data,
unsigned int length,
char *out)
00102 throw (AuroraException);
00103
00111 virtual
bool convertTupleFromRegex(
Subexpr match,
00112 const vector<
Subexpr>& subexprs,
00113
char *out)
00114 throw (AuroraException) = 0;
00115
00116 private:
00117 string _regex;
00118 ptr<regex_t> _preg;
00119
00120
00121 vector<
Subexpr> _subexprs;
00122 };
00123
00124 BOREALIS_NAMESPACE_END
00125 #endif