C++ API Reference¶
This page documents the C++ API for the DS library. The documentation is generated from the C++ source code.
All classes and functions are in the ds namespace.
Headers¶
1 2 3 | |
string_t¶
String handling class. Defined in <ds/string.hh>.
Methods¶
data_size()¶
Get the size of the string data in bytes.
1 | |
head()¶
Get a pointer to the first byte.
1 | |
tail()¶
Get a pointer past the last byte.
1 | |
print()¶
Output the string to a buffer.
1 | |
scan()¶
Read a string from a buffer.
1 | |
variable_t¶
Logical variable class. Defined in <ds/variable.hh>.
Variables represent placeholders that can be unified with other terms.
Methods¶
name()¶
Get the name of the variable (without backtick prefix).
1 | |
data_size()¶
Get the size of the variable data in bytes.
1 | |
head() / tail()¶
Get pointers to the data boundaries.
1 2 | |
print() / scan()¶
Input/output operations.
1 2 | |
item_t¶
Item (constant/functor) class. Defined in <ds/item.hh>.
Items represent atomic values or function symbols.
Methods¶
name()¶
Get the name of the item.
1 | |
data_size()¶
Get the size of the item data in bytes.
1 | |
head() / tail()¶
Get pointers to the data boundaries.
1 2 | |
print() / scan()¶
Input/output operations.
1 2 | |
list_t¶
List class. Defined in <ds/list.hh>.
Lists contain ordered sequences of terms.
Methods¶
length()¶
Get the number of elements in the list.
1 | |
getitem()¶
Get an element by index.
1 | |
data_size()¶
Get the size of the list data in bytes.
1 | |
head() / tail()¶
Get pointers to the data boundaries.
1 2 | |
print() / scan()¶
Input/output operations.
1 2 | |
term_t¶
General term class. Defined in <ds/term.hh>.
A term can be a variable, item, or list.
Enum: term_type_t¶
1 2 3 4 5 6 | |
Methods¶
get_type()¶
Get the type of this term.
1 | |
is_null()¶
Check if the term is null.
1 | |
variable() / item() / list()¶
Get the underlying value as the specific type. Returns nullptr if the term is not of that type.
1 2 3 | |
set_type() / set_null() / set_variable() / set_item() / set_list()¶
Set the term type.
1 2 3 4 5 | |
data_size()¶
Get the size of the term data in bytes.
1 | |
head() / tail()¶
Get pointers to the data boundaries.
1 2 | |
print() / scan()¶
Input/output operations.
1 2 | |
ground()¶
Ground this term using a dictionary to substitute variables.
1 2 | |
match()¶
Match two terms and produce a unification dictionary.
1 2 3 | |
rename()¶
Rename variables by adding prefix and suffix.
1 2 | |
rule_t¶
Logical rule class. Defined in <ds/rule.hh>.
A rule consists of premises and a conclusion.
Methods¶
conclusion()¶
Get the conclusion of the rule.
1 | |
only_conclusion()¶
Get the conclusion only if there are no premises. Returns nullptr otherwise.
1 | |
premises()¶
Get a premise by index.
1 | |
premises_count()¶
Get the number of premises.
1 | |
valid()¶
Check if the rule is valid.
1 | |
data_size()¶
Get the size of the rule data in bytes.
1 | |
head() / tail()¶
Get pointers to the data boundaries.
1 2 | |
print() / scan()¶
Input/output operations.
1 2 | |
ground()¶
Ground this rule using a dictionary.
1 2 3 4 | |
match()¶
Match this rule with a fact.
1 2 | |
rename()¶
Rename variables in this rule.
1 2 | |
search_t¶
Search engine class. Defined in <ds/search.hh>.
Manages a knowledge base and performs logical inference.
Constructor¶
1 | |
Parameters:
limit_size: Maximum size for each stored rule/factbuffer_size: Size of the internal buffer for operations
Methods¶
set_limit_size()¶
Set the maximum rule/fact size.
1 | |
set_buffer_size()¶
Set the internal buffer size.
1 | |
reset()¶
Clear all rules and facts.
1 | |
add()¶
Add a rule or fact from text.
1 | |
execute()¶
Execute one round of inference.
1 | |
Parameters:
callback: Function called for each new inference. Return false to continue, true to stop.
Returns: The number of new inferences generated.
Utility Functions¶
Helper functions in <ds/utility.hh>.
text_to_term()¶
Parse text into a term object.
1 | |
Parameters:
text: The text representation of the termlength: Maximum size for the resulting binary term
Returns: A unique_ptr to the created term, or nullptr if length exceeded.
term_to_text()¶
Convert a term object to text.
1 | |
Parameters:
term: The binary term to convertlength: Maximum size for the resulting text
Returns: A unique_ptr to the text, or nullptr if length exceeded.
text_to_rule()¶
Parse text into a rule object.
1 | |
Parameters:
text: The text representation of the rulelength: Maximum size for the resulting binary rule
Returns: A unique_ptr to the created rule, or nullptr if length exceeded.
rule_to_text()¶
Convert a rule object to text.
1 | |
Parameters:
rule: The binary rule to convertlength: Maximum size for the resulting text
Returns: A unique_ptr to the text, or nullptr if length exceeded.
Complete Example¶
Here's a complete example demonstrating the C++ API:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |