struct vector_c
{
	int		base, len;
	vec_t	stub;
	vec_p	data, idx;
	vboolean verbose;
	char	caller[64];
	vector_c(int base,int len)
	{
		this->base = base;
		this->len = len;
		data = (vec_p)memAlloc(len * sizeof(vec_t));
		idx = data - base;
		verbose = false;
		strcpy(caller,"vector_c::operator[]");
	}
	~vector_c()
	{
		memFree(data);
	}
	vec_t &operator[](int elem)
	{
		if(elem < base || (elem-base)>=len)
		{
			conlPrintf(LOG_ERROR,
				"%s: wrong col (lower %d, upper %d, req %d).\n",
				caller,base,base+len-1,elem);
			stub = 0;
			return stub;
		}
		if(verbose)
			conlPrintf(LOG_INFO,
				"%s: col lower %d, upper %d, req %d.\n",
				caller,base,base + len - 1,elem);
		return idx[elem];
	}
};

struct matrix_c
{
	int		row_base, num_rows;
	int		col_base, num_cols;
	vector_c **rows;
	matrix_c(int row_base,int num_rows,int col_base,int num_cols)
	{
		this->row_base = row_base;
		this->num_rows = num_rows;
		this->col_base = col_base;
		this->num_cols = num_cols;
		rows = (vector_c**)memAlloc((num_rows + 1) * sizeof(vector_c*));
		for(int i=0;i <= num_rows;i++)
		{
			rows[i] = new vector_c(col_base,num_cols);
			strcpy(rows[i]->caller,"matrix_c::operator[][]");
		}
		rows[num_rows]->verbose = true;
	}
	~matrix_c(void)
	{
		for(int i=0;i <= num_rows;i++)
			delete rows[i];
		memFree(rows);
	}
	vector_c &operator[](int row_index)
	{
		if(row_index < row_base || (row_index - row_base) >= num_rows)
		{
			conlPrintf(LOG_ERROR,
				"matrix_c::operator[]: wrong row (lower %d, upper %d, req %d).\n",
				row_base,row_base + num_rows - 1,row_index);
			return *(rows[num_rows]);
		}
		return *(rows[row_index - row_base]);
	}
};

int main()
{
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	
	matrix_c m(1,2,1,2);
	
	m[0][0] = 0;
	m[0][1] = 1;
	m[1][0] = 2;
	m[1][1] = 3;
		
	m[0][4] = 0;
	m[3][0] = 0;
	m[3][4] = 0;
		
	return 0;
}
