Loading...
Searching...
No Matches
Symbol.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/base/Testable.h>
#include <gtsam/inference/Key.h>
#include <boost/serialization/nvp.hpp>
#include <cstdint>
#include <functional>
namespace gtsam {
class GTSAM_EXPORT Symbol {
protected:
unsigned char c_;
std::uint64_t j_;
public:
Symbol() :
c_(0), j_(0) {
}
Symbol(const Symbol& key) :
c_(key.c_), j_(key.j_) {
}
Symbol(unsigned char c, std::uint64_t j) :
c_(c), j_(j) {
}
Symbol(Key key);
Key key() const;
operator Key() const { return key(); }
void print(const std::string& s = "") const;
bool equals(const Symbol& expected, double tol = 0.0) const;
unsigned char chr() const {
return c_;
}
std::uint64_t index() const {
return j_;
}
operator std::string() const;
std::string string() const { return std::string(*this); };
bool operator<(const Symbol& comp) const {
return c_ < comp.c_ || (comp.c_ == c_ && j_ < comp.j_);
}
bool operator==(const Symbol& comp) const {
return comp.c_ == c_ && comp.j_ == j_;
}
bool operator==(Key comp) const {
return comp == (Key)(*this);
}
bool operator!=(const Symbol& comp) const {
return comp.c_ != c_ || comp.j_ != j_;
}
bool operator!=(Key comp) const {
return comp != (Key)(*this);
}
static std::function<bool(Key)> ChrTest(unsigned char c);
GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const Symbol &);
private:
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_NVP(c_);
ar & BOOST_SERIALIZATION_NVP(j_);
}
};
inline Key symbol(unsigned char c, std::uint64_t j) { return (Key)Symbol(c,j); }
inline unsigned char symbolChr(Key key) { return Symbol(key).chr(); }
inline std::uint64_t symbolIndex(Key key) { return Symbol(key).index(); }
namespace symbol_shorthand {
inline Key A(std::uint64_t j) { return Symbol('a', j); }
inline Key B(std::uint64_t j) { return Symbol('b', j); }
inline Key C(std::uint64_t j) { return Symbol('c', j); }
inline Key D(std::uint64_t j) { return Symbol('d', j); }
inline Key E(std::uint64_t j) { return Symbol('e', j); }
inline Key F(std::uint64_t j) { return Symbol('f', j); }
inline Key G(std::uint64_t j) { return Symbol('g', j); }
inline Key H(std::uint64_t j) { return Symbol('h', j); }
inline Key I(std::uint64_t j) { return Symbol('i', j); }
inline Key J(std::uint64_t j) { return Symbol('j', j); }
inline Key K(std::uint64_t j) { return Symbol('k', j); }
inline Key L(std::uint64_t j) { return Symbol('l', j); }
inline Key M(std::uint64_t j) { return Symbol('m', j); }
inline Key N(std::uint64_t j) { return Symbol('n', j); }
inline Key O(std::uint64_t j) { return Symbol('o', j); }
inline Key P(std::uint64_t j) { return Symbol('p', j); }
inline Key Q(std::uint64_t j) { return Symbol('q', j); }
inline Key R(std::uint64_t j) { return Symbol('r', j); }
inline Key S(std::uint64_t j) { return Symbol('s', j); }
inline Key T(std::uint64_t j) { return Symbol('t', j); }
inline Key U(std::uint64_t j) { return Symbol('u', j); }
inline Key V(std::uint64_t j) { return Symbol('v', j); }
inline Key W(std::uint64_t j) { return Symbol('w', j); }
inline Key X(std::uint64_t j) { return Symbol('x', j); }
inline Key Y(std::uint64_t j) { return Symbol('y', j); }
inline Key Z(std::uint64_t j) { return Symbol('z', j); }
}
class SymbolGenerator {
const unsigned char c_;
public:
constexpr SymbolGenerator(const unsigned char c) : c_(c) {}
Symbol operator()(const std::uint64_t j) const { return Symbol(c_, j); }
constexpr unsigned char chr() const { return c_; }
};
template<> struct traits<Symbol> : public Testable<Symbol> {};
} // \ namespace gtsam
Testable.h
Concept check for values that can be used in unit tests.
Key.h
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::symbolIndex
std::uint64_t symbolIndex(Key key)
Return the index portion of a symbol key.
Definition Symbol.h:141
gtsam::symbol
Key symbol(unsigned char c, std::uint64_t j)
Create a symbol key from a character and index, i.e.
Definition Symbol.h:135
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:156
gtsam::symbolChr
unsigned char symbolChr(Key key)
Return the character portion of a symbol key.
Definition Symbol.h:138
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:100
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::Symbol
Character and index key used to refer to variables.
Definition Symbol.h:35
gtsam::Symbol::chr
unsigned char chr() const
Retrieve key character.
Definition Symbol.h:73
gtsam::Symbol::operator==
bool operator==(Key comp) const
Comparison for use in maps.
Definition Symbol.h:99
gtsam::Symbol::operator!=
bool operator!=(const Symbol &comp) const
Comparison for use in maps.
Definition Symbol.h:104
gtsam::Symbol::operator==
bool operator==(const Symbol &comp) const
Comparison for use in maps.
Definition Symbol.h:94
gtsam::Symbol::key
Key key() const
return Key (integer) representation
Definition Symbol.cpp:41
gtsam::Symbol::Symbol
Symbol(const Symbol &key)
Copy constructor.
Definition Symbol.h:48
gtsam::Symbol::Symbol
Symbol()
Default constructor.
Definition Symbol.h:43
gtsam::Symbol::Symbol
Symbol(unsigned char c, std::uint64_t j)
Constructor.
Definition Symbol.h:53
gtsam::Symbol::operator<
bool operator<(const Symbol &comp) const
Comparison for use in maps.
Definition Symbol.h:89
gtsam::Symbol::index
std::uint64_t index() const
Retrieve key index.
Definition Symbol.h:78
gtsam::Symbol::string
std::string string() const
Return string representation of the key.
Definition Symbol.h:86
gtsam::Symbol::operator!=
bool operator!=(Key comp) const
Comparison for use in maps.
Definition Symbol.h:109