Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
doc:logging:tutorials-cpp [2014/09/09 09:35] – Object references winkler | doc:logging:tutorials-cpp [2014/09/19 15:13] – Added info on registering custom OWL namespaces winkler | ||
---|---|---|---|
Line 36: | Line 36: | ||
wstool set beliefstate_client --git https:// | wstool set beliefstate_client --git https:// | ||
- | After doing a wstool update to make sure all library checkouts are up | + | After doing a '' |
to date, make sure that everything compiles just fine: | to date, make sure that everything compiles just fine: | ||
Line 63: | Line 63: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include < | ||
using namespace beliefstate_client; | using namespace beliefstate_client; | ||
Line 101: | Line 102: | ||
| | ||
// Open a top-level context (level 0) | // Open a top-level context (level 0) | ||
- | | + | |
| | ||
// Open a sub-context (level 1) | // Open a sub-context (level 1) | ||
- | | + | |
- | // End the sub-context from level 1 | + | |
- | bscl-> | + | |
- | | + | |
// Open another sub-context (level 1) | // Open another sub-context (level 1) | ||
- | | + | |
+ | |||
+ | // Close the first sub-context | ||
+ | ctxCupOnTable-> | ||
| | ||
- | // Open yet another sub-context (level 2) | + | // Close the second |
- | int nContextID_3 = bscl-> | + | |
- | // End the sub-context from level 2 | + | |
- | bscl-> | + | |
- | + | ||
- | // End the sub-context | + | |
- | | + | |
| | ||
// End the top-level context | // End the top-level context | ||
- | | + | |
| | ||
// Actual logging ends here. | // Actual logging ends here. | ||
Line 126: | Line 123: | ||
The logging result of this program is a nested tree with two branches | The logging result of this program is a nested tree with two branches | ||
- | from the top-level node, one with depth 1, and one with depth 2. | + | from the top-level node. The logged circumstances here could be that a cup that formerly sat on a table in a room was first removed from the table (ending the '' |
+ | |||
+ | Contexts can be hierarchically nested, or can be concatenated concurrently. A good practice is to always have one main context from which all other contexts derive. Don't create multiple contexts using '' | ||
To export the logged tree now, we add another call from inside the | To export the logged tree now, we add another call from inside the | ||
Line 145: | Line 144: | ||
generation. | generation. | ||
+ | A resulting PDF could then look like this: | ||
+ | {{ : | ||
==== Non-Default Contexts ==== | ==== Non-Default Contexts ==== | ||
- | To override default-parameters, | + | To override default-parameters, |
* the start and end timestamps for the context timepoints, and | * the start and end timestamps for the context timepoints, and | ||
Line 156: | Line 156: | ||
<code pseudo> | <code pseudo> | ||
- | int startContext(context-name, | + | Context* Context::startContext(context-name, |
</ | </ | ||
So the time point noted in the resulting log-tree can be annotated with a custom timepoint (for non-realtime logging uses). If this parameter is omitted, the current Unix time on the system running the Beliefstate logging system is used. | So the time point noted in the resulting log-tree can be annotated with a custom timepoint (for non-realtime logging uses). If this parameter is omitted, the current Unix time on the system running the Beliefstate logging system is used. | ||
- | The same accounts for the '' | + | The same accounts for the '' |
<code pseudo> | <code pseudo> | ||
- | int endContext(context-name, | + | void Context:: |
</ | </ | ||
The success flag is by default set to '' | The success flag is by default set to '' | ||
Line 172: | Line 172: | ||
<code pseudo> | <code pseudo> | ||
- | int startContext(context-name, | + | Context* Context::startContext(context-name, |
</ | </ | ||
Line 187: | Line 187: | ||
In you C++-program, | In you C++-program, | ||
<code cpp> | <code cpp> | ||
- | int nCtx = bscl-> | + | Context* ctxContext |
- | bscl-> | + | ctxContext-> |
</ | </ | ||
- | Of course, for real-time purposes (or if you don't care about the timestamps), | + | Of course, for real-time purposes (or if you don't care about the timestamps), |
=== Issueing Discrete Events === | === Issueing Discrete Events === | ||
- | When your application requires the issuance of discrete, momentarily events you can use the convenience function discreteEvent: | + | When your application requires the issuance of discrete, momentarily events you can use the convenience function |
<code pseudo> | <code pseudo> | ||
- | int discreteEvent(event-name, | + | void Context::discreteEvent(event-name, |
</ | </ | ||
Line 213: | Line 213: | ||
should be added to the current context. To achieve this, in your program, call these lines while you are in the appropriate context: | should be added to the current context. To achieve this, in your program, call these lines while you are in the appropriate context: | ||
<code cpp> | <code cpp> | ||
- | bscl-> | + | ctxContext-> |
- | bscl-> | + | ctxContext-> |
</ | </ | ||
The resulting '' | The resulting '' | ||
Line 258: | Line 258: | ||
< | < | ||
< | < | ||
- | < | + | < |
- | < | + | < |
</ | </ | ||
</ | </ | ||
This is achieved by using the following, simple code: | This is achieved by using the following, simple code: | ||
<code cpp> | <code cpp> | ||
- | int nID = bscl-> | + | Context* ctxInCtct |
Object* objCup = new Object("& | Object* objCup = new Object("& | ||
- | bscl-> | + | ctxInCtct-> |
Object* objTable = new Object("& | Object* objTable = new Object("& | ||
- | bscl-> | + | ctxInCtct-> |
delete objCup; | delete objCup; | ||
delete objTable; | delete objTable; | ||
- | bscl->endContext(nID); | + | ctxInCtct->end(); |
</ | </ | ||
Additionally, | Additionally, | ||
<code xml> | <code xml> | ||
- | < | + | < |
< | < | ||
< | < | ||
</ | </ | ||
- | < | + | < |
< | < | ||
< | < | ||
Line 295: | Line 295: | ||
If they are left out, the object will be of type ''& | If they are left out, the object will be of type ''& | ||
<code pseudo> | <code pseudo> | ||
- | addObject(object, | + | void Context::addObject(object, |
</ | </ | ||
produces the actual addition of the object reference to the current context (and creation of the object individual). The optional '' | produces the actual addition of the object reference to the current context (and creation of the object individual). The optional '' | ||
+ | |||
+ | |||
+ | === Registering custom OWL namespaces === | ||
+ | |||
+ | When using custom namespaces in the entity class definitions, | ||
+ | <code cpp> | ||
+ | bscl-> | ||
+ | </ | ||
+ | with both parameters representing your use-case, of course. | ||
+ | |||
+ | Custom namespaces can therefore be registered by calling | ||
+ | `void BeliefstateClient:: | ||
+ | where the shortcut is the short version of the namespace, i.e. `sim`, and the IRI is the actual URL you want to have associated. | ||
+ | ==== Sample Program ==== | ||
+ | |||
+ | A complete sample program depicting the '' |