- renamed Sed::IOStream to Sed::Stream

- renamed StdSed::StdStream to StdSed::FileStream
- added StdSed::StringStream
This commit is contained in:
2009-12-19 21:06:28 +00:00
parent de7082d0d0
commit 92cbbbcec1
6 changed files with 192 additions and 131 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Sed.hpp 318 2009-12-18 12:34:42Z hyunghwan.chung $
* $Id: Sed.hpp 319 2009-12-19 03:06:28Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -56,10 +56,10 @@ public:
typedef qse_sed_depth_t depth_t;
///
/// The IOStream class is a base class for I/O operation during
/// The Stream class is a base class for I/O operation during
/// execution.
///
class IOStream: public Types
class Stream: public Types
{
public:
enum Mode
@ -116,8 +116,8 @@ public:
io_arg_t* arg;
};
IOStream () {}
virtual ~IOStream () {}
Stream () {}
virtual ~Stream () {}
virtual int open (Data& io) = 0;
virtual int close (Data& io) = 0;
@ -125,8 +125,8 @@ public:
virtual ssize_t write (Data& io, const char_t* buf, size_t len) = 0;
private:
IOStream (const IOStream&);
IOStream& operator= (const IOStream&);
Stream (const Stream&);
Stream& operator= (const Stream&);
};
///
@ -179,7 +179,7 @@ public:
/// streams defined through I/O handlers
/// @return 0 on success, -1 on failure
///
int execute (IOStream& iostream);
int execute (Stream& iostream);
///
/// The getOption() function gets the current options.
@ -278,7 +278,7 @@ protected:
/// default error formatting string getter
errstr_t dflerrstr;
/// I/O stream to read data from and write output to.
IOStream* iostream;
Stream* iostream;
private:

View File

@ -1,5 +1,5 @@
/*
* $Id: StdSed.hpp 318 2009-12-18 12:34:42Z hyunghwan.chung $
* $Id: StdSed.hpp 319 2009-12-19 03:06:28Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE.
@ -23,6 +23,7 @@
#include <qse/sed/Sed.hpp>
#include <qse/cmn/StdMmgr.hpp>
#include <qse/cmn/str.h>
/** @file
* Standard Stream Editor
@ -42,11 +43,11 @@ class StdSed: public Sed
public:
StdSed (Mmgr* mmgr = &StdMmgr::DFL): Sed (mmgr) {}
class StdStream: public IOStream
class FileStream: public Stream
{
public:
StdStream (const char_t* infile = QSE_NULL,
const char_t* outfile = QSE_NULL):
FileStream (const char_t* infile = QSE_NULL,
const char_t* outfile = QSE_NULL):
infile(infile), outfile(outfile)
{
}
@ -60,6 +61,36 @@ public:
const char_t* infile;
const char_t* outfile;
};
class StringStream: public Stream
{
public:
StringStream (const char_t* in);
StringStream (const char_t* in, size_t len);
~StringStream ();
int open (Data& io);
int close (Data& io);
ssize_t read (Data& io, char_t* buf, size_t len);
ssize_t write (Data& io, const char_t* buf, size_t len);
const char_t* getInput (size_t* len = QSE_NULL) const;
const char_t* getOutput (size_t* len = QSE_NULL) const;
protected:
struct
{
const char_t* ptr;
const char_t* end;
const char_t* cur;
} in;
struct
{
bool inited;
qse_str_t buf;
} out;
};
};
/**