JegasAPI - www.jegas.com

Class JFC_DL

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type JFC_DL = class(JFC_DLITEM)

Description

Out of the box this class manipulates JFC_DLITEM class - Which until you expand on it - or use a one of the derivitives iNN here, is useless. It gives you the foundation for a very powerful double linked list pair: JFC_DLITEM CLASS to have dynamic instances of , and a JFC_DL to manage multiple instances of your CLASSES derived from JFC_DLITEM.

Sample Code provided iNN vitual "STUB" routines contained iNN comments

Hierarchy

Overview

Fields

Public bCopy: Boolean;
Public bDebug: Boolean;
Public bDestroyNestedLists: boolean;
Public bShowNestedLists: boolean;
Public iType: Int64;
Public lpFirst: pointer;
Public lpItem: pointer;
Public lpLast: pointer;
Public lpOwner: pointer;
Public pvt_u8AutoNumber: UInt64;
Public uItems: UInt64;
Public uN: UInt64;

Methods

Public Constructor Create;
Public Constructor CreateCopy(p_lpSameTypeOfClass: pointer);
Public Destructor Destroy; override;
Public Function AppendItem:Boolean;
Public Function AppendItemToList(p_lpNewItem: pointer):Boolean;
Public Function AppendItem_lpPtr(p_lpPtr: pointer): Boolean;
Public Function AutoNumber: UInt64;
Public Function BOL: Boolean;
Public Function DeleteAll: Boolean;
Public Function DeleteItem:Boolean;
Public Function DeleteThisItem(p_lpItem:pointer):Boolean;
Public Function EOL: Boolean;
Public Function FNextItem_lpPTR(p_lp: pointer):Boolean;
Public Function FoundAnsistring( p_saString: AnsiString; p_bCaseSensitive: Boolean; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;
Public Function FoundBinary( p_lpWhat: pointer; p_uSize: UInt64; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;
Public Function FoundItem(p_lp: pointer):Boolean;
Public Function FoundItem_lpPTR(p_lp: pointer):Boolean;
Public Function FoundNth(p_uN: UInt64):Boolean;
Public Function FoundTimestamp( p_tsFrom: TTIMESTAMP; p_tsTo: TTIMESTAMP; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;
Public Function InsertItem:Boolean;
Public Function InsertItemInList(p_lpNewItem: pointer):Boolean;
Public Function InsertItem_lpPtr(p_lpPtr: pointer): Boolean;
Public Function MoveFirst:Boolean;
Public Function MoveLast:Boolean;
Public Function MoveNext:Boolean;
Public Function MovePrevious:Boolean;
Public Function NextItem_lpPtr: pointer;
Public Function Next_lpItem:pointer;
Public Function PrevItem_lpPtr: pointer;
Public Function Prev_lpItem:pointer;
Public Function pvt_CreateItem: JFC_DLITEM; Virtual;
Public Function read_item_lpPtr: pointer;
Public Function RemoveItemFromList:pointer;
Public Function RemoveThisItemFromList(p_lpItem:pointer):pointer;
Public Function SortAnsistring( p_bCaseSensitive: Boolean; p_lpOffset: pointer; p_bAscending: Boolean; p_bUsePtr: Boolean ):Boolean;
Public Function SortBinary( p_uSize: UInt64; p_lpOffset: pointer; p_bAscending: Boolean; p_bUsePtr: Boolean ):Boolean;
Public Procedure pvt_createtask; Virtual;
Public Procedure pvt_DestroyItem(p_lp:pointer); Virtual;
Public Procedure pvt_destroytask(p_lp: pointer); Virtual;
Public Procedure SwapItems(p_lpItem1, p_lpItem2: pointer);
Public Procedure SwapItem_lpPtr(p_lpItem1, p_lpItem2: pointer);
Public Procedure Sync(p_lpSameTypeOfClass: pointer); Virtual;
Public Procedure write_item_lpptr(p_lp:pointer);

Properties

Public property IsCopy: Boolean read bCopy;
Public property Item_lpPtr: pointer read read_item_lpPtr Write write_item_lpptr;
Public property ListCount: UInt64 read UItems;
Public property N: UInt64 read uN;

Description

Fields

Public bCopy: Boolean;
 
Public bDebug: Boolean;

=============================================================================

Public bDestroyNestedLists: boolean;

DELETE Special Flag - If you inherit JFC_DL - you must implement yourself. For example see pvt_destroyitem. It's simple. DEFAULT is FALSE. If Set to TRUE - then when the interior pvt_Destroyitem function is called via DeleteItem, DeleteAll or DeleteThisItem - then the JFC_DLITEM.lpPtr field is checked to see if its NIL. If it IS NOT NIL - It is presumed to be a pointer to another JFC_DL class - which needs to be destroyed so orphans aren't left in memory. SO... It Calls DeleteAll on the JFC_DL hanging off the DLITEM.lpPtr we are deleting, then destroys it, and sets lpPtr to NIL right before the item is released. There is no 100% secure way I know of to ascertain if the class I want to delete IS NOT a base or whatever...

SO DO NOT misunderstand the name of this variable. I needed a generic enough name so descendants can implement this also.

If this FLAG is true, the Code in the JFC_DL.pvt_destroyitem procedure ASSUMES the Object pointed to in JFC_DLITEM.lpPtr is a JFC_DL.

Likewise, in the JFC_XDL class, If this FLAG is true, the Code in the JFC_XDL.pvt_destroyitem procedure ASSUMES the Object pointed to in JFC_XDLITEM.lpPtr is a JFC_XDL.

Public bShowNestedLists: boolean;

Not Implemented fully this Generation - but ATM, 2009-02-12, only JFC_XDL and JFC_XXDL have the saHTMLTable Function. The same way that bDestroyNestedLists:=true - Destroys DL's hanging off the JFC_DLITEM.lpPtr (if not NIL), this variable controls if the saHTMLTable function rendered nested lists.

Public iType: Int64;

Value is DESCENDANT DEFINED, use as you like. 32bit or 64bit - depends on endian

Public lpFirst: pointer;

32bit or 64bit - depends on endian

Public lpItem: pointer;

CURRENT "ItemClass" this CLASS is looking at.

Public lpLast: pointer;
 
Public lpOwner: pointer;

DESCENDANT DEFINED - can be handy

Public pvt_u8AutoNumber: UInt64;
 
Public uItems: UInt64;
 
Public uN: UInt64;

< 32bit or 64bit - depends on endian

Methods

Public Constructor Create;

OVERRIDE BUT INHERIT

Public Constructor CreateCopy(p_lpSameTypeOfClass: pointer);

Makes an Instance of CLASS that is "ReadOnly" and "looks" at the list managed by the CLASS you passed iNN p_lpSameTypeOfClass. This allows TWO or more "CURSORs" iNN the same list. Before You Start messing with a copyied VERSION of this CLASS, call "Sync" method if it is possible the copied CLASS has added or removed any items.

Public Destructor Destroy; override;

override but inherit

Public Function AppendItem:Boolean;

true unless copy or error

Public Function AppendItemToList(p_lpNewItem: pointer):Boolean;

Appends your class to the end of the list and makes it the current item. Pass pointer to your classitem - You are responsible for not adding same class twice - that is pointless ONE and TWO it will corrupt the list. If you're not sure - Call "FindItem" function - with the pointer of the class you wish to add. If it returns false - then its safe to add it.

Public Function AppendItem_lpPtr(p_lpPtr: pointer): Boolean;

True unless copy or error

Public Function AutoNumber: UInt64;

Special Feature Presentation of the Highly advanced AutoNumber ;) Returns a higher LongInt number each time its called until it rolls over. Good for UNIQUE IDENTIFIERS. Works Like Database AUTONUMBER fields. NOTE: This is not called automatically ANYWHERE - Descendant classes that wish to utilize this are totally responsible for calling this routine at the right times - Suggestion: When AppendItem'n or InsertITem'n ;)

Public Function BOL: Boolean;

"Beginning of List" - TRUE if Current Item is the FIRST ITEM iNN the list OR the list is Empty.

Public Function DeleteAll: Boolean;

DeleteAll Returns TRUE unless Error - Or bCopyied Class.

Public Function DeleteItem:Boolean;

TRUE if Successful Delete - False if Copy, empty list, or error

Public Function DeleteThisItem(p_lpItem:pointer):Boolean;
 
Public Function EOL: Boolean;

"End Of List" - TRUE if Current Item is the LAST ITEM iNN the list OR the list is Empty.

Public Function FNextItem_lpPTR(p_lp: pointer):Boolean;

Good Sample Source to See How a Basic JFC_DL.FoundBinary is done. Looks for your pointer starting from beginning of list

Public Function FoundAnsistring( p_saString: AnsiString; p_bCaseSensitive: Boolean; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;

CORE Ansistring Search Same as FoundBinary but for Ansistrings - Has Case Sensitivity option. Not for use with NORMAL STRINGS. Normal Strings have serious limitations not true with ANSISTRINGS. I CHOSE to use ANSISTRINGS as much as possible. Sorry there isn't a Case insensitive search for normal strings. This is a base class....you could write one! :)

Public Function FoundBinary( p_lpWhat: pointer; p_uSize: UInt64; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;

Search Funtions NOTES ABOUT THESE SEARCH METHODS: –They All are smart enough to just return false if the list is empty. –They ALL - upon a successful FIND - Set the CURRENT Item to the just FOUND item. –They ALL - upon failing - RETURN the list to the item that was Current before the search was invoked. –They all are reasonably fast, platform independant and to a large degree datatype oblivious - less special searches for ANSISTRING type. –Any Binary searches for data types (for instance a whole record) that has one or more ANSISTRING variables iNN it will be unreliable because ANSISTRINGS are really pointers and the SAME data might be stored somewhere else _in_ mem, meaning pointer values won't match - hence search MAY fail.

CORE Binary Search - Tricky BUT GOLDEN!

Returns TRUE if Found and False if not. Good For EXACT MATCHES of BINARY Data - This means everything except ANSISTRINGS - IF used for STRINGS - CASE and LENGTH SENSISTIVE!

Its Tricky but portable - Kind of a VARIANT type thing - HERE is an example to try to explain how it works.

Result:=JFC_DL.FoundBinary(@FindThis, SizeOf(FindThis), @TYOURITEMCLASS(nil).FindThisField; TRUE,FALSE);

To Seek a record based on an OBJECT stored _in_ lpPTR change the last field to true and instead of @TYOURITEMCLASS(nil).iFindThisField Use @YOURCLASS(nil).iFindThisField;

NOTE: The TypeCast of nil is MUTE! ITs used for pointer math - But you need to send it because it is a reference point for the pointer math. IT Works - thats all that matters. If you have multiple SIZE class items managed by this JFC_DL class - Careful about Searching fields that might (memory wise) fall outside of a class's memory bounds - _in_ Short - If you have two classes _in_ a list where the FIRST type has one LongInt and the second has two - You should only do searches on the FIRST int cuz you might inadvertantly attempt to read from a memory location that isn't yours. This shouldn't be something to worry about until you start getting REALLY complex - multiple class types _in_ same linked list etc. And even then it works with care.

Public Function FoundItem(p_lp: pointer):Boolean;

Looks for specific lpItem pointer value - Important Because just setting lpItem to a specific pointer to an ITEM you know EXISTS will screw up "Nth" - The Item's #'d position iNN list - BUT you can get around this for blazing speed by SETTING lpITem directly = and doing a MoveFirst or MoveLast to resync Nth value...As long as you remember that "Nth" is corrupt until then if you just hyperspeed your way around.

Use this to be safe. If its already THERE - just returns TRUE otherwise IT does a MoveFirst and loops through list until it finds it. If it DOES it returns TRUE, FALSE otherwise.

Public Function FoundItem_lpPTR(p_lp: pointer):Boolean;

Good Sample Source to See How a Basic JFC_DL.FoundBinary is done. Looks for your pointer starting from NEXT position _in_ list

Public Function FoundNth(p_uN: UInt64):Boolean;

SEEK "Nth" item uN list. Returns TRUE if Found, FALSE otherwise

This routine does calculate the shortest method to navigate from the current position iNN the list to the requested one. But it does require multiple iterations - though so far it proves to be pretty darn fast. Fast as it can without a jump table.

I didn't add a jump table as a memory saver for classes that don't even use this. It would be very possible to make your own jump table. I didn't because it would add storage overhead I didn't want iNN the base class.

Public Function FoundTimestamp( p_tsFrom: TTIMESTAMP; p_tsTo: TTIMESTAMP; p_lpOffset: pointer; p_bStartAtBegin: Boolean; p_bUsePtr: Boolean):Boolean;

CORE TTIMESTAMP Search Same as FoundBinary but for TTIMESTAMP This does not return a sort listed, it simply searches for the next TTIMESTAMP within the p_tsFrom and p_tsTo Parameters.

Public Function InsertItem:Boolean;

TRUE if Successful - False if Copy, or error

Public Function InsertItemInList(p_lpNewItem: pointer):Boolean;

Inserts Your Class iNN front of the current item and becomes the current item. Same rules apply as append concerning duplicates.

Public Function InsertItem_lpPtr(p_lpPtr: pointer): Boolean;

TRUE if Successful - False if Copy, or error

Public Function MoveFirst:Boolean;
 
Public Function MoveLast:Boolean;
 
Public Function MoveNext:Boolean;
 
Public Function MovePrevious:Boolean;
 
Public Function NextItem_lpPtr: pointer;

Returns RAW value from JFC_DLITEM.lpPtr field from the next or prev item. If it doesn't exist - Currently its designed to just bomb for speed reasons. (Die Quickly...kidding)

Public Function Next_lpItem:pointer;

Pointer to next JFC_DLITEM item (See lpItem)

Public Function PrevItem_lpPtr: pointer;
 
Public Function Prev_lpItem:pointer;

Pointer to next JFC_DLITEM item (See lpItem)

Public Function pvt_CreateItem: JFC_DLITEM; Virtual;

OVERRIDE - DON'T INHERIT! Make this return YOUR ITEM CLASS TYPE after its instanced.

Public Function read_item_lpPtr: pointer;

make properties work

Public Function RemoveItemFromList:pointer;

"Removes" Current Item from List - Returns NIL if failed else pointer to your removed item. Fails if list empty or a "bCopy"

Public Function RemoveThisItemFromList(p_lpItem:pointer):pointer;

Same Thing as RemoveItemFromList but removes SPECIFIC item instead of Current "lpItem".

Public Function SortAnsistring( p_bCaseSensitive: Boolean; p_lpOffset: pointer; p_bAscending: Boolean; p_bUsePtr: Boolean ):Boolean;

THIS is a slow Bubble Sort - Though Pointer method faster paradigm Then trying to sort the ACTUAL pointers that control the DL navigation

Public Function SortBinary( p_uSize: UInt64; p_lpOffset: pointer; p_bAscending: Boolean; p_bUsePtr: Boolean ):Boolean;

THIS is a slow Bubble Sort - Though Pointer method faster paradigm Then trying to sort the ACTUAL pointers that control the DL navigation

Public Procedure pvt_createtask; Virtual;

Place to put "generations" of code thats you can add to but inherit the previous generation - unlike pvt_createitem which gets overriden entirely CALLED AFTER pvt_createItem

Public Procedure pvt_DestroyItem(p_lp:pointer); Virtual;

OVERRIDE - DON'T INHERIT! Make This DESTROY your ClassItem When p_ptr (pointer to YOUR class) is sent.

Public Procedure pvt_destroytask(p_lp: pointer); Virtual;

Place to put "generations" of code thats you can add to but inherit the previous generation - unlike pvt_destroyitem which gets overriden entirely CALLED BEFORE pvt_DestroyItem

Public Procedure SwapItems(p_lpItem1, p_lpItem2: pointer);

No Error Checking - Make sure they exist - Swaps Sequential Positions in list - not fastest thing iNN world but it works.

Public Procedure SwapItem_lpPtr(p_lpItem1, p_lpItem2: pointer);

Faster Than Swap Items - This doesn't Change the ORDER or the linked list itself - it swaps the data iNN the JFC_DLITEM.lpPtr fields. You Supply the TWO "ITEMS" that point to the JFC_DLITEM classes.

Public Procedure Sync(p_lpSameTypeOfClass: pointer); Virtual;

OVERRIDE BUT INHERIT

Public Procedure write_item_lpptr(p_lp:pointer);

make properties work

Properties

Public property IsCopy: Boolean read bCopy;

Returns TRUE if this class was created with the CreateCopy constructor.

Public property Item_lpPtr: pointer read read_item_lpPtr Write write_item_lpptr;

————————————————————————— Properties and Stuff Added for conveinance of accessing fields iNN "ITEMs"

Public property ListCount: UInt64 read UItems;

Returns number of items uN list.

Public property N: UInt64 read uN;

Reports CURRENT Item's sequential position iNN the list.

JegasAPI - www.jegas.com
Generated by PasDoc 0.14.0.