Meta programming
There is a code generator that allows to create some common code by using metadata. It runs before code compilation and generate files with a name <header_name>.generated.<header_extension>
.
For example if you run it for a file text.h
it would produce a file text.generated.h
To make a metadata for you code you can use this set of macros: * SC_CLASS - allows you to specify metadata for a class; * SC_GENERATED_BODY - macros that need to be used after SC_CLASS, because it would be replaced in during compilation time with generated declaration for this class; * SC_PROPERTY - allows to specify metadata for members of a class (including static members).
You should to specify SC_CLASS and SC_GENERATED_BODY for all child classes of ScObject
Syntax
There is a syntax rule that used for a metadata specification:
[<PropertyName> [ (<PropertyValue>, <PropertyValue>, ...) ] ], …
For example:
SC_CLASS(Agent, CmdClass("command_update_power_usage"))
SC_CLASS(CmdClass("command_generate_text_from_template"), Agent)
SC_PROPERTY(Keynode("nrel_real_energy_usage"), ForceCreate)
SC_CLASS(Agent, Event(ActionManager::msActionPeriodical, SC_EVENT_ADD_OUTPUT_ARC))
You should to use SC_CLASS and SC_GENERATED_BODY in class declaration:
class AWhoAreYouAgent : public ScAgentAction
{
SC_CLASS(Agent, CmdClass("command_who_are_you"))
SC_GENERATED_BODY()
};
Classes
Table of available properties of class metadata (SC_CLASS):
Property | Description |
---|---|
Agent | Parent class: ScAgent and all childs
You should always use it for all ScAgent child classes |
CmdClass | Determine system identifier of command class that implemented by sc-agent.
Parent class: ScAgentAction Arguments:
|
Event | Specify condition to start sc-agent implementation. Parent class: ScAgent Arguments:
|
LoadOrder | Specify order (priority) of module loading. Can be used just in ScModule child classes.
Parent class: ScModule Arguments:
|
Members
Table of available properties of class members metadata (SC_PROPERTY):
Property | Description |
---|---|
Keynode |
Arguments:
You can use this property just for members that has ScAddr type.
|
Template |
Arguments:
You can use this property just for members that has ScTemplate type.
|
ForceCreate |
Arguments:
Used just with Keynode property. Using of this property force sc-element creation, if it didn't found by system identifier.
|
FAQ
- How to include one
MyObject
intoOtherObject
/* In CPP file you should include header file for object, that implemented in this file * For example in file MyObject.cpp we should make order */ #include "otherObject.hpp" #include "otherObject2.hpp" ... #include "myObject.hpp" // other includes (that doesn't contains ScObject derived classes) ... // Implementation ...