CPP API class rl3::Factsheet
Contents
rl3::Factsheet class overview
- Description
- The class possesses members for management of Factsheet objects by means of:
- saving/ loading factsheets;
- asserting/ retracting data to/ from factsheets;
- numerous accessor functions to get data from factsheets.
- The class also possesses functions to create iterators for cycling through the factsheet (either by fact label or by fact tree path).
- Remarks
- For iterator functions, please refer to rl3::FactIterator or rl3::FactPathIterator classes.
constructor
rl3::Factsheet object can be created with rl3::BaseEngine factory only (refer to create_factsheet
and load_factsheet
functions in rl3::RL3Engine or rl3::KMLEngine derived from the rl3::BaseEngine class)
destructor
~Factsheet();
Destroy a Factsheet object.
assert_fact functions
void assert_fact(std::shared_ptr<rl3::Fact> fact);
Assert a fact (either simple or based on other facts/ factsheets) to a factsheet.
To use the function, a new Fact object should be created first.
TBD: Clarify whether facts are deleted after having been asserted or not.
Note that the rl3_factsheet_assert_fact function can not delete facts after they are asserted.
Therefore, to avoid memory leaks it is required that the facts are deleted by the rl3_fact_destroy function after assertion if not further needed elsewhere |
fact: | a shared pointer to a fact object |
Returns: | nothing |
void assert_fact(const UnicodeString& label, const UnicodeString& value, double weight = 1.0);
Assert a simple fact to a factsheet with omitting the creation of a Fact object.
The label
and value
parameters in function definition are of unicode string type.
label: | a reference to the name (label) of a fact |
value: | a reference to fact value |
weight: | fact weight |
Returns: | nothing |
void assert_fact(const std::string& label, const std::string& value, double weight = 1.0);
Assert a simple fact to a factsheet with omitting the creation of a Fact object.
The label
and value
parameters in function definition are of UTF-8 string type.
label: | a reference to the name (label) of a fact |
value: | a reference to fact value |
weight: | fact weight |
Returns: | nothing |
void assert_fact(const char* label, const char* value, double weight = 1.0) {assert_fact(std::string(label), std::string(value), weight);}
Assert a simple fact to a factsheet with omitting the creation of a Fact object.
The label
and value
parameters in function definition are character pointers.
label: | a name (label) of a fact |
value: | fact value |
weight: | fact weight |
Returns: | nothing |
retract_fact functions
void retract_fact(std::shared_ptr<rl3::FactIterator> iterator);
Remove a fact from a factsheet.
iterator: | a shared pointer to an iterator object |
Returns: | nothing |
void retract_facts(const UnicodeString& label);
Remove multiple facts from a factsheet by label.
The label
parameter in function definition is of unicode string type.
label: | a reference to fact label |
Returns: | nothing |
void retract_facts(const std::string& label);
Remove multiple facts from a factsheet by label.
The label
parameter in function definition is of UTF-8 string type.
label: | a reference to fact label |
Returns: | nothing |
void retract_facts(const char* label) {retract_facts(std::string(label));}
Remove multiple facts from a factsheet by label.
The label
parameter in function definition is a character pointer.
label: | a pointer to the first character in the fact name (label) |
Returns: | nothing |
has_fact functions
bool has_fact(const UnicodeString& label);
Check whether a fact is in the factsheet.
The label
parameter in function definition is of unicode string type.
label: | a reference to fact label |
Returns: | boolean |
bool has_fact(const std::string& label);
Check whether a fact is in the factsheet.
The label
parameter in function definition is of UTF-8 string type.
label: | a reference to fact label |
Returns: | boolean |
bool has_fact(const char* label) {return has_fact(std::string(label));}
Check whether a fact is in the factsheet.
The label
parameter in function definition is a character pointer.
label: | a pointer to the first character in the fact name (label) |
Returns: | boolean |
get_facts_count functions
unsigned int get_facts_count(const UnicodeString& label);
Get the fact count in a factsheet by label.
The label
parameter in function definition is of unicode string type.
label: | a reference to fact label |
Returns: | unsigned integer |
unsigned int get_facts_count(const std::string& label);
Get the fact count in a factsheet by label.
The label
parameter in function definition is of UTF-8 string type.
label: | a reference to fact label |
Returns: | unsigned integer |
unsigned int get_facts_count(const char* label) {return get_facts_count(std::string(label));}
Get the fact count in a factsheet by label.
The label
parameter in function definition is a character pointer.
label: | a pointer to the first character in the fact name (label) |
Returns: | unsigned integer |
get_fact_iterator functions
std::shared_ptr<rl3::FactIterator> get_fact_iterator();
Create an iterator to cycle through the facts.
Returns: | a shared pointer to a FactIterator object |
std::shared_ptr<rl3::FactIterator> get_fact_iterator(const UnicodeString& label);
Create an iterator to cycle through the facts with a defined label in a factsheet.
The label
parameter in function definition is of unicode string type.
label: | a reference to fact label |
Returns: | a shared pointer to a FactIterator object |
std::shared_ptr<rl3::FactIterator> get_fact_iterator(const std::string& label);
Create an iterator to cycle through the facts with a defined label in a factsheet.
The label
parameter in function definition is of UTF-8 string type.
label: | a reference to fact label |
Returns: | a shared pointer to a FactIterator object |
std::shared_ptr<rl3::FactIterator> get_fact_iterator(const char* label) {return get_fact_iterator(std::string(label));}
Create an iterator to cycle through the facts with a defined label in a factsheet.
The label
parameter in function definition is a character pointer.
label: | a pointer to the first character in the fact name (label) |
Returns: | a shared pointer to a FactIterator object |
get_factpath_iterator functions
std::shared_ptr<rl3::FactPathIterator> get_factpath_iterator(const UnicodeString& path);
Create an iterator that can go down the fact tree by path.
The path
parameter in function definition is of unicode string type.
path: | a reference to a fact tree path |
Returns: | a shared pointer to a FactPathIterator object |
std::shared_ptr<rl3::FactPathIterator> get_factpath_iterator(const std::string& path);
Create an iterator that can go down the fact tree by path.
The path
parameter in function definition is of UTF-8 string type.
path: | a reference to a fact tree path |
Returns: | a shared pointer to a FactPathIterator object |
std::shared_ptr<rl3::FactPathIterator> get_factpath_iterator(const char* path) {return get_factpath_iterator(std::string(path));}
Create an iterator that can go down the fact tree by path.
The path
parameter in function definition is a character pointer.
path: | a pointer to the first character in the fact tree path |
Returns: | a shared pointer to a FactPathIterator object |
to_json
string to_json(std::shared_ptr<rl3::SharedText> root_text = NULL, bool include_text = true);
Save Factsheet as JSON string.
root_text: | NULL if factsheet should be considered as independent / self-containing structure. Default is NULL .
|
include_text | true if text field should be included in the output; false otherwise. Default is true .
|
Returns: | JSON string. |