IArray.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 IArray implements an array of inlined items. The main use of IArray is to provide sequential storage initialized to zero. IArray items can be reallocated using IArray_resize().

IArray— Array of inlined items, initialized to zero.

If maxCount is zero, no memory is allocated at construction time.

struct IArray_ {
  //@args       Memory memory, size_t itemSize, int32_t maxCount
  Memory MEMORY;        // Where the IArray items are allocated.
  size_t ITEMSIZE;
  int32_t MAXCOUNT;
  //@access MAXSIZE     (IArray_MAXCOUNT(this)*IArray_ITEMSIZE(this))
  IArrayItem BASE;
  //@access PAST        (IArrayItem)((char *)IArray_BASE(this)+IArray_MAXSIZE(this))
};
IArray_resize— Resize the IArray.

After IArray_resize, IArray may have moved in memory. in this case any pointer obtained though IArray_access() will be dangling. The extra storage obtained by resizing is initialized to zero.

maxCount
The new maxCount.
void
IArray_resize(IArray this, int32_t maxCount);
IArray_empty— Empty this IArray
void
IArray_empty(IArray this, IArrayItemRelease release);
IArray_memory— This IArray memory.
static inline Memory
IArray_memory(const_IArray this)
{
  return IArray_MEMORY(this);
}
IArray_itemSize— This IArray item size.
static inline size_t
IArray_itemSize(const_IArray this)
{
  return IArray_ITEMSIZE(this);
}
IArray_maxCount— This IArray maximum count.
static inline int32_t
IArray_maxCount(const_IArray this)
{
  return IArray_MAXCOUNT(this);
}
IArray_base— This IArray base item.
static inline IArrayItem
IArray_base(const_IArray this)
{
  return IArray_BASE(this);
}
IArray_past— This IArray past item.
static inline IArrayItem
IArray_past(const_IArray this)
{
  return IArray_PAST(this);
}
IArray_maxSize— Maximum size in bytes used by this IArray items.
static inline size_t
IArray_maxSize(const_IArray this)
{
  return IArray_MAXSIZE(this);
}
IArray_count— This IArray maximum count.
static inline int32_t
IArray_count(const_IArray this)
{
  return IArray_MAXCOUNT(this);
}
IArray_firstItem— First item of the IArray.
Return
Pointer to the first item.
static inline IArrayItem
IArray_firstItem(const_IArray this)
{
  return IArray_BASE(this);
}
IArray_lastItem— Last item of the IArray.
Return
Pointer to the last item.
static inline IArrayItem
IArray_lastItem(const_IArray this)
{
  char *past = IArray_PAST(this);
  size_t itemSize = IArray_ITEMSIZE(this);
  return (IArrayItem)(past - itemSize);
}
IArray_FOREACH— Iterates from first to last IArray item.

Exiting IArray_FOREACH with break or return is allowed.

this
The IArray.
Type
Type of the inlined items.
iter
Type* pointer set to each item.
#define IArray_FOREACH(this, Type, iter) { \
  Type *IArray_BASE = (Type *)IArray_base(this); \
  Type *IArray_PAST = (Type *)IArray_past(this), *(iter); \
  Except_CHECK(IArray_BASE == NULL || sizeof(Type) == IArray_itemSize(this)); \
  for (iter = IArray_BASE; iter < IArray_PAST; ++(iter)) {
#define IArray_ENDEACH \
  } \
}
IArray_FORBACK— Iterates from last to first IArray item.

Exiting IArray_FORBACK with break or return is allowed.

this
The IArray.
Type
Type of the inlined items.
iter
Type* pointer set to each item.
#define IArray_FORBACK(this, Type, iter) { \
  Type *IArray_BASE = (Type *)IArray_base(this); \
  Type *IArray_PAST = (Type *)IArray_past(this), *(iter); \
  Except_CHECK(IArray_BASE == NULL || sizeof(Type) == IArray_itemSize(this)); \
  for (iter = IArray_PAST - 1; iter >= IArray_BASE; --(iter)) {
#define IArray_ENDBACK \
  } \
}
IArray_access— Access the IArray by index.
index
The index.
Return
Pointer to the corresponding item.
static inline IArrayItem
IArray_access(const_IArray this, int32_t index)
{
  char *base = IArray_BASE(this);
  size_t itemSize = IArray_ITEMSIZE(this);
  Except_REQUIRE(index >= 0 && index*itemSize < IArray_maxSize(this));
  return base + itemSize*index;
}