Topics

Note Selector

Loading Definitions

Monday, August 12, 2024

Definitions are loaded from a definition directory, typically as part of the initialization of a software library or application.

Most of the files in the directory make up the definition files, but there are some special files, such as alias files.

Multiple definitions can exist within a single file, either adjacently or in a hierarchy.

Definition files can depend/inherit from other definition files. Therefore, all definition files need to be loaded before they can be resolved, which is a process of finalizing the construction of loaded definitions.

There are 3 resolving processes that need to take place after loading definition files:

  • Resolve Inheritance - Copy the data structure of another definition
  • Resolve Parents - Move child definitions that existed in other files into their parent definitions
  • Resolve Links - Copy the data structure of another definition

Resolution must be processed in a specific order to prevent missing dependencies. For example, Line Editor in qllineeditor.json inherits Widget from qlwidget.json, but Widget inherits Box from qlbox.json. It is important that Widget's inheritance of Box get's resolved before Line Editor's inheritance of Widget.

Resolving Inheritance

When files are loaded, they should be analyzed to determine a dependency list which can be used for inheritance resolution ordering.

The following is an incomplete example of how a dependency list from QLayers would look:

Dependency List

No Dependents:

  • qlbox.json
  • qllabel.json
  • qlradiobutton.json

Has Dependents:

  • qlwidget.json:
    • qlbox.json
  • qldialog.json:
    • qlbox.json
    • qllabel.json
    • qlwidget.json
  • qllineeditor.json:
    • qlwidget.json
  • qlslider.json:
    • qlwidget.json

Based on the above dependencies, the files should be resolved in the following order:

  • qlwidget.json
  • qldialog.json
  • qllineeditor.json
  • qlslider.json

Really, in this example, the only important thing to note is that qlwidget.json needs to be resolved first. The other files are resolved after, in any order since none of them depend on each other.

Resolving in a while loop

The list of files that contain dependencies can be continuously iterated over, and the files that have finalized dependencies can get finalized themselves. As the while loop processes, all dependencies should get resolved.

Files that have no dependencies are already considered finalized.

When a definition is finalized, it should be added to the root definition.

Attribute Changes

Create an LAttribute constructor that receives an LJsonValue and handles the new structure rules allowed for defining attributes, such as valuation without requiring an object, type deduction, linking via "L:" prefixed link strings, alternative links, etc.