UPF recognizes several pragmas in IDL definitions in addition to standard pragma version:
UPF has one-to-many relation between interfaces and classes -- there may be many classes that implement given interface. This is very useful for plugins etc., but it can be inconvenient in some situations.
A typical example of such situation is UPF's upf.IManager
interface. There can only be one implementation of upf.IManager
, that being upf.impl.Manager
. UPF provides a way for you to inform it that some interface will have only one implementation: pragma single_impl. Pragma's syntax is pragma single_impl <interface_name> <implementation_name>
. See an example:
module foo { interface IBar : upf::IObject { ... }; #pragma single_impl IBar MyBar };
Note that the pragma must follow immediately after the interface it is used with!
UPF can generate more programmer-friendly code if you provided the pragma. In C++, you'd have to explicitly pass "MyBar" name to upf::create without the pragma, as in this example:
Ptr<foo::IBar> = upf::create("MyBar");
This is of course error-prone because upf::create's string argument can't be checked for type correctness. You can now use following syntax instead (note that MyBar doesn't occur anywhere on the line):
Ptr<foo::IBar> = upf::create<foo::IBar>();
This only works with single_impl
interfaces, of course.
This pragma only affect C++ headers generator. It specifies header file(s) to include in generated .h file in addition to these included automatically. This is mainly useful together with types defined as native in IDL description.
// IDL file: my.idl #pragma cxx_include "my_defs.h" #pragma cxx_include "my_native_type.h" native MyNativeType; ...interface definitions follow...