inference/Symbol.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 #pragma once
20 
21 #include <gtsam/base/Testable.h>
22 #include <gtsam/inference/Key.h>
23 
24 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
25 #include <boost/serialization/nvp.hpp>
26 #endif
27 #include <cstdint>
28 #include <functional>
29 
30 namespace gtsam {
31 
37 class GTSAM_EXPORT Symbol {
38 protected:
39  unsigned char c_;
41 
42 public:
43 
45  Symbol() :
46  c_(0), j_(0) {
47  }
48 
50  Symbol(const Symbol& key) :
51  c_(key.c_), j_(key.j_) {
52  }
53 
55  Symbol(unsigned char c, std::uint64_t j) :
56  c_(c), j_(j) {
57  }
58 
60  Symbol(Key key);
61 
63  Key key() const;
64 
66  operator Key() const { return key(); }
67 
69  void print(const std::string& s = "") const;
70 
72  bool equals(const Symbol& expected, double tol = 0.0) const;
73 
75  unsigned char chr() const {
76  return c_;
77  }
78 
80  std::uint64_t index() const {
81  return j_;
82  }
83 
85  operator std::string() const;
86 
88  std::string string() const { return std::string(*this); }
89 
91  bool operator<(const Symbol& comp) const {
92  return c_ < comp.c_ || (comp.c_ == c_ && j_ < comp.j_);
93  }
94 
96  bool operator==(const Symbol& comp) const {
97  return comp.c_ == c_ && comp.j_ == j_;
98  }
99 
101  bool operator==(Key comp) const {
102  return comp == (Key)(*this);
103  }
104 
106  bool operator!=(const Symbol& comp) const {
107  return comp.c_ != c_ || comp.j_ != j_;
108  }
109 
111  bool operator!=(Key comp) const {
112  return comp != (Key)(*this);
113  }
114 
120  static std::function<bool(Key)> ChrTest(unsigned char c);
121 
123  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const Symbol &);
124 
125 private:
126 
127 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
128 
129  friend class boost::serialization::access;
130  template<class ARCHIVE>
131  void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
132  ar & BOOST_SERIALIZATION_NVP(c_);
133  ar & BOOST_SERIALIZATION_NVP(j_);
134  }
135 #endif
136 };
137 
139 inline Key symbol(unsigned char c, std::uint64_t j) { return (Key)Symbol(c,j); }
140 
142 inline unsigned char symbolChr(Key key) { return Symbol(key).chr(); }
143 
146 
147 namespace symbol_shorthand {
148 inline Key A(std::uint64_t j) { return Symbol('a', j); }
149 inline Key B(std::uint64_t j) { return Symbol('b', j); }
150 inline Key C(std::uint64_t j) { return Symbol('c', j); }
151 inline Key D(std::uint64_t j) { return Symbol('d', j); }
152 inline Key E(std::uint64_t j) { return Symbol('e', j); }
153 inline Key F(std::uint64_t j) { return Symbol('f', j); }
154 inline Key G(std::uint64_t j) { return Symbol('g', j); }
155 inline Key H(std::uint64_t j) { return Symbol('h', j); }
156 inline Key I(std::uint64_t j) { return Symbol('i', j); }
157 inline Key J(std::uint64_t j) { return Symbol('j', j); }
158 inline Key K(std::uint64_t j) { return Symbol('k', j); }
159 inline Key L(std::uint64_t j) { return Symbol('l', j); }
160 inline Key M(std::uint64_t j) { return Symbol('m', j); }
161 inline Key N(std::uint64_t j) { return Symbol('n', j); }
162 inline Key O(std::uint64_t j) { return Symbol('o', j); }
163 inline Key P(std::uint64_t j) { return Symbol('p', j); }
164 inline Key Q(std::uint64_t j) { return Symbol('q', j); }
165 inline Key R(std::uint64_t j) { return Symbol('r', j); }
166 inline Key S(std::uint64_t j) { return Symbol('s', j); }
167 inline Key T(std::uint64_t j) { return Symbol('t', j); }
168 inline Key U(std::uint64_t j) { return Symbol('u', j); }
169 inline Key V(std::uint64_t j) { return Symbol('v', j); }
170 inline Key W(std::uint64_t j) { return Symbol('w', j); }
171 inline Key X(std::uint64_t j) { return Symbol('x', j); }
172 inline Key Y(std::uint64_t j) { return Symbol('y', j); }
173 inline Key Z(std::uint64_t j) { return Symbol('z', j); }
174 }
175 
179  const unsigned char c_;
180 public:
181  constexpr SymbolGenerator(const unsigned char c) : c_(c) {}
182  Symbol operator()(const std::uint64_t j) const { return Symbol(c_, j); }
183  constexpr unsigned char chr() const { return c_; }
184 };
185 
187 template<> struct traits<Symbol> : public Testable<Symbol> {};
188 
189 } // \ namespace gtsam
gtsam::SymbolGenerator::chr
constexpr unsigned char chr() const
Definition: inference/Symbol.h:183
gtsam::symbol_shorthand::E
Key E(std::uint64_t j)
Definition: inference/Symbol.h:152
gtsam::SymbolGenerator
Definition: inference/Symbol.h:178
gtsam::symbol_shorthand::P
Key P(std::uint64_t j)
Definition: inference/Symbol.h:163
gtsam::symbol_shorthand::Q
Key Q(std::uint64_t j)
Definition: inference/Symbol.h:164
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
Testable.h
Concept check for values that can be used in unit tests.
gtsam::SymbolGenerator::SymbolGenerator
constexpr SymbolGenerator(const unsigned char c)
Definition: inference/Symbol.h:181
gtsam::Symbol::operator!=
bool operator!=(Key comp) const
Definition: inference/Symbol.h:111
gtsam::symbol_shorthand::N
Key N(std::uint64_t j)
Definition: inference/Symbol.h:161
gtsam::Symbol::operator!=
bool operator!=(const Symbol &comp) const
Definition: inference/Symbol.h:106
gtsam::Symbol::Symbol
Symbol(unsigned char c, std::uint64_t j)
Definition: inference/Symbol.h:55
gtsam::symbol_shorthand::M
Key M(std::uint64_t j)
Definition: inference/Symbol.h:160
gtsam::symbol_shorthand::J
Key J(std::uint64_t j)
Definition: inference/Symbol.h:157
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::Symbol::string
std::string string() const
Return string representation of the key.
Definition: inference/Symbol.h:88
gtsam::Symbol::c_
unsigned char c_
Definition: inference/Symbol.h:39
gtsam::symbol_shorthand::S
Key S(std::uint64_t j)
Definition: inference/Symbol.h:166
gtsam::symbol_shorthand::A
Key A(std::uint64_t j)
Definition: inference/Symbol.h:148
gtsam::Symbol::operator==
bool operator==(const Symbol &comp) const
Definition: inference/Symbol.h:96
gtsam::symbol_shorthand::G
Key G(std::uint64_t j)
Definition: inference/Symbol.h:154
gtsam::Symbol::chr
unsigned char chr() const
Definition: inference/Symbol.h:75
gtsam::symbolIndex
std::uint64_t symbolIndex(Key key)
Definition: inference/Symbol.h:145
Key.h
gtsam::symbol_shorthand::X
Key X(std::uint64_t j)
Definition: inference/Symbol.h:171
gtsam::print
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
gtsam::symbol_shorthand::Z
Key Z(std::uint64_t j)
Definition: inference/Symbol.h:173
gtsam::Symbol::Symbol
Symbol(const Symbol &key)
Definition: inference/Symbol.h:50
gtsam::symbol_shorthand::D
Key D(std::uint64_t j)
Definition: inference/Symbol.h:151
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
gtsam::symbol_shorthand::R
Key R(std::uint64_t j)
Definition: inference/Symbol.h:165
gtsam::symbol
Key symbol(unsigned char c, std::uint64_t j)
Definition: inference/Symbol.h:139
gtsam::symbol_shorthand::L
Key L(std::uint64_t j)
Definition: inference/Symbol.h:159
gtsam::symbol_shorthand::Y
Key Y(std::uint64_t j)
Definition: inference/Symbol.h:172
gtsam::symbol_shorthand::H
Key H(std::uint64_t j)
Definition: inference/Symbol.h:155
gtsam::symbol_shorthand::B
Key B(std::uint64_t j)
Definition: inference/Symbol.h:149
gtsam::Symbol::operator<
bool operator<(const Symbol &comp) const
Definition: inference/Symbol.h:91
gtsam::symbol_shorthand::F
Key F(std::uint64_t j)
Definition: inference/Symbol.h:153
gtsam::Symbol::operator==
bool operator==(Key comp) const
Definition: inference/Symbol.h:101
gtsam::equals
Definition: Testable.h:112
gtsam::symbol_shorthand::K
Key K(std::uint64_t j)
Definition: inference/Symbol.h:158
key
const gtsam::Symbol key('X', 0)
gtsam::SymbolGenerator::c_
const unsigned char c_
Definition: inference/Symbol.h:179
gtsam::symbol_shorthand::O
Key O(std::uint64_t j)
Definition: inference/Symbol.h:162
gtsam::Symbol::index
std::uint64_t index() const
Definition: inference/Symbol.h:80
gtsam::symbol_shorthand::I
Key I(std::uint64_t j)
Definition: inference/Symbol.h:156
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::traits
Definition: Group.h:36
gtsam::symbolChr
unsigned char symbolChr(Key key)
Definition: inference/Symbol.h:142
gtsam::symbol_shorthand::W
Key W(std::uint64_t j)
Definition: inference/Symbol.h:170
gtsam::Symbol::Symbol
Symbol()
Definition: inference/Symbol.h:45
gtsam::tol
const G double tol
Definition: Group.h:79
gtsam::symbol_shorthand::T
Key T(std::uint64_t j)
Definition: inference/Symbol.h:167
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
gtsam::symbol_shorthand::U
Key U(std::uint64_t j)
Definition: inference/Symbol.h:168
gtsam::Symbol::j_
std::uint64_t j_
Definition: inference/Symbol.h:40
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::symbol_shorthand::V
Key V(std::uint64_t j)
Definition: inference/Symbol.h:169
gtsam::SymbolGenerator::operator()
Symbol operator()(const std::uint64_t j) const
Definition: inference/Symbol.h:182
gtsam::Symbol
Definition: inference/Symbol.h:37
gtsam::symbol_shorthand::C
Key C(std::uint64_t j)
Definition: inference/Symbol.h:150


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:05:21