2 Objects

2.1 The top-level object

The PnlObject structure is used to simulate some inheritance between the ojbects of Pnl. It must be the first element of all the objects existing in Pnl so that casting any object to a PnlObject is legal

typedef unsigned int PnlType; 
 
typedef void (DestroyFunc) (void **); 
typedef PnlObject* (CopyFunc) (PnlObject *); 
typedef PnlObject* (NewFunc) (PnlObject *); 
typedef void (CloneFunc) (PnlObject *dest, const PnlObject *src); 
struct _PnlObject 
{ 
  PnlType type; /*!< a unique integer id */ 
  const char *label; /*!< a string identifier (for the moment not useful) */ 
  PnlType parent_type; /*!< the identifier of the parent object is any, 
                          otherwise parent_type=id */ 
  int nref; /*!< number of references on the object */ 
  DestroyFunc *destroy; /*!< frees an object */ 
  NewFunc     *constructor; /*!< New function */ 
  CopyFunc    *copy; /*!< Copy function */ 
  CloneFunc   *clone; /*!< Clone function */ 
};

Here is the list of all the types actually defined




PnlType Description


PNL_TYPE_VECTOR general vectors
PNL_TYPE_VECTOR_DOUBLE real vectors
PNL_TYPE_VECTOR_INT integer vectors
PNL_TYPE_VECTOR_COMPLEX complex vectors
PNL_TYPE_MATRIX general matrices
PNL_TYPE_MATRIX_DOUBLE real matrices
PNL_TYPE_MATRIX_INT integer matrices
PNL_TYPE_MATRIX_COMPLEX complex matrices
PNL_TYPE_TRIDIAG_MATRIX general tridiagonal matrices
PNL_TYPE_TRIDIAG_MATRIX_DOUBLEreal tridiagonal matrices
PNL_TYPE_BAND_MATRIX general band matrices
PNL_TYPE_BAND_MATRIX_DOUBLE real band matrices
PNL_TYPE_SP_MATRIX sparse general matrices
PNL_TYPE_SP_MATRIX_DOUBLE sparse real matrices
PNL_TYPE_SP_MATRIX_INT sparse integer matrices
PNL_TYPE_SP_MATRIX_COMPLEX sparse complex matrices
PNL_TYPE_HMATRIX general hyper matrices
PNL_TYPE_HMATRIX_DOUBLE real hyper matrices
PNL_TYPE_HMATRIX_INT integer hyper matrices
PNL_TYPE_HMATRIX_COMPLEX complex hyper matrices
PNL_TYPE_BASIS bases
PNL_TYPE_RNG random number generators
PNL_TYPE_LIST doubly linked list
PNL_TYPE_ARRAY array

Table 1: PnlTypes

We provide several macros for manipulating PnlObejcts.

2.2 List object

This section describes functions for creating an manipulating lists. Lists are internally stored as doubly linked lists.

The structures and functions related to lists are declared in pnl/pnl_list.h.

typedef struct _PnlCell PnlCell; 
struct _PnlCell 
{ 
  struct _PnlCell *prev;  /*!< previous cell or 0 */ 
  struct _PnlCell *next;  /*!< next cell or 0 */ 
  PnlObject *self;       /*!< stored object */ 
}; 
 
 
typedef struct _PnlList PnlList; 
struct _PnlList 
{ 
  /** 
   * Must be the first element in order for the object mechanism to work 
   * properly. This allows any PnlList pointer to be cast to a PnlObject 
   */ 
  PnlObject object; 
  PnlCell *first; /*!< first element of the list */ 
  PnlCell *last; /*!< last element of the list */ 
  PnlCell *curcell; /*!< last accessed element, 
                         if never accessed is NULL */ 
  int icurcell; /*!< index of the last accessed element, 
                     if never accessed is NULLINT */ 
  int len; /*!< length of the list */ 
};

Important note: Lists only store addresses of objects. So when an object is inserted into a list, only its address is stored into the list. This implies that you must not free any objects inserted into a list. The deallocation is automatically handled by the function pnl_list_free.

2.3 Array object

This section describes functions for creating and manipulating arrays of PnlObjects.

The structures and functions related to arrays are declared in pnl/pnl_array.h.

typedef struct _PnlArray PnlArray; 
struct _PnlArray 
{ 
  /** 
   * Must be the first element in order for the object mechanism to work 
   * properly. This allows any PnlArray pointer to be cast to a PnlObject 
   */ 
  PnlObject object; 
  int size; 
  PnlObject **array; 
  int mem_size; 
};

Important note: Arrays only store addresses of objects. So when an object is inserted into an array, only its address is stored into the array. This implies that you must not free any objects inserted into a array. The deallocation is automatically handled by the function pnl_array_free.