#ifndef _LUCENE_LOCAL_EXTRA
#define _LUCENE_LOCAL_EXTRA
#ifndef LUCENE_HIDE_INTERNAL
#define __CLUCENEARRAY(mangle,proxytype,ctype,setter,deletor) ctype* array; \
	_CL##mangle##Array(ctype* a,int l){ \
		array=_CL_NEWARRAY(ctype,l+1);len=l; \
		for ( int i=0;i<l;i++ )set( a[i],i ); \
	} \
	_CL##mangle##Array(ctype* a){ \
		int l=0; if ( a != NULL ) while(a[l]!=NULL) l++; \
		array=_CL_NEWARRAY(ctype,l+1);len=l; \
		for ( int i=0;i<l;i++ ) set( a[i],i ); \
	}
#define __CLUCENEBASECLASS :LUCENE_BASE
#else
#define __CLUCENEARRAY(mangle,proxytype,ctype,setter,deletor)
#define __CLUCENEBASECLASS
#endif //LUCENE_HIDE_INTERNAL
#define CLUCENEARRAY(mangle,proxytype,ctype,setter,deletor) \
class _CL##mangle##Array __CLUCENEBASECLASS{ \
protected: \
	void clear(){ \
		if ( len >=0 && array != NULL ) \
			for ( int idx=0;idx<len;idx++ ) deletor; \
		len = 0; \
	} \
	int len; \
public: \
	_CL##mangle##Array(){ \
		len=-1; array = NULL; \
	} \
	~_CL##mangle##Array(){ \
		clear(); \
	} \
	int length(){ \
		if ( len == -1 ) _CLTHROWA(CL_ERR_InvalidState,"not initalised"); \
		return len; \
	} \
	void init(int len){ \
		clear(); \
		if ( len != -1 ) _CLDELETE_ARRAY(array); \
		this->array = _CL_NEWARRAY(ctype,len+1); \
		for ( int i=0;i<len+1;i++ ) array[i] = NULL; \
		this->len = len;  \
	} \
	ctype get(int idx) const{ \
		if ( len == -1 ) _CLTHROWA(CL_ERR_InvalidState,"not initalised"); \
		if ( idx < 0 && idx > len ) _CLTHROWA(CL_ERR_IndexOutOfBounds,"index out of range"); \
		return array[idx]; \
	}\
	void set(ctype a, int i){ \
		if ( len == -1 )_CLTHROWA(CL_ERR_InvalidState,"not initalised"); \
		if ( i < 0 && i > len ) _CLTHROWA(CL_ERR_IndexOutOfBounds,"index out of range"); \
		array[i] = setter; \
	} \
	__CLUCENEARRAY(mangle,proxytype,ctype,setter,deletor) \
};

#endif