diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index f3fb0153..40c91d75 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.hpp 474 2011-05-23 16:52:37Z hyunghwan.chung $ + * $Id: Awk.hpp 477 2011-05-24 04:22:40Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -412,20 +412,48 @@ public: /// /// The Index class encapsulates an index of an arrayed value. /// - class Index + class Index: protected qse_cstr_t { public: friend class Value; /// The Index() function creates an empty array index. - Index (): ptr (EMPTY_STRING), len (0) {} + Index () + { + this->ptr = EMPTY_STRING; + this->len = 0; + } /// The Index() function creates a string array index. - Index (const char_t* ptr, size_t len): - ptr (ptr), len (len) {} + Index (const char_t* ptr, size_t len) + { + this->ptr = ptr; + this->len = len; + } - const char_t* ptr; - size_t len; + void set (const qse_cstr_t* x) + { + this->ptr = x->ptr; + this->len = x->len; + } + + void set (const qse_xstr_t* x) + { + this->ptr = x->ptr; + this->len = x->len; + } + + Index& operator= (const qse_cstr_t* x) + { + this->set (x); + return *this; + } + + Index& operator= (const qse_xstr_t* x) + { + this->set (x); + return *this; + } }; /// diff --git a/qse/include/qse/awk/awk.h b/qse/include/qse/awk/awk.h index b8ad85f0..c2d079bb 100644 --- a/qse/include/qse/awk/awk.h +++ b/qse/include/qse/awk/awk.h @@ -1,5 +1,5 @@ /* - * $Id: awk.h 474 2011-05-23 16:52:37Z hyunghwan.chung $ + * $Id: awk.h 477 2011-05-24 04:22:40Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -274,10 +274,8 @@ struct qse_awk_val_map_itr_t }; typedef struct qse_awk_val_map_itr_t qse_awk_val_map_itr_t; -#define QSE_AWK_VAL_MAP_ITR_KEY_PTR(itr) \ - ((const qse_char_t*)QSE_HTB_KPTR((itr)->pair)) -#define QSE_AWK_VAL_MAP_ITR_KEY_LEN(itr) \ - (*(const qse_size_t*)&QSE_HTB_KLEN((itr)->pair)) +#define QSE_AWK_VAL_MAP_ITR_KEY(itr) \ + ((const qse_cstr_t*)QSE_HTB_KPTL((itr)->pair)) #define QSE_AWK_VAL_MAP_ITR_VAL(itr) \ ((const qse_awk_val_t*)QSE_HTB_VPTR((itr)->pair)) diff --git a/qse/include/qse/cmn/htb.h b/qse/include/qse/cmn/htb.h index fd4840e7..0ed56148 100644 --- a/qse/include/qse/cmn/htb.h +++ b/qse/include/qse/cmn/htb.h @@ -1,5 +1,5 @@ /* - * $Id: htb.h 474 2011-05-23 16:52:37Z hyunghwan.chung $ + * $Id: htb.h 477 2011-05-24 04:22:40Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -285,6 +285,9 @@ struct qse_htb_t #define QSE_HTB_KSCALE(m) (*(const int*)&(m)->scale[QSE_HTB_KEY]) #define QSE_HTB_VSCALE(m) (*(const int*)&(m)->scale[QSE_HTB_VAL]) +#define QSE_HTB_KPTL(p) (&(p)->key) +#define QSE_HTB_VPTL(p) (&(p)->val) + #define QSE_HTB_KPTR(p) ((p)->key.ptr) #define QSE_HTB_KLEN(p) ((p)->key.len) #define QSE_HTB_VPTR(p) ((p)->val.ptr) diff --git a/qse/include/qse/cmn/map.h b/qse/include/qse/cmn/map.h index 9b49aa54..11159fb1 100644 --- a/qse/include/qse/cmn/map.h +++ b/qse/include/qse/cmn/map.h @@ -79,6 +79,8 @@ # define QSE_MAP_KEEPER(map) QSE_HTB_KEEPER(map) # define QSE_MAP_KSCALE(map) QSE_HTB_KSCALE(map) # define QSE_MAP_VSCALE(map) QSE_HTB_VSCALE(map) +# define QSE_MAP_KPTL(p) QSE_HTB_KPTL(p) +# define QSE_MAP_VPTL(p) QSE_HTB_VPTL(p) # define QSE_MAP_KPTR(p) QSE_HTB_KPTR(p) # define QSE_MAP_KLEN(p) QSE_HTB_KLEN(p) # define QSE_MAP_VPTR(p) QSE_HTB_VPTR(p) @@ -135,6 +137,8 @@ # define QSE_MAP_KEEPER(map) QSE_RBT_KEEPER(map) # define QSE_MAP_KSCALE(map) QSE_RBT_KSCALE(map) # define QSE_MAP_VSCALE(map) QSE_RBT_VSCALE(map) +# define QSE_MAP_KPTL(p) QSE_RBT_KPTL(p) +# define QSE_MAP_VPTL(p) QSE_RBT_VPTL(p) # define QSE_MAP_KPTR(p) QSE_RBT_KPTR(p) # define QSE_MAP_KLEN(p) QSE_RBT_KLEN(p) # define QSE_MAP_VPTR(p) QSE_RBT_VPTR(p) diff --git a/qse/include/qse/cmn/rbt.h b/qse/include/qse/cmn/rbt.h index 5bded784..febd986c 100644 --- a/qse/include/qse/cmn/rbt.h +++ b/qse/include/qse/cmn/rbt.h @@ -256,6 +256,9 @@ struct qse_rbt_t #define QSE_RBT_KSCALE(m) ((const int)(m)->scale[QSE_RBT_KEY]) #define QSE_RBT_VSCALE(m) ((const int)(m)->scale[QSE_RBT_VAL]) +#define QSE_RBT_KPTL(p) (&(p)->key) +#define QSE_RBT_VPTL(p) (&(p)->val) + #define QSE_RBT_KPTR(p) ((p)->key.ptr) #define QSE_RBT_KLEN(p) ((p)->key.len) #define QSE_RBT_VPTR(p) ((p)->val.ptr) diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index e9cf405e..10aaf1b4 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1,5 +1,5 @@ /* - * $Id: Awk.cpp 476 2011-05-23 17:07:13Z hyunghwan.chung $ + * $Id: Awk.cpp 477 2011-05-24 04:22:40Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -806,8 +806,7 @@ Awk::Value::IndexIterator Awk::Value::getFirstIndex (Index* idx) const iptr = qse_awk_rtx_getfirstmapvalitr (this->run->rtx, this->val, &itr); if (iptr == QSE_NULL) return IndexIterator::END; // no more key - idx->ptr = QSE_AWK_VAL_MAP_ITR_KEY_PTR(iptr); - idx->len = QSE_AWK_VAL_MAP_ITR_KEY_LEN(iptr); + idx->set (QSE_AWK_VAL_MAP_ITR_KEY(iptr)); return itr; } @@ -827,8 +826,7 @@ Awk::Value::IndexIterator Awk::Value::getNextIndex ( iptr = qse_awk_rtx_getnextmapvalitr (this->run->rtx, this->val, &itr); if (iptr == QSE_NULL) return IndexIterator::END; // no more key - idx->ptr = QSE_AWK_VAL_MAP_ITR_KEY_PTR(iptr); - idx->len = QSE_AWK_VAL_MAP_ITR_KEY_LEN(iptr); + idx->set (QSE_AWK_VAL_MAP_ITR_KEY(iptr)); return itr; } diff --git a/qse/lib/awk/run.c b/qse/lib/awk/run.c index 1662f0eb..d2722878 100644 --- a/qse/lib/awk/run.c +++ b/qse/lib/awk/run.c @@ -1,5 +1,5 @@ /* - * $Id: run.c 469 2011-05-21 16:16:18Z hyunghwan.chung $ + * $Id: run.c 477 2011-05-24 04:22:40Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -260,9 +260,9 @@ typedef qse_awk_val_t* (*binop_func_t) ( typedef qse_awk_val_t* (*eval_expr_t) (qse_awk_rtx_t* run, qse_awk_nde_t* nde); #ifdef NDEBUG -#define xstr_to_cstr(x) ((qse_cstr_t*)x) +# define xstr_to_cstr(xstr) ((qse_cstr_t*)xstr) #else -static qse_cstr_t* xstr_to_cstr (qse_xstr_t* xstr) +static QSE_INLINE qse_cstr_t* xstr_to_cstr (qse_xstr_t* xstr) { /* i use this function to typecast qse_cstr_t* to * qse_xstr_t* instead of direct typecasting.