added code to the Sed class
This commit is contained in:
parent
2a4dd14b2a
commit
b010320498
@ -19,8 +19,7 @@
|
||||
#ifndef _QSE_MMGR_HPP_
|
||||
#define _QSE_MMGR_HPP_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
#include <qse/Types.hpp>
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
@ -33,9 +32,16 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
* write code in more object-oriented fashion. An inheriting class should
|
||||
* implement three pure virtual functions.
|
||||
*/
|
||||
class Mmgr: public qse_mmgr_t
|
||||
class Mmgr: public Types, public qse_mmgr_t
|
||||
{
|
||||
public:
|
||||
/** defines an alias type to qse_mmgr_t */
|
||||
typedef qse_mmgr_t mmgr_t;
|
||||
|
||||
/**
|
||||
* The Mmgr() function builds a memory manager composed of bridge
|
||||
* functions connecting itself with it.
|
||||
*/
|
||||
Mmgr () throw ()
|
||||
{
|
||||
this->alloc = alloc_mem;
|
||||
@ -44,6 +50,9 @@ public:
|
||||
this->data = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ~Mmgr() function finalizes a memory manager.
|
||||
*/
|
||||
virtual ~Mmgr () {}
|
||||
|
||||
protected:
|
||||
|
52
qse/include/qse/Types.hpp
Normal file
52
qse/include/qse/Types.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* $Id: Sed.hpp 127 2009-05-07 13:15:04Z baconevi $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _QSE_TYPES_HPP_
|
||||
#define _QSE_TYPES_HPP_
|
||||
|
||||
#include <qse/types.h>
|
||||
#include <qse/macros.h>
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_BEGIN_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
class Types
|
||||
{
|
||||
public:
|
||||
/** boolean data type */
|
||||
typedef qse_bool_t bool_t;
|
||||
/** data type that can hold any character */
|
||||
typedef qse_char_t char_t;
|
||||
/** data type that can hold any character or an end-of-file value */
|
||||
typedef qse_cint_t cint_t;
|
||||
/** represents an unsigned integer number of the same size as void* */
|
||||
typedef qse_size_t size_t;
|
||||
/** signed version of size_t */
|
||||
typedef qse_ssize_t ssize_t;
|
||||
/** represents an integer */
|
||||
typedef qse_long_t long_t;
|
||||
/** represents a floating-point number */
|
||||
typedef qse_real_t real_t;
|
||||
};
|
||||
|
||||
/////////////////////////////////
|
||||
QSE_END_NAMESPACE(QSE)
|
||||
/////////////////////////////////
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: Awk.hpp 148 2009-05-20 10:44:47Z hyunghwan.chung $
|
||||
* $Id: Awk.hpp 156 2009-05-25 13:39:18Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -35,27 +35,10 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
class Awk: public Mmgr
|
||||
{
|
||||
public:
|
||||
/** Boolean data type */
|
||||
typedef qse_bool_t bool_t;
|
||||
/** Data type that can hold any character */
|
||||
typedef qse_char_t char_t;
|
||||
/** Data type that can hold any character or an end-of-file value */
|
||||
typedef qse_cint_t cint_t;
|
||||
/** Represents an unsigned integer number of the same size as void* */
|
||||
typedef qse_size_t size_t;
|
||||
/** Signed version of size_t */
|
||||
typedef qse_ssize_t ssize_t;
|
||||
/** Represents an integer */
|
||||
typedef qse_long_t long_t;
|
||||
/** Represents a floating-point number */
|
||||
typedef qse_real_t real_t;
|
||||
/** Represents the internal hash table */
|
||||
typedef qse_map_t map_t;
|
||||
/** Represents a key/value pair */
|
||||
typedef qse_map_pair_t pair_t;
|
||||
|
||||
typedef qse_mmgr_t mmgr_t;
|
||||
|
||||
/** Represents an internal awk value */
|
||||
typedef qse_awk_val_t val_t;
|
||||
|
||||
|
@ -32,15 +32,31 @@ QSE_BEGIN_NAMESPACE(QSE)
|
||||
class Sed: public Mmgr
|
||||
{
|
||||
public:
|
||||
typedef qse_sed_t sed_t;
|
||||
typedef qse_sed_io_cmd_t sed_io_cmd_t;
|
||||
typedef qse_sed_io_arg_t sed_io_arg_t;
|
||||
|
||||
Sed () throw (): sed (QSE_NULL) {}
|
||||
|
||||
int open () throw ();
|
||||
void close () throw ();
|
||||
int compile () throw ();
|
||||
int compile (const char_t* sptr, size_t slen) throw ();
|
||||
int execute () throw ();
|
||||
|
||||
protected:
|
||||
qse_sed_t* sed;
|
||||
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 openOut (const char_t* path) = 0;
|
||||
virtual int closeOut () = 0;
|
||||
virtual ssize_t writeOut (const char_t* buf, size_t len) = 0;
|
||||
|
||||
private:
|
||||
static int xin (sed_t* s, sed_io_cmd_t cmd, sed_io_arg_t* arg);
|
||||
static int xout (sed_t* s, sed_io_cmd_t cmd, sed_io_arg_t* arg);
|
||||
};
|
||||
|
||||
/////////////////////////////////
|
||||
|
@ -48,14 +48,64 @@ void Sed::close () throw()
|
||||
}
|
||||
}
|
||||
|
||||
int Sed::compile () throw ()
|
||||
int Sed::compile (const char_t* sptr, size_t slen) throw ()
|
||||
{
|
||||
return 0;
|
||||
QSE_ASSERT (sed != QSE_NULL);
|
||||
return qse_sed_comp (sed, sptr, slen);
|
||||
}
|
||||
|
||||
int Sed::execute () throw ()
|
||||
{
|
||||
return 0;
|
||||
QSE_ASSERT (sed != QSE_NULL);
|
||||
return qse_sed_exec (sed, xin, xout);
|
||||
}
|
||||
|
||||
int Sed::xin (sed_t* s, sed_io_cmd_t cmd, sed_io_arg_t* arg)
|
||||
{
|
||||
Sed* sed = *(Sed**)QSE_XTN(s);
|
||||
|
||||
try
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_SED_IO_OPEN:
|
||||
return sed->openIn (arg->open.path);
|
||||
case QSE_SED_IO_CLOSE:
|
||||
return sed->closeIn ();
|
||||
case QSE_SED_IO_READ:
|
||||
return sed->readIn (arg->read.buf, arg->read.len);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int Sed::xout (sed_t* s, sed_io_cmd_t cmd, sed_io_arg_t* arg)
|
||||
{
|
||||
Sed* sed = *(Sed**)QSE_XTN(s);
|
||||
|
||||
try
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case QSE_SED_IO_OPEN:
|
||||
return sed->openOut (arg->open.path);
|
||||
case QSE_SED_IO_CLOSE:
|
||||
return sed->closeOut ();
|
||||
case QSE_SED_IO_READ:
|
||||
return sed->writeOut (arg->write.data, arg->write.len);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user