diff --git a/gtsam/inference/EdgeKey.cpp b/gtsam/inference/EdgeKey.cpp index d44f7a2a2..f8caf8ce1 100644 --- a/gtsam/inference/EdgeKey.cpp +++ b/gtsam/inference/EdgeKey.cpp @@ -20,9 +20,12 @@ namespace gtsam { -// Output stream operator implementation +EdgeKey::operator std::string() const { + return "{" + std::to_string(i_) + ", " + std::to_string(j_) + "}"; +} + GTSAM_EXPORT std::ostream& operator<<(std::ostream& os, const EdgeKey& key) { - os << "{" << key.i() << ", " << key.j() << "}"; + os << (std::string)key; return os; } diff --git a/gtsam/inference/EdgeKey.h b/gtsam/inference/EdgeKey.h index 13de55f9e..bf1bf6030 100644 --- a/gtsam/inference/EdgeKey.h +++ b/gtsam/inference/EdgeKey.h @@ -37,6 +37,10 @@ class GTSAM_EXPORT EdgeKey { /// Constructor EdgeKey(std::uint32_t i, std::uint32_t j) : i_(i), j_(j) {} + EdgeKey(Key key) + : i_(static_cast(key >> 32)), + j_(static_cast(key)) {} + /// @} /// @name API /// @{ @@ -50,6 +54,9 @@ class GTSAM_EXPORT EdgeKey { /// Retrieve low 32 bits inline std::uint32_t j() const { return j_; } + /** Create a string from the key */ + operator std::string() const; + /// Output stream operator friend GTSAM_EXPORT std::ostream& operator<<(std::ostream&, const EdgeKey&);