// CodeGear C++Builder
// Copyright (c) 1995, 2021 by Embarcadero Technologies, Inc.
// All rights reserved

// (DO NOT EDIT: machine generated header) 'ABSPage.pas' rev: 35.00 (Windows)

#ifndef AbspageHPP
#define AbspageHPP

#pragma delphiheader begin
#pragma option push
#pragma option -w-      // All warnings off
#pragma option -Vx      // Zero-length empty class member 
#pragma pack(push,8)
#include <System.hpp>
#include <SysInit.hpp>
#include <System.Classes.hpp>
#include <Winapi.Windows.hpp>
#include <System.Math.hpp>
#include <ABSExcept.hpp>
#include <ABSMemory.hpp>
#include <ABSConst.hpp>
#include <ABSTypes.hpp>

//-- user supplied -----------------------------------------------------------

namespace Abspage
{
//-- forward type declarations -----------------------------------------------
struct TABSPageTableStateInfo;
class DELPHICLASS TABSPage;
class DELPHICLASS TABSPageController;
struct TABSPageElement; struct TABSSessionPageInfo;
class DELPHICLASS TABSSortedPageList;
struct TABSSessionPageInfo;
class DELPHICLASS TABSPageManager;
//-- type declarations -------------------------------------------------------
#pragma pack(push,1)
struct DECLSPEC_DRECORD TABSPageTableStateInfo
{
public:
	int TableState;
	bool IsTableStateValueAssigned;
};
#pragma pack(pop)


#pragma pack(push,4)
class PASCALIMPLEMENTATION TABSPage : public System::TObject
{
	typedef System::TObject inherited;
	
	
private:
	typedef System::DynamicArray<TABSPageTableStateInfo> _TABSPage__1;
	
	
private:
	TABSPageManager* LPageManager;
	int FPageNo;
	System::Byte *FPageBuffer;
	bool FOwnBuffer;
	bool FIsDirty;
	int FUseCount;
	TABSSortedPageList* FParentList;
	int FSessionID;
	bool FReloaded;
	bool FEncryptionEnabled;
	_TABSPage__1 FTableStates;
	Abstypes::PABSDiskPageHeader __fastcall GetPageHeader();
	int __fastcall GetPageHeaderSize();
	System::PByte __fastcall GetPageData();
	int __fastcall GetPageDataSize();
	int __fastcall GetPageSize();
	
public:
	void __fastcall InitHeader();
	__fastcall TABSPage(TABSPageManager* PageManager);
	__fastcall virtual ~TABSPage();
	void __fastcall ClearPageBuffer();
	void __fastcall AllocPageBuffer();
	void __fastcall FreeAndNilPageBuffer();
	void __fastcall EnlargePageBuffer(int NewSize);
	void __fastcall Synchronize();
	bool __fastcall GetTableState(int SessionID, int &TableState);
	void __fastcall SetTableState(int SessionID, int TableState);
	__property int PageNo = {read=FPageNo, write=FPageNo, nodefault};
	__property int PageSize = {read=GetPageSize, nodefault};
	__property System::PByte PageBuffer = {read=FPageBuffer, write=FPageBuffer};
	__property bool OwnBuffer = {read=FOwnBuffer, write=FOwnBuffer, nodefault};
	__property bool IsDirty = {read=FIsDirty, write=FIsDirty, nodefault};
	__property int UseCount = {read=FUseCount, write=FUseCount, nodefault};
	__property TABSPageManager* PageManager = {read=LPageManager, write=LPageManager};
	__property Abstypes::PABSDiskPageHeader PageHeader = {read=GetPageHeader};
	__property int PageHeaderSize = {read=GetPageHeaderSize, nodefault};
	__property System::PByte PageData = {read=GetPageData};
	__property int PageDataSize = {read=GetPageDataSize, nodefault};
	__property TABSSortedPageList* ParentList = {read=FParentList, write=FParentList};
	__property int SessionID = {read=FSessionID, write=FSessionID, nodefault};
	__property bool Reloaded = {read=FReloaded, write=FReloaded, nodefault};
	__property bool EncryptionEnabled = {read=FEncryptionEnabled, write=FEncryptionEnabled, nodefault};
};

#pragma pack(pop)

#pragma pack(push,4)
class PASCALIMPLEMENTATION TABSPageController : public System::TObject
{
	typedef System::TObject inherited;
	
private:
	TABSPage* LPage;
	
protected:
	void __fastcall SetPageNo(int Value);
	int __fastcall GetPageNo();
	int __fastcall GetPageSize();
	void __fastcall SetPageBuffer(System::PByte Value);
	System::PByte __fastcall GetPageBuffer();
	void __fastcall SetOwnBuffer(bool Value);
	bool __fastcall GetOwnBuffer();
	void __fastcall SetIsDirty(bool Value);
	bool __fastcall GetIsDirty();
	void __fastcall SetUseCount(int Value);
	int __fastcall GetUseCount();
	TABSPageManager* __fastcall GetPageManager();
	System::PByte __fastcall GetPageData();
	int __fastcall GetPageDataSize();
	
public:
	void __fastcall EnlargePageBuffer(int NewSize);
	__property TABSPage* Page = {read=LPage, write=LPage};
	__property int PageNo = {read=GetPageNo, write=SetPageNo, nodefault};
	__property int PageSize = {read=GetPageSize, nodefault};
	__property System::PByte PageBuffer = {read=GetPageBuffer, write=SetPageBuffer};
	__property bool OwnBuffer = {read=GetOwnBuffer, write=SetOwnBuffer, nodefault};
	__property bool IsDirty = {read=GetIsDirty, write=SetIsDirty, nodefault};
	__property int UseCount = {read=GetUseCount, write=SetUseCount, nodefault};
	__property TABSPageManager* PageManager = {read=GetPageManager};
	__property System::PByte PageData = {read=GetPageData};
	__property int PageDataSize = {read=GetPageDataSize, nodefault};
public:
	/* TObject.Create */ inline __fastcall TABSPageController() : System::TObject() { }
	/* TObject.Destroy */ inline __fastcall virtual ~TABSPageController() { }
	
};

#pragma pack(pop)

struct DECLSPEC_DRECORD TABSPageElement
{
public:
	TABSPage* Page;
	__int64 LRUCount;
};


class PASCALIMPLEMENTATION TABSSortedPageList : public System::TObject
{
	typedef System::TObject inherited;
	
	
private:
	typedef System::DynamicArray<int> _TABSSortedPageList__1;
	
	typedef System::DynamicArray<TABSPageElement> _TABSSortedPageList__2;
	
	
private:
	_TABSSortedPageList__1 KeyItems;
	int ItemCount;
	int AllocBy;
	int deAllocBy;
	int MaxAllocBy;
	int AllocItemCount;
	__int64 LRUCount;
	int LRULastFound;
	int __fastcall FindPositionForInsert(int key);
	int __fastcall FindPosition(int key);
	void __fastcall InsertByPosition(int ItemNo, int key, TABSPageElement &value);
	void __fastcall DeleteByPosition(int ItemNo);
	
public:
	_TABSSortedPageList__2 ValueItems;
	__fastcall TABSSortedPageList(int size);
	void __fastcall SetSize(int newSize);
	TABSPage* __fastcall Find(int key);
	void __fastcall Insert(TABSPage* Page);
	void __fastcall Delete(int PageNo);
	void __fastcall Clear();
	TABSPage* __fastcall FirstByLRU();
	TABSPage* __fastcall NextByLRU();
	void __fastcall UpdateLRU(TABSPage* Page);
	__property int Count = {read=ItemCount, nodefault};
public:
	/* TObject.Destroy */ inline __fastcall virtual ~TABSSortedPageList() { }
	
};


struct DECLSPEC_DRECORD TABSSessionPageInfo
{
public:
	int SessionID;
	TABSSortedPageList* DirtyPages;
	Abstypes::TABSIntegerArray* AddedPageNumbers;
	Abstypes::TABSIntegerArray* RemovedPageNumbers;
};


#pragma pack(push,4)
class PASCALIMPLEMENTATION TABSPageManager : public System::TObject
{
	typedef System::TObject inherited;
	
	
private:
	typedef System::DynamicArray<TABSSessionPageInfo> _TABSPageManager__1;
	
	
protected:
	_RTL_CRITICAL_SECTION FCSect;
	int FCacheCapacity;
	TABSSortedPageList* FSharedPages;
	_TABSPageManager__1 FSessions;
	System::Word FPageSize;
	System::Word FPageHeaderSize;
	System::Word FPageDataSize;
	int FPageCount;
	bool FMultiUser;
	bool FIgnoreCRCErrors;
	void __fastcall Lock();
	void __fastcall Unlock();
	int __fastcall AddNewSession(int SessionID);
	bool __fastcall FindSession(int SessionID, int &SessionNo);
	bool __fastcall FindPage(TABSSortedPageList* Pages, int PageNo, TABSPage* &Page);
	void __fastcall RemovePageIfExists(TABSSortedPageList* Pages, int PageNo);
	virtual int __fastcall GetPageCount();
	virtual bool __fastcall IsSafeNotToSyncPage(int SessionID, TABSPage* Page);
	virtual void __fastcall UpdatePageTableState(int SessionID, TABSPage* Page);
	
public:
	virtual void __fastcall LoadFromStream(System::Classes::TStream* Stream);
	virtual void __fastcall SaveToStream(System::Classes::TStream* Stream);
	virtual void __fastcall InternalAddPage(TABSPage* aPage) = 0 ;
	virtual void __fastcall InternalRemovePage(int PageNo) = 0 ;
	virtual bool __fastcall InternalReadPage(TABSPage* aPage) = 0 ;
	virtual void __fastcall InternalWritePage(TABSPage* aPage) = 0 ;
	__fastcall TABSPageManager();
	__fastcall virtual ~TABSPageManager();
	TABSPage* __fastcall AddPage(int SessionID, System::Word PageType);
	virtual void __fastcall RemovePage(int SessionID, int PageNo);
	virtual TABSPage* __fastcall GetPage(int SessionID, int PageNo, System::Word PageType, bool SynchronizeAllowed = true);
	void __fastcall PutPage(TABSPage* aPage);
	virtual void __fastcall ApplyChanges(int SessionID);
	void __fastcall CancelChanges(int SessionID);
	__property System::Word PageSize = {read=FPageSize, nodefault};
	__property System::Word PageHeaderSize = {read=FPageHeaderSize, nodefault};
	__property System::Word PageDataSize = {read=FPageDataSize, nodefault};
	__property int PageCount = {read=GetPageCount, nodefault};
	__property bool MultiUser = {read=FMultiUser, write=FMultiUser, nodefault};
	__property bool IgnoreCRCErrors = {read=FIgnoreCRCErrors, write=FIgnoreCRCErrors, nodefault};
};

#pragma pack(pop)

//-- var, const, procedure ---------------------------------------------------
}	/* namespace Abspage */
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_ABSPAGE)
using namespace Abspage;
#endif
#pragma pack(pop)
#pragma option pop

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// AbspageHPP
