The Xc++ language allows for reflecting free functions
using $function
.
For example the following is a $function declaration and typically appears in a public header:
// Function declaration in public header
$function+ void f();
The following is a $function definition and typically appears in a cpp file:
// Function definition in cpp file
$function+ void f()
{
}
The +
is called the public modifier and means that the free function is
public - so it is reflected and exported by the library.
Normally a $function
in a public header of a library will use the public modifier,
therefore Xcpp generates a warning if a $function
is declared in a public header without the +
.
When a $function
is reflected an instance of a
ReflectedGlobalFunction is registered in the
ReflectedGlobalFunction registry.
The reflection information is sufficient to allow the cxPython library to call a registered $function
from python.
<<extern>>
allows a $function
to be reflected and registered even though
it is implemented in another library.
In that case there will be a $function declaration using <<extern>>
, but there will be
no $function definition (i.e. with a function body).
$function+ <<extern>> TcpMsgServer* CreateTcpMsgServer(
IoContextPool* pool,
EProtocol protocol,
int32 port,
bool reuse_addr,
ITcpMsgEndPoint& ep,
const TcpMsgSessionSettings& sessionSettings);
For example this is needed for the free functions CreateIoContextPool()
, CreateTcpMsgServer()
and CreateTcpMsgClient()
which are implemented in the cxMessage2 library which is not an xcpp project.
Inlined $functions are supported. Typically an inlined function appears in a public header of a library. It both declares and defines the function. It is reflected and registered in the normal way, however it is available as an inlined free function in C++.
The following is an example which appears in the ceda-core header IPersistable.h
$function+ inline OID GetOid(ptr<const IPersistable> po)
{
return po->GetPersistObjState().m_oid;
}
A $function declaration supports default parameters. For example the following appears in the ceda-core header IPersistStore.h
$function+ PSpace* OpenPSpace(
PersistStore* ps,
ConstStringZ name,
EOpenMode openMode = OM_OPEN_ALWAYS,
CSpace* cspace = nullptr);