Key Expression

class KeyExpr : public zenoh::Owned<::z_owned_keyexpr_t>

A Zenoh key expression .

Key expression can be registered in the zenoh::Session object with zenoh::Session::declare_keyexpr method. 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 KeyExpr includes the other.

Parameters:

other – the KeyExpr to compare with

Returns:

true if current key expression includes other, i.e. contains every key belonging to the other.

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 KeyExpr to 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:

true if there is at least one non-empty key that is contained in both key expressions, false otherwise.

inline IntersectionLevel relation_to(const KeyExpr &other)

Returns the relation between this and other from this’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 true the 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 true the 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 true the 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 KeyExpr &other)

Copy constructor.

Operators

inline bool operator==(std::string_view other) const

Key expression to string equality relation.

Parameters:

other – a string to compare with.

Returns:

true if the key expression string representation is equal to other, false otherwise.

inline bool operator!=(std::string_view other) const

Key expression to string inequality relation.

Parameters:

other – a string to compare with.

Returns:

false if the key expression string representation is equal to other, true otherwise.

inline bool operator==(const std::string &other) const

Key expression to string equality relation.

Parameters:

other – a string to compare with.

Returns:

true if the key expression string representation is equal to other, false otherwise.

inline bool operator!=(const std::string &other) const

Key expression to string inequality relation.

Parameters:

other – a string to compare with.

Returns:

false if the key expression string representation is equal to other, true otherwise.

inline bool operator==(const char *other) const

Key expression to string equality relation.

Parameters:

other – a null-terminated string to compare with.

Returns:

true if the key expression string representation is equal to other, false otherwise.

inline bool operator!=(const char *other) const

Key expression to string inequality relation.

Parameters:

other – a null-terminated string to compare with.

Returns:

false if the key expression string representation is equal to other, true otherwise.

inline bool operator==(const KeyExpr &other) const

Equality relation.

Parameters:

other – a key expression to compare with.

Returns:

true if both key expressions are equal (i.e. they represent the same set of resources), false otherwise.

inline bool operator!=(const KeyExpr &other) const

Inequality relation.

Parameters:

other – a key expression to compare with.

Returns:

false if both key expressions are equal (i.e. they represent the same set of resources), true otherwise.

inline KeyExpr &operator=(const KeyExpr &other)

Assignment operator.