The included Node class can be used as a template for almost any class you would need (except possibly container classes). All classes use the Class library (Class.ahk) to provide their functionality, but all other classes are optional and only required if you wish to use them.
The zip file, found, here contains Class.ahk, the wrapper classes, classes Node, Cdll, and Array, some "test" scripts to demonstrate the Class library's functionality, and a Rectangle Class to demonstate how to modify the Node class to be your own, personalized class.
First off, every Class object has a class name stored with it. This allows for type checking (currenly, only the class' destroy function use type checking, should all Class functions use type checking?) Also, this allows dynamic calling of a classes destroy function. The objects have a "lock count" (description following), so the object is only destroyed when the lock count is zero.
Next, I use type "obj" (which is internally stored as a uint) to distinguish a class object from a normal address. Each class object (except _Node objects, e.g. Cdll_Node) have a lock count which tracks how many times a variable is used.
Each class has a new and a destroy function. The new function returns the address for the newly created object (or 0 if it fails, which should only result if there is not enough memory), and the destroy function returns true if the object was destroyed. The destroy function returns false if attempting to destroy an object of the wrong type (e.g. calling Node_destroy while passing a String object), or if the lock count for the object is not zero (the lock count is decreased by one and false is returned).
If the object is not a wrapper, then the address for the object is returned. Substitute the wrappers class for %ClassName%.
Code:
%ClassName%_new(value = "") - creates a new wrapper object with the specified value (or leave blank to make an empty wrapper object). The default is "" for strings and 0 for numbers.
%ClassName%_destroy(ClassObject) - destroys the object and frees the associated memory.
%ClassName%_getValue(ClassObject) - "unwraps" the value and returns it
%ClassName%_setValue(ClassObject, value) - "wraps" the specified value into the specified ClassObject.
Next, the Node Class.
Code:
Node_new(Size) - creates a new Node with <Size> number of user-entered values.
Node_destroy(Node) - destroys the Node and frees the associated memory.
Finally, the two Container classes.
Cdll functions:
Code:
Cdll_new() and Cdll_destroy(Cdll)
Cdll_addBefore/after(Cdll_Node, node) - creates a new Cdll_Node object after Cdll_Node and sets the node field of it to <node> (a class object). The function returns the address to the newly created Cdll_Node (or 0 if it fails, which should only occur if there is no more memory).
Note, Cdll_node (like all _Node classes) doesn't have a lock count.
Code:
Cdll_previous(Cdll_Node) - returns the address for the Cdll_Node before the specified one. The returned object is either of class Cdll_Node orr Cdll (the sentinel "node").
Cdll_next(Cdll_Node) - returns the address for the Cdll_Node after the specified one.
Cdll_remove(Cdll_Node) - removes the specified Cdll_Node from the Cdll which contains it (returning true on sucess). Note, Cdll_Node must be the address returned from either Cdll_addBefore or Cdll_addAfter. Calling Cdll_remove with any other class object (including the one returned from Cdll_new() has no effect.
The other container class included is Array.
Code:
Array_new(size) - creates a new Array with given size and returns the address to the Array object
Array_destroy(Array)
like all getters and setters, indexes start at 1. Also, the index is checked against the size of the array - 1 <= index <= size (as entered when creating the array)
Array_getAddress(Array, index) - returns the address for the class object.
Array_get(Array, index) - returns the value for the class object. If the class object is a wrapper, the return value is the "unwrapped" value in the wrapper, and if the object is not a wrapper, then the address for the object is returned (it behaves the same as Array_getAddress(Array, index))
Array_set(Array, index, value) - sets Array[index] to value. value must be a class object. To use a basic type (String, Int, etc.) use its respective wrapper class to wrap the value.
______
Right now, the menu wrapper so far can move items within a menu (while maintaining the menu icon (if added using Menu Icons), the menu "goto label"/submenu, the display name, and other menu data).
The menu and menu item dll structure has a value which can store a value.
Then, the menu wrapper will include a Cdll which contains Cdlls for each menu. This allows me to add the menu/menu item value to the cdll and sub menu cdll to the main Cdll (which stores all the menus).
Then, the address will be stored on the menu/menu item in the menu/menu item dll structure so that my menu wrapper can access and modify those values.
______
Yeah, I should be able to have the menu wrapper out tomorrow. I'm also going to incorporable Lexikos' Menu Icons into the wrapper.