The MetaClass is used to manage all classes supported by the system core.
The MetaClass is responsible for managing the construction of new classes. Each MetaClass object remains active for the lifetime of the running program, and provides the benefit of run-time introspection so that detailed class information can be retrieved at any time. This enables scripting languages such as Fluid to interact with all class types without needing active knowledge of their capabilities.
A number of additional functions are available in the Core for the purpose of class management and introspection. FindClass() allows all registered classes to be scanned. CheckAction() verifies if a specific action is supported by a class. FindField() confirms if a specific field is declared in the class specification.
Classes are typically declared in modules, but if a class is intended to be private for an executable then declaring it within the application code is feasible also.
Further discussion on classes and their technical aspects can be found in the Parasol Wiki.
The MetaClass class consists of the following fields:
Access | Name | Type | Comment | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ActionTable | APTR [] | This field can be read to retrieve a MetaClass object's internal action table. | |||||||||||||||||||||||||||
This field retrieves the internal action table of a class. The action table is arranged into a jump table of action routines, with each routine pointing directly to the object support functions. The size of the jump table is defined by the global constant It is possible to check if an action is supported by a class by looking up its index within the ActionTable, for example | |||||||||||||||||||||||||||||
Actions | APTR | Defines the actions supported by the class. | |||||||||||||||||||||||||||
Action routines are associated with a new class by referring to a list of ActionArray items in this field. Each provided action ID must be paired with its associated routine. Internally, the provided list is copied to the ActionTable and the original values will serve no further purpose. The following example shows a list of ActionArray structures borrowed from the Picture class. Note that such lists can also be auto-generated using our IDL scripts - an approach that we strongly recommend. ActionArray clActions[] = { { AC::Free, PIC_Free }, { AC::NewObject, PIC_NewObject }, { AC::Init, PIC_Init }, { AC::Query, PIC_Query }, { AC::Read, PIC_Read }, { AC::SaveToObject, PIC_SaveToObject }, { AC::Seek, PIC_Seek }, { AC::Write, PIC_Write }, { 0, NULL } }; Note: Never refer to method ID's in an action list - the Methods field is provided for this purpose. | |||||||||||||||||||||||||||||
BaseClassID | CLASSID | Specifies the base class ID of a class object. | |||||||||||||||||||||||||||
The BaseClassID must always be set prior to the initialisation of a new MetaClass object unless ClassName is considered sufficient. If the BaseClassID is zero then the hash of ClassName is computed and set as the value of BaseClassID. When defining a sub-class, it is required that the BaseClassID refers to the class that is being supported. | |||||||||||||||||||||||||||||
Category | CCF | The system category that a class belongs to. | |||||||||||||||||||||||||||
When designing a new class it is recommended that a suitable category is chosen and declared in this field. It is acceptable for a class to be a member of multiple categories by combining category flags together.
| |||||||||||||||||||||||||||||
ClassID | CLASSID | Specifies the ID of a class object. | |||||||||||||||||||||||||||
The ClassID uniquely identifies a class. If this value differs from the BaseClassID, then the class is determined to be a sub-class. The ClassID value always reflects the | |||||||||||||||||||||||||||||
ClassName | CSTRING | The name of the represented class. | |||||||||||||||||||||||||||
This field specifies the name of the represented class. Characters should be limited to those in the range of A-Z and written in camel case, e.g. | |||||||||||||||||||||||||||||
ClassVersion | DOUBLE | The version number of the class. | |||||||||||||||||||||||||||
This field value must reflect the version of the class structure. Legal version numbers start from 1.0 and ascend. Revision numbers can be used to indicate bug-fixes or very minor changes. If declaring a sub-class then this value can be | |||||||||||||||||||||||||||||
Dictionary | struct Field * | Returns a field lookup table sorted by field IDs. | |||||||||||||||||||||||||||
Following initialisation of the MetaClass, the Dictionary can be read to retrieve the internal field lookup table. For base-classes, the client can use the binary search technique to find fields by their ID. For sub-classes, use linear scanning. | |||||||||||||||||||||||||||||
Fields | const struct FieldArray * | Points to a FieldArray that describes the class' object structure. | |||||||||||||||||||||||||||
This field points to an array that describes the structure of objects that will be generated for this class. It is compulsory that base classes define this array. Sub-classes will inherit the structure of their base, but they may set Fields with additional virtual fields if desired. Refer to the Parasol Wiki on class development for more information. | |||||||||||||||||||||||||||||
FileDescription | CSTRING | Describes the file type represented by the class. | |||||||||||||||||||||||||||
This field allows you to specify a description of the class' file type, if the class is designed to be file related. This setting can be important, as it helps to distinguish your class from the other file based classes. Always make sure that your file description is short, descriptive and unique. A file description such as | |||||||||||||||||||||||||||||
FileExtension | CSTRING | Describes the file extension represented by the class. | |||||||||||||||||||||||||||
This field describes the file extension/s that the class will recognise. For example: Use of the vertical bar allows more than one file extension to be supported by the class. The file extension that is preferred for saving data must come first. | |||||||||||||||||||||||||||||
FileHeader | CSTRING | Defines a string expression that will allow relevant file data to be matched to the class. | |||||||||||||||||||||||||||
If a class supports file data, then the FileHeader field is used to identify the types of data that the class supports. This feature is used by routines that need to analyse files and determine which classes support them. For example, the JPEG class supports files that start with a 32-bit token to identify them as JPEG. Declaring a FileHeader expression to match these tokens will allow the FileView feature to detect JPEG files and display an appropriate icon for each JPEG entry in the file list. The expression format is The offset is an integer that identifies the byte position at which the given Value will be present. The Value is expressed as a hexadecimal number if it is prefixed with a dollar sign $, otherwise the Value is treated as case-sensitive text. Multiple expressions can be specified in sequence if there is more than one comparison to be made - so In some cases, a series of unrelated token sequences may need to be used to match against files. This is true for the JPEG class, which supports three different tokens all at offset 0 for identification. Each matching sequence must be separated with an OR symbol | as demonstrated in this example for the JPEG header: | |||||||||||||||||||||||||||||
Flags | CLF | Optional flag settings. | |||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||
Icon | CSTRING | Associates an icon with the file data for this class. | |||||||||||||||||||||||||||
Files that belong to a class can be associated with an icon that is declared in this field. The icon string format is | |||||||||||||||||||||||||||||
Location | STRING | Returns the path from which the class binary is loaded. | |||||||||||||||||||||||||||
The path from which the class binary was loaded is readable from this field. The path may not necessarily include the file extension of the source binary. | |||||||||||||||||||||||||||||
Methods | STRUCT [] | Set this field to define the methods supported by the class. | |||||||||||||||||||||||||||
If a class design will include support for methods, create a MethodEntry list and set this field prior to initialisation. The array must provide information on each method's ID, name, parameters, and structure size. Note that method lists can be auto-generated using our IDL scripts - an approach that we strongly recommend. | |||||||||||||||||||||||||||||
Module | STRING | The name of the module binary that initialised the class. | |||||||||||||||||||||||||||
Objects | LONG [] | Returns an allocated list of all objects that belong to this class. | |||||||||||||||||||||||||||
This field will compile a list of all objects that belong to the class. The list is sorted with the oldest object appearing first. The resulting array must be terminated with FreeResource() after use. | |||||||||||||||||||||||||||||
OpenCount | INT | The total number of active objects that are linked back to the MetaClass. | |||||||||||||||||||||||||||
This field reveals the total number of objects that reference the class. This figure will fluctuate over time as new objects are created and old ones are destroyed. When the OpenCount reaches zero, the Core may flush the Module that the class is related to, so long as no more programs are using it or any other classes created by the module. | |||||||||||||||||||||||||||||
Path | CSTRING | The path to the module binary that represents the class. | |||||||||||||||||||||||||||
The Path field must be set on initialisation and refers to the default location of the class' module binary, for example | |||||||||||||||||||||||||||||
RootModule | OBJECTPTR | Returns a direct reference to the RootModule object that hosts the class. | |||||||||||||||||||||||||||
Size | INT | The total size of the object structure represented by the MetaClass. | |||||||||||||||||||||||||||
This field value must indicate the byte size of the objects that will be created from the MetaClass. For example, the Picture class defines this value as If the size is not explicitly defined, the initialisation process will determine the structure size by evaluating the field definitions that have been provided. |
The following methods are currently supported:
Name | Comment | ||||||||
---|---|---|---|---|---|---|---|---|---|
FindField | Search a class definition for a specific field. | ||||||||
ERR mc::FindField(OBJECTPTR Object, LONG ID, struct Field ** Field, objMetaClass ** Source)
This method checks if a class has defined a given field by scanning its blueprint for a matching In some clases the field might not be present in the main class spec, but does appear in an integral class. In that case, a reference to the class will be returned in the |
Class categories
Name | Description |
---|---|
CCF::AUDIO | Audio classes interface with audio hardware and drivers for audio playback and recording purposes. |
CCF::COMMAND | Command classes perform specific procedures, like copying or moving a file, managing volumes or executing a program. |
CCF::DATA | Data classes parse, query and manipulate data. |
CCF::FILESYSTEM | FileSystem classes are based on file management and interaction with file based data. |
CCF::GRAPHICS | Graphics classes provide graphics management and drawing services. |
CCF::GUI | GUI classes are used in the development of graphical user interfaces. |
CCF::IO | I/O classes manage hardware and software based input and output. |
CCF::MISC | Miscellaneous classes do not fit into any of the other available categories. |
CCF::MULTIMEDIA | Classes that represent more than one media type, e.g. video files. |
CCF::NETWORK | Network classes interface with system drivers to simplify network communications. |
CCF::SYSTEM | System classes are designed to provide low-level services related to system management. |
CCF::TOOL | Tools provide interactive services for the user. |
Flags for the MetaClass.
Name | Description |
---|---|
CLF::INHERIT_LOCAL | Inherit the functionality of local objects defined in the class spec. |
CLF::NO_OWNERSHIP | Objects created will not be tracked to the creating process, nor any parent object (SetOwner() will not work either). |
Field | Type | Description |
---|---|---|
Routine | APTR | Pointer to the function entry point |
ActionCode | AC | Action identifier |
Used to describe the public fields of a class.
Field | Type | Description |
---|---|---|
Arg | MAXINT | An option to complement the field type. Can be a pointer or an integer value |
GetValue | FUNCTION * | A virtual function that will retrieve the value for this field. |
SetValue | APTR | A virtual function that will set the value for this field. |
WriteValue | FUNCTION * | An internal function for writing to this field. |
Name | CSTRING | The English name for the field, e.g. Width |
FieldID | ULONG | Provides a fast way of finding fields, e.g. FID_Width |
Offset | UWORD | Field offset within the object |
Index | UWORD | Field array index |
Flags | ULONG | Special flags that describe the field |
Used to construct class blueprints for the MetaClass.
Field | Type | Description |
---|---|---|
Name | CSTRING | The name of the field, e.g. Width |
GetField | APTR | void GetField(*Object, APTR Result); |
SetField | APTR | ERR SetField(*Object, APTR Value); |
Arg | MAXINT | Can be a pointer or an integer value |
Flags | ULONG | Special flags that describe the field |
Class Info | |
---|---|
ID | ID_METACLASS |
Category | System |
Include | modules/metaclass.h |
Version | 1 |