added qse_awk_rtx_getfirstmapvalitr()/qse_awk_rtx_getnextmapvalitr()

This commit is contained in:
2011-05-13 22:06:55 +00:00
parent 4e882e79c0
commit a2a474bb34
6 changed files with 185 additions and 74 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 441 2011-04-22 14:28:43Z hyunghwan.chung $
* $Id: Awk.hpp 458 2011-05-13 04:06:55Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -459,7 +459,7 @@ public:
/// The IndexIterator class is a helper class to make simple
/// iteration over array elements.
///
class IndexIterator
class IndexIterator: public qse_awk_val_map_itr_t
{
public:
friend class Value;
@ -474,26 +474,29 @@ public:
/// The IndexIterator() function creates an iterator
/// for an arrayed value.
///
IndexIterator (): pair (QSE_NULL), buckno (0) {}
IndexIterator ()
{
this->pair = QSE_NULL;
this->buckno = 0;
}
protected:
IndexIterator (pair_t* pair, size_t buckno):
pair (pair), buckno (buckno) {}
IndexIterator (pair_t* pair, size_t buckno)
{
this->pair = pair;
this->buckno = buckno;
}
public:
bool operator== (const IndexIterator& ii) const
{
return pair == ii.pair && buckno == ii.buckno;
return this->pair == ii.pair && this->buckno == ii.buckno;
}
bool operator!= (const IndexIterator& ii) const
{
return !operator== (ii);
}
protected:
pair_t* pair;
size_t buckno;
};
///
@ -664,8 +667,8 @@ public:
/// iterator that can be passed to getNextIndex() if not
///
IndexIterator getNextIndex (
Index* idx, ///< index holder
const IndexIterator& iter ///< current position
Index* idx, ///< index holder
const IndexIterator& curitr ///< current position
) const;
protected:

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 457 2011-05-12 16:16:57Z hyunghwan.chung $
* $Id: awk.h 458 2011-05-13 04:06:55Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -265,6 +265,21 @@ struct qse_awk_val_ref_t
};
typedef struct qse_awk_val_ref_t qse_awk_val_ref_t;
/**
* The qse_awk_val_map_itr_t type defines the iterator to map value fields.
*/
struct qse_awk_val_map_itr_t
{
qse_htb_pair_t* pair;
qse_size_t buckno;
};
typedef struct qse_awk_val_map_itr_t qse_awk_val_map_itr_t;
#define QSE_AWK_VAL_MAP_ITR_KPTR(itr) QSE_HTB_KPTR((itr)->pair)
#define QSE_AWK_VAL_MAP_ITR_KLEN(itr) QSE_HTB_KLEN((itr)->pair)
#define QSE_AWK_VAL_MAP_ITR_VPTR(itr) QSE_HTB_VPTR((itr)->pair)
/**
* The qse_awk_nde_type_t defines the node types.
*/
@ -1929,6 +1944,31 @@ qse_awk_val_t* qse_awk_rtx_getmapvalfld (
qse_size_t klen
);
/**
* The qse_awk_rtx_getfirstmapvalitr() returns the iterator to the
* first pair in the map. It returns #QSE_NULL and sets the pair field of
* @a itr to #QSE_NULL if the map contains no pair. Otherwise, it returns
* @a itr pointing to the first pair.
*/
qse_awk_val_map_itr_t* qse_awk_rtx_getfirstmapvalitr (
qse_awk_rtx_t* rtx,
qse_awk_val_t* map,
qse_awk_val_map_itr_t* itr
);
/**
* The qse_awk_rtx_getnextmapvalitr() returns the iterator to the
* next pair to @a itr in the map. It returns #QSE_NULL and sets the pair
* field of @a itr to #QSE_NULL if @a itr points to the last pair.
* Otherwise, it returns @a itr pointing to the next pair.
*/
qse_awk_val_map_itr_t* qse_awk_rtx_getnextmapvalitr (
qse_awk_rtx_t* rtx,
qse_awk_val_t* map,
qse_awk_val_map_itr_t* itr
);
/**
* The qse_awk_rtx_makerefval() function creates a reference value.
* @return value on success, QSE_NULL on failure