added code for the StdSed class

This commit is contained in:
2009-05-27 07:29:47 +00:00
parent 822c681691
commit 502bab8e4e
9 changed files with 217 additions and 85 deletions

View File

@ -40,19 +40,51 @@ public:
int open () throw ();
void close () throw ();
int compile (const char_t* sptr) throw ();
int compile (const char_t* sptr, size_t slen) throw ();
int execute () throw ();
class IO
{
public:
friend class Sed;
protected:
IO (sed_io_arg_t* arg): arg(arg) {}
public:
const char_t* getPath () const
{
return arg->path;
}
const void* getHandle () const
{
return arg->handle;
}
void setHandle (void* handle)
{
arg->handle = handle;
}
protected:
sed_io_arg_t* arg;
};
protected:
sed_t* sed;
virtual int openIn (const char_t* path) = 0;
virtual int closeIn () = 0;
virtual ssize_t readIn (char_t* buf, size_t len) = 0;
virtual int openInput (IO& io) = 0;
virtual int closeInput (IO& io) = 0;
virtual ssize_t readInput (IO& io, char_t* buf, size_t len) = 0;
virtual int openOut (const char_t* path) = 0;
virtual int closeOut () = 0;
virtual ssize_t writeOut (const char_t* buf, size_t len) = 0;
virtual int openOutput (IO& io) = 0;
virtual int closeOutput (IO& io) = 0;
virtual ssize_t writeOutput (
IO& io, const char_t* data, size_t len) = 0;
private:
static int xin (sed_t* s, sed_io_cmd_t cmd, sed_io_arg_t* arg);

View File

@ -27,12 +27,18 @@ QSE_BEGIN_NAMESPACE(QSE)
class StdSed: public Sed
{
public:
protected:
void* allocMem (qse_size_t n) throw ();
void* reallocMem (void* ptr, qse_size_t n) throw ();
void freeMem (void* ptr) throw ();
int openInput (IO& io);
int closeInput (IO& io);
ssize_t readInput (IO& io, char_t* buf, size_t len);
int openOutput (IO& io);
int closeOutput (IO& io);
ssize_t writeOutput (IO& io, const char_t* data, size_t len);
};
/////////////////////////////////

View File

@ -122,34 +122,27 @@ typedef enum qse_sed_io_cmd_t qse_sed_io_cmd_t;
/**
* The qse_sed_io_arg_t type defines a data structure required by an IO handler.
*/
union qse_sed_io_arg_t
struct qse_sed_io_arg_t
{
struct
{
void* handle; /* out */
const qse_char_t* path; /* in */
} open;
void* handle;
const qse_char_t* path;
struct
union
{
void* handle; /* in */
qse_char_t* buf; /* out */
qse_size_t len; /* in */
} read;
struct
{
qse_char_t* buf;
qse_size_t len;
} r;
struct
{
void* handle; /* in */
const qse_char_t* data; /* in */
qse_size_t len; /* in */
} write;
struct
{
void* handle; /* in */
} close;
struct
{
const qse_char_t* data;
qse_size_t len;
} w;
} u;
};
typedef union qse_sed_io_arg_t qse_sed_io_arg_t;
typedef struct qse_sed_io_arg_t qse_sed_io_arg_t;
/**
* The qse_sed_io_fun_t type defines an IO handler. An IO handler is called by