PtrSeq.xcc
Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com)
Copyright 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.
This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.
The PtrSeq implements a FIFO stack of pointers over sequential storage.
PtrSeq— Sequence of pointers implemented as stack.
If maxCount
is zero, no memory is allocated at construction time.
struct PtrSeq_ { //@args Memory memory, int32_t maxCount Memory MEMORY; // Where the PtrSeq items are allocated. //@access ITEMSIZE sizeof(PtrSeqItem) uint32_t STATUS; // MAXCOUNT:31;ISORDERED:1; //@access ISORDERED (PtrSeq_STATUS(this)&0x1) //@access MAXCOUNT (int32_t)(PtrSeq_STATUS(this)>>1) //@access MAXSIZE (PtrSeq_MAXCOUNT(this)*sizeof(PtrSeqItem)) PtrSeqItem *BASE; PtrSeqItem *PAST; //@access USEDSIZE ((char*)PtrSeq_PAST(this) - (char*)PtrSeq_BASE(this)) };
PtrSeq_resize— Resize this PtrSeq.
- maxCount
- The new
maxCount
. AfterPtrSeq_resize
, PtrSeq may have moved in memory. in this case any pointer obtained thoughPtrSeq_access
() will be dangling.
void PtrSeq_resize(PtrSeq this, int32_t maxCount);
PtrSeq_empty— Empty this PtrSeq.
void PtrSeq_empty(PtrSeq this);
PtrSeq_memory— This PtrSeq memory.
static inline Memory PtrSeq_memory(const_PtrSeq this) { return PtrSeq_MEMORY(this); }
PtrSeq_maxCount— This PtrSeq maximum count.
static inline int32_t PtrSeq_maxCount(const_PtrSeq this) { return PtrSeq_MAXCOUNT(this); }
PtrSeq_base— This PtrSeq base item.
static inline const PtrSeqItem * PtrSeq_base(const_PtrSeq this) { return PtrSeq_BASE(this); }
PtrSeq_past— This PtrSeq past item.
static inline const PtrSeqItem * PtrSeq_past(const_PtrSeq this) { return PtrSeq_PAST(this); }
PtrSeq_FOREACH— Iterates from first to last PtrSeq item.
Exiting PtrSeq_FOREACH with break
or return
is allowed.
- this
- The PtrSeq.
- item
- Type item.
#define PtrSeq_FOREACH(this, Type, item) { \ const PtrSeqItem *PtrSeq_BASE = PtrSeq_base(this); \ const PtrSeqItem *PtrSeq_PAST = PtrSeq_past(this); \ const PtrSeqItem *PtrSeq_ITER = PtrSeq_BASE; \ for (; PtrSeq_ITER < PtrSeq_PAST; PtrSeq_ITER++) { \ Type (item) = (Type)*PtrSeq_ITER; #define PtrSeq_ENDEACH \ } \ }
PtrSeq_FORBACK— Iterates from last to first PtrSeq item.
Exiting PtrSeq_FORBACK with break
or return
is allowed.
- this
- The PtrSeq.
- item
- Type item.
#define PtrSeq_FORBACK(this, Type, item) { \ const PtrSeqItem *PtrSeq_BASE = PtrSeq_base(this); \ const PtrSeqItem *PtrSeq_PAST = PtrSeq_past(this); \ const PtrSeqItem *PtrSeq_ITER = PtrSeq_PAST - 1; \ for (; PtrSeq_ITER >= PtrSeq_BASE; --PtrSeq_ITER) { \ Type (item) = (Type)*PtrSeq_ITER; #define PtrSeq_ENDBACK \ } \ }
PtrSeq_maxSize— Maximum size in bytes used by this PtrSeq items.
static inline size_t PtrSeq_maxSize(const_PtrSeq this) { return PtrSeq_MAXSIZE(this); }
PtrSeq_usedSize— Size in bytes used by this PtrSeq items.
static inline size_t PtrSeq_usedSize(const_PtrSeq this) { return PtrSeq_USEDSIZE(this); }
PtrSeq_isEmpty— True iff this PtrSeq is empty.
static inline bool PtrSeq_isEmpty(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); PtrSeqItem *past = PtrSeq_PAST(this); return past == base; }
PtrSeq_isSingle— True iff this PtrSeq has a single entry.
static inline bool PtrSeq_isSingle(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); PtrSeqItem *past = PtrSeq_PAST(this); return past == base + 1; }
PtrSeq_isFull— True iff this PtrSeq is full.
static inline bool PtrSeq_isFull(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); PtrSeqItem *past = PtrSeq_PAST(this); int32_t maxCount = PtrSeq_MAXCOUNT(this); return past == base + maxCount; }
PtrSeq_count— Count items in the PtrSeq.
- Return
- The count of items in the PtrSeq.
static inline int32_t PtrSeq_count(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); PtrSeqItem *past = PtrSeq_PAST(this); return past - base; }
PtrSeq_isOrdered— This PtrSeq ordered status.
static inline bool PtrSeq_isOrdered(const_PtrSeq this) { return PtrSeq_ISORDERED(this); }
PtrSeq_clearOrdered— Set this PtrSeq status as unordered.
static inline void PtrSeq_clearOrdered(PtrSeq this) { *PtrSeq__STATUS(this) &= ~0x1; }
PtrSeq_base_— Base of this PtrSeq for use by external sort.
static inline PtrSeqItem * PtrSeq_base_(PtrSeq this) { *PtrSeq__STATUS(this) &= ~0x1; return PtrSeq_BASE(this); }
PtrSeq_firstItem— First item of the PtrSeq.
- Return
- Pointer to the first item.
static inline PtrSeqItem PtrSeq_firstItem(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); Except_REQUIRE(!PtrSeq_isEmpty(this)); return base[0]; }
PtrSeq_lastItem— Last item of the PtrSeq.
- Return
- Pointer to the last item.
static inline PtrSeqItem PtrSeq_lastItem(const_PtrSeq this) { PtrSeqItem *past = PtrSeq_PAST(this); Except_REQUIRE(!PtrSeq_isEmpty(this)); return past[-1]; }
PtrSeq_access— Access the PtrSeq by index.
- index
- The index.
- Return
- The corresponding item.
static inline PtrSeqItem PtrSeq_access(const_PtrSeq this, int32_t index) { PtrSeqItem *base = PtrSeq_BASE(this); int32_t maxCount = PtrSeq_MAXCOUNT(this); Except_REQUIRE(index >= 0 && index < maxCount); return base[index]; }
PtrSeq_bottom— Access the bottom PtrSeq.
static inline PtrSeqItem PtrSeq_bottom(const_PtrSeq this) { PtrSeqItem *base = PtrSeq_BASE(this); return base[0]; }
PtrSeq_top— Access the top PtrSeqItem
static inline PtrSeqItem PtrSeq_top(const_PtrSeq this) { PtrSeqItem *past = PtrSeq_PAST(this); Except_REQUIRE(!PtrSeq_isEmpty(this)); return past[-1]; }
PtrSeq_push— Push as last item on the PtrSeq.
static inline void PtrSeq_push(PtrSeq this, PtrSeqItem item) { PtrSeqItem *past = PtrSeq_PAST(this); Except_REQUIRE(!PtrSeq_isFull(this)); *PtrSeq__PAST(this) = past + 1; *past = item; }
PtrSeq_push2— Push as last item on the PtrSeq, resizing the PtrSeq if necessary.
- Return
- The pushed PtrSeqItem. As the PtrSeq may be resized, it is an error to maintain pointers to existing items.
void PtrSeq_push2(PtrSeq this, PtrSeqItem item);
PtrSeq_pop— Pop the last PtrSeq item.
static inline void PtrSeq_pop(PtrSeq this) { PtrSeqItem *past = PtrSeq_PAST(this); Except_REQUIRE(!PtrSeq_isEmpty(this)); *PtrSeq__PAST(this) = --past; }