Key Expression
-
class KeyExpr : public zenoh::Owned<::z_owned_keyexpr_t>
A Zenoh key expression .
Key expression can be registered in the
zenoh::Sessionobject withzenoh::Session::declare_keyexprmethod. The unique id is internally assinged to the key expression string in this case. This allows to reduce bandwith usage when transporting key expressions.Methods
Get underlying key expression string.
-
typedef ::z_keyexpr_intersection_level_t IntersectionLevel
Intersection level of 2 key expressions.
Values:
Z_KEYEXPR_INTERSECTION_LEVEL_DISJOINT: 2 key expression do not intersect.
Z_KEYEXPR_INTERSECTION_LEVEL_INTERSECTS: 2 key expressions intersect, i.e. there exists at least one key that is included by both.
Z_KEYEXPR_INTERSECTION_LEVEL_INCLUDES: First key expression is the superset of second one.
Z_KEYEXPR_INTERSECTION_LEVEL_EQUALS: 2 key expressions are equal.
Warning
This API has been marked as unstable: it works as advertised, but it may be changed in a future release.
-
inline bool includes(const KeyExpr &other)
Check if a given
KeyExprincludes the other.- Parameters:
other – the
KeyExprto compare with- Returns:
trueif current key expression includesother, i.e. contains every key belonging to theother.
-
inline KeyExpr concat(std::string_view s, ZResult *err = nullptr) const
Construct new key expression by concatenating the current one with a string.
- Parameters:
s – a string to concatenate with the key expression.
err – if not null, the result code will be written to this location, otherwise ZException exception will be thrown in case of error.
- Returns:
a new key expression.
-
inline KeyExpr join(const KeyExpr &other, ZResult *err = nullptr) const
Construct new key expression by joining it with another one.
- Parameters:
other – the
KeyExprto append.err – if not null, the result code will be written to this location, otherwise ZException exception will be thrown in case of error.
-
inline bool intersects(const KeyExpr &other) const
Check if 2 key expressions intersect.
- Returns:
trueif there is at least one non-empty key that is contained in both key expressions,falseotherwise.
-
inline IntersectionLevel relation_to(const KeyExpr &other)
Returns the relation between
thisandotherfromthis’s point of view.
-
static inline bool is_canon(std::string_view s)
Check if the string represents a canonical key expression.
Constructors
-
inline KeyExpr(std::string_view key_expr, bool autocanonize = true, ZResult *err = nullptr)
Create a new instance from a string.
- Parameters:
key_expr – string representing key expression.
autocanonize – if
truethe key_expr will be autocanonized, prior to constructing key expression.err – if not null, the result code will be written to this location, otherwise ZException exception will be thrown in case of error.
-
inline KeyExpr(const std::string &key_expr, bool autocanonize = true, ZResult *err = nullptr)
Create a new instance from a string.
- Parameters:
key_expr – string representing key expression.
autocanonize – if
truethe key_expr will be autocanonized, prior to constructing key expression.err – if not null, the result code will be written to this location, otherwise ZException exception will be thrown in case of error.
-
inline KeyExpr(const char *key_expr, bool autocanonize = true, ZResult *err = nullptr)
Create a new instance from a null-terminated string.
- Parameters:
key_expr – null-terminated string representing key expression.
autocanonize – if
truethe key_expr will be autocanonized, prior to constructing key expression.err – if not null, the result code will be written to this location, otherwise ZException exception will be thrown in case of error.
Operators
-
inline bool operator==(std::string_view other) const
Key expression to string equality relation.
- Parameters:
other – a string to compare with.
- Returns:
trueif the key expression string representation is equal to other,falseotherwise.
-
inline bool operator!=(std::string_view other) const
Key expression to string inequality relation.
- Parameters:
other – a string to compare with.
- Returns:
falseif the key expression string representation is equal to other,trueotherwise.
-
inline bool operator==(const std::string &other) const
Key expression to string equality relation.
- Parameters:
other – a string to compare with.
- Returns:
trueif the key expression string representation is equal to other,falseotherwise.
-
inline bool operator!=(const std::string &other) const
Key expression to string inequality relation.
- Parameters:
other – a string to compare with.
- Returns:
falseif the key expression string representation is equal to other,trueotherwise.
-
inline bool operator==(const char *other) const
Key expression to string equality relation.
- Parameters:
other – a null-terminated string to compare with.
- Returns:
trueif the key expression string representation is equal to other,falseotherwise.
-
inline bool operator!=(const char *other) const
Key expression to string inequality relation.
- Parameters:
other – a null-terminated string to compare with.
- Returns:
falseif the key expression string representation is equal to other,trueotherwise.
-
inline bool operator==(const KeyExpr &other) const
Equality relation.
- Parameters:
other – a key expression to compare with.
- Returns:
trueif both key expressions are equal (i.e. they represent the same set of resources),falseotherwise.
-
typedef ::z_keyexpr_intersection_level_t IntersectionLevel