// COPYRIGHT (C) 1990-1999.  All Rights Reserved. - DATA.HPP
// Zinc Software Incorporated.  Pleasant Grove, Utah  USA
// May be freely copied, used and distributed.

#include <z_list.hpp>
#include <z_str.hpp>

class SimpleDatabase : protected ZafList
{
public:
	SimpleDatabase(int recordSize);
	virtual ~SimpleDatabase(void);

	void AddRecord(void *record, ZafOffset index = -1);
	void DeleteRecord(ZafOffset index);
	void ModifyRecord(ZafOffset index, void *record);

	int Records(void) { return ((int)records); }
	int CurrentRecord(void *record = ZAF_NULLP(void));
	int SeekNextRecord(void *record = ZAF_NULLP(void));
	int SeekPreviousRecord(void *record = ZAF_NULLP(void));
	int SeekRandomRecord(ZafOffset index, void *record = ZAF_NULLP(void));

private:
	int recordSize;
	ZafOffset records;
	ZafOffset currentIndex;
	ZafElement *currentElement;

	class RecordElement : public ZafElement
	{
	public:
		RecordElement(void *record, int recordSize);
		virtual ~RecordElement(void);

		void *Record(void) { return record; }
		void SetRecord(void *setRecord, int recordSize) { memcpy(record, setRecord, (size_t)recordSize); }

	private:
		void *record;
	};
};
