Class ApiBufferMultiCondition

Class Documentation

class ApiBufferMultiCondition

This class defines a tree structure for evaluating multiple logical conditions.

Public Functions

ApiBufferMultiCondition()
int AddGateNode(ApiBufferConditionNodeType::T type, int parent = -1)

Adds a gate node (non-leaf) to the multi-condition.

Remark

This function returns -1 if:

  • The tree has reached the maximum number of nodes.

  • The node type is Leaf (use AddLeafNode for leaf nodes).

  • The specified parent node is already a leaf.

Parameters:
  • type[in] The type of the gate node (And, Or, Not, etc.).

  • parent[in] Optional. The index of the parent node. If -1, the new node is left unconnected.

Returns:

Index of the newly added node on success; -1 on failure.

int AddLeafNode(ApiBufferCondition *condition, int parent = -1)

Adds a leaf node (condition) to the multi-condition.

Remark

This function returns -1 if:

  • The tree has reached the maximum number of nodes.

  • The specified parent node is already a leaf.

Parameters:
  • condition[in] A pointer to the condition associated with this leaf node.

  • parent[in] Optional. The index of the parent node. If -1, the new node is left unconnected.

Returns:

Index of the newly added node on success; -1 on failure.

bool ConnectParentChild(int parent, int child)

Connects two existing nodes as parent and child in the multi-condition tree.

Remark

This function returns false if:

  • Either index is out of range.

  • The parent node already has the maximum number of children.

  • The parent node is a leaf and cannot have children.

  • The child node is already connected to another parent.

  • The connection would create a cycle in the tree (e.g., the child is an ancestor of the parent).

Parameters:
  • parent[in] Index of the parent node.

  • child[in] Index of the child node.

Returns:

true if the connection is successful; false otherwise.

int CheckValidity()

Validates the multi-condition.

Checks that:

  • There are no cycles in the tree

  • There is exactly one root node (parent == -1)

  • Gate nodes have at least one child

  • Leaf nodes have no children

  • Each leaf condition is valid

Remark

This function returns:

Returns:

ErrorCode::None if the tree is valid; otherwise, a specific error code.

void Clear()

Clears the multi-condition and resets its state.

Remark

Resets all nodes, sets rootIdx to -1, and nodeCount to 0.

Public Members

int rootIdx

Index of the root node in the tree.

int nodeCount

Total number of nodes currently in the tree.

ApiBufferConditionNode nodes[constants::maxConditionTreeNode]

Preallocated array of all condition nodes in the tree.