-added Awk::Value::getFirstIndex() & Awk::Value::getNextIndex()

-fixed a few bugs in the Awk::Value class
This commit is contained in:
2009-07-14 02:51:23 +00:00
parent 814ed89e53
commit 9b6eb94664
11 changed files with 1077 additions and 730 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 229 2009-07-12 13:06:01Z hyunghwan.chung $
* $Id: Awk.hpp 230 2009-07-13 08:51:23Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -239,6 +239,69 @@ public:
void operator delete (void* p) throw ();
void operator delete[] (void* p) throw ();
class Index
{
public:
friend class Value;
Index (): ptr (EMPTY_STRING), len (0) {}
Index (const char_t* ptr, size_t len):
ptr (ptr), len (len) {}
const char_t* ptr;
size_t len;
};
class IntIndex: public Index
{
public:
IntIndex (long_t num);
protected:
// 2^32: 4294967296
// 2^64: 18446744073709551616
// 2^128: 340282366920938463463374607431768211456
// -(2^32/2): -2147483648
// -(2^64/2): -9223372036854775808
// -(2^128/2): -170141183460469231731687303715884105728
#if QSE_SIZEOF_LONG_T > 16
# error SIZEOF(qse_long_t) TOO LARGE.
# error INCREASE THE BUFFER SIZE TO SUPPORT IT.
#elif QSE_SIZEOF_LONG_T == 16
char_t buf[41];
#elif QSE_SIZEOF_LONG_T == 8
char_t buf[21];
#else
char_t buf[12];
#endif
};
class IndexIterator
{
public:
friend class Value;
static IndexIterator END;
IndexIterator (): pair (QSE_NULL), buckno (0) {}
IndexIterator (pair_t* pair, size_t buckno):
pair (pair), buckno (buckno) {}
bool operator== (const IndexIterator& ii) const
{
return pair == ii.pair && buckno == ii.buckno;
}
bool operator!= (const IndexIterator& ii) const
{
return !operator== (ii);
}
protected:
pair_t* pair;
size_t buckno;
};
Value ();
Value (Run& run);
Value (Run* run);
@ -302,62 +365,75 @@ public:
int setStr (Run* r, const char_t* str);
int setIndexedVal (
const char_t* idx, size_t isz, val_t* v);
const Index& idx,
val_t* v
);
int setIndexedVal (
Run* r, const char_t* idx, size_t isz, val_t* v);
Run* r,
const Index& idx,
val_t* v
);
int setIndexedInt (
const char_t* idx, size_t isz, long_t v);
const Index& idx,
long_t v
);
int setIndexedInt (
Run* r, const char_t* idx, size_t isz, long_t v);
Run* r,
const Index& idx,
long_t v);
int setIndexedReal (
const char_t* idx,
size_t isz,
const Index& idx,
real_t v
);
int setIndexedReal (
Run* r,
const char_t* idx,
size_t isz,
const Index& idx,
real_t v
);
int setIndexedStr (
const char_t* idx,
size_t isz,
const Index& idx,
const char_t* str,
size_t len
);
int setIndexedStr (
Run* r,
const char_t* idx,
size_t isz,
const Index& idx,
const char_t* str,
size_t len
);
int setIndexedStr (
const char_t* idx,
size_t isz,
const Index& idx,
const char_t* str
);
int setIndexedStr (
Run* r,
const char_t* idx,
size_t isz,
const Index& idx,
const char_t* str
);
bool isIndexed () const;
int getIndexed (
const char_t* idx,
size_t isz,
Value& val
const Index& idx,
Value* val
) const;
IndexIterator getFirstIndex (
Index* idx
) const;
IndexIterator getNextIndex (
Index* idx,
const IndexIterator& iter
) const;
protected:

View File

@ -1,5 +1,5 @@
/*
* $Id: StdAwk.hpp 229 2009-07-12 13:06:01Z hyunghwan.chung $
* $Id: StdAwk.hpp 230 2009-07-13 08:51:23Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -23,9 +23,11 @@
/**
* @example awk05.cpp
* This program demonstrates how to embed QSE::StdAwk in C++.
* This program demonstrates how to embed QSE::StdAwk::loop().
* @example awk06.cpp
* This program demonstrates how to embed QSE::StdAwk in C++.
* This program demonstrates how to use QSE::StdAwk::call().
* @example awk07.cpp
* This program demonstrates how to handle an indexed value.
*/
/////////////////////////////////

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 228 2009-07-11 03:01:36Z hyunghwan.chung $
* $Id: awk.h 230 2009-07-13 08:51:23Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -1809,6 +1809,18 @@ void* qse_awk_rtx_alloc (
qse_size_t size /**< block size in bytes */
);
/**
* The qse_awk_rtx_realloc() function resizes a memory block pointed to
* by @a ptr to @a size bytes using the memory manager associated with
* a runtime context @a rtx.
* @return the pointer to a memory block on success, #QSE_NULL on failure.
*/
void* qse_awk_rtx_realloc (
qse_awk_rtx_t* rtx, /**< runtime context */
void* ptr, /**< memory block */
qse_size_t size /**< block size in bytes */
);
/**
* The qse_awk_rtx_free() function frees a memory block pointed to by @a ptr
* using the memory manager of a runtime ocntext @a rtx.

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 220 2009-07-01 13:14:39Z hyunghwan.chung $
* $Id: types.h 230 2009-07-13 08:51:23Z hyunghwan.chung $
*
Copyright 2006-2009 Chung, Hyung-Hwan.
@ -70,24 +70,31 @@ typedef enum qse_tri_t qse_tri_t;
(QSE_SIZEOF_VOID_P == QSE_SIZEOF_LONG)
typedef long qse_int_t;
typedef unsigned long qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF_LONG
#elif defined(__SPU__) && (QSE_SIZEOF_VOID_P == QSE_SIZEOF_LONG)
typedef long qse_int_t;
typedef unsigned long qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF_LONG
#elif QSE_SIZEOF_VOID_P == QSE_SIZEOF_INT
typedef int qse_int_t;
typedef unsigned int qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF_INT
#elif QSE_SIZEOF_VOID_P == QSE_SIZEOF_LONG
typedef long qse_int_t;
typedef unsigned long qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF_LONG
#elif QSE_SIZEOF_VOID_P == QSE_SIZEOF_LONG_LONG
typedef long long qse_int_t;
typedef unsigned long long qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF_LONG_LONG
#elif QSE_SIZEOF_VOID_P == QSE_SIZEOF___INT32
typedef __int32 qse_int_t;
typedef unsigned __int32 qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF___INT32
#elif QSE_SIZEOF_VOID_P == QSE_SIZEOF___INT64
typedef __int64 qse_int_t;
typedef unsigned __int64 qse_uint_t;
#define QSE_SIZEOF_INT_T QSE_SIZEOF___INT64
#else
# error unsupported pointer size
#endif
@ -101,12 +108,15 @@ typedef enum qse_tri_t qse_tri_t;
#if QSE_SIZEOF_LONG_LONG > 0
typedef long long qse_long_t;
typedef unsigned long long qse_ulong_t;
#define QSE_SIZEOF_LONG_T QSE_SIZEOF_LONG_LONG
#elif QSE_SIZEOF___INT64 > 0
typedef __int64 qse_long_t;
typedef unsigned __int64 qse_ulong_t;
#define QSE_SIZEOF_LONG_T QSE_SIZEOF___INT64
#else
typedef long qse_long_t;
typedef unsigned long qse_ulong_t;
#define QSE_SIZEOF_LONG_T QSE_SIZEOF_LONG
#endif
/** @typedef qse_int8_t