LabeledSymbol.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 
20 #pragma once
21 
22 #include <gtsam/base/Testable.h>
23 #include <gtsam/inference/Symbol.h>
24 
25 #include <functional>
26 
27 namespace gtsam {
28 
37 class GTSAM_EXPORT LabeledSymbol {
38  protected:
39  unsigned char c_, label_;
41 
42  public:
45 
47  LabeledSymbol();
48 
51 
53  LabeledSymbol(unsigned char c, unsigned char label, std::uint64_t j);
54 
57 
61 
63  void print(const std::string& s = "") const;
64 
66  bool equals(const LabeledSymbol& expected, double tol = 0.0) const {
67  return (*this) == expected;
68  }
69 
73 
75  operator Key() const;
76 
78  Key key() const { return (Key) * this; }
79 
81  inline unsigned char label() const { return label_; }
82 
84  inline unsigned char chr() const { return c_; }
85 
87  inline size_t index() const { return j_; }
88 
90  operator std::string() const;
91 
93  friend GTSAM_EXPORT std::ostream& operator<<(std::ostream&,
94  const LabeledSymbol&);
95 
99 
100  bool operator<(const LabeledSymbol& comp) const;
101  bool operator==(const LabeledSymbol& comp) const;
102  bool operator==(Key comp) const;
103  bool operator!=(const LabeledSymbol& comp) const;
104  bool operator!=(Key comp) const;
105 
113 
115  static std::function<bool(Key)> TypeTest(unsigned char c);
116 
118  static std::function<bool(Key)> LabelTest(unsigned char label);
119 
121  static std::function<bool(Key)> TypeLabelTest(unsigned char c,
122  unsigned char label);
123 
127 
129  LabeledSymbol upper() const { return LabeledSymbol(c_, toupper(label_), j_); }
130  LabeledSymbol lower() const { return LabeledSymbol(c_, tolower(label_), j_); }
131 
133  LabeledSymbol newChr(unsigned char c) const {
134  return LabeledSymbol(c, label_, j_);
135  }
136 
138  LabeledSymbol newLabel(unsigned char label) const {
139  return LabeledSymbol(c_, label, j_);
140  }
141 
143 
144  private:
145 #ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
146  friend class boost::serialization::access;
148  template <class ARCHIVE>
149  void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
150  ar& BOOST_SERIALIZATION_NVP(c_);
151  ar& BOOST_SERIALIZATION_NVP(label_);
152  ar& BOOST_SERIALIZATION_NVP(j_);
153  }
154 #endif
155 }; // \class LabeledSymbol
156 
158 inline Key mrsymbol(unsigned char c, unsigned char label, size_t j) {
159  return (Key)LabeledSymbol(c, label, j);
160 }
161 
163 inline unsigned char mrsymbolChr(Key key) { return LabeledSymbol(key).chr(); }
164 
166 inline unsigned char mrsymbolLabel(Key key) {
167  return LabeledSymbol(key).label();
168 }
169 
171 inline size_t mrsymbolIndex(Key key) { return LabeledSymbol(key).index(); }
172 
174 template <>
175 struct traits<LabeledSymbol> : public Testable<LabeledSymbol> {};
176 
177 } // namespace gtsam
gtsam::LabeledSymbol::j_
std::uint64_t j_
Definition: LabeledSymbol.h:40
gtsam::LabeledSymbol::chr
unsigned char chr() const
Retrieve key character.
Definition: LabeledSymbol.h:84
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::operator<<
std::ostream & operator<<(std::ostream &os, const Dih6 &m)
Definition: testGroup.cpp:109
gtsam::LabeledSymbol::lower
LabeledSymbol lower() const
Definition: LabeledSymbol.h:130
Testable.h
Concept check for values that can be used in unit tests.
gtsam::LabeledSymbol
Definition: LabeledSymbol.h:37
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
gtsam::LabeledSymbol::newLabel
LabeledSymbol newLabel(unsigned char label) const
Create a new symbol with a different label.
Definition: LabeledSymbol.h:138
gtsam::operator==
bool operator==(const Matrix &A, const Matrix &B)
Definition: base/Matrix.h:99
gtsam::mrsymbolChr
unsigned char mrsymbolChr(Key key)
Return the character portion of a symbol key.
Definition: LabeledSymbol.h:163
gtsam::LabeledSymbol::index
size_t index() const
Retrieve key index.
Definition: LabeledSymbol.h:87
gtsam::LabeledSymbol::key
Key key() const
return the integer version
Definition: LabeledSymbol.h:78
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
cholesky::expected
Matrix expected
Definition: testMatrix.cpp:971
Symbol.h
gtsam::LabeledSymbol::upper
LabeledSymbol upper() const
Converts to upper/lower versions of labels.
Definition: LabeledSymbol.h:129
gtsam::LabeledSymbol::label
unsigned char label() const
Retrieve label character.
Definition: LabeledSymbol.h:81
key
const gtsam::Symbol key('X', 0)
operator<
bool operator<(const benchmark_t &b1, const benchmark_t &b2)
Definition: benchmark-blocking-sizes.cpp:144
gtsam::operator!=
bool operator!=(const Matrix &A, const Matrix &B)
Definition: base/Matrix.h:106
gtsam
traits
Definition: SFMdata.h:40
gtsam::Testable
Definition: Testable.h:152
gtsam::LabeledSymbol::newChr
LabeledSymbol newChr(unsigned char c) const
Create a new symbol with a different character.
Definition: LabeledSymbol.h:133
gtsam::traits
Definition: Group.h:36
gtsam::mrsymbolIndex
size_t mrsymbolIndex(Key key)
Return the index portion of a symbol key.
Definition: LabeledSymbol.h:171
gtsam::LabeledSymbol::label_
unsigned char label_
Definition: LabeledSymbol.h:39
gtsam::LabeledSymbol::equals
bool equals(const LabeledSymbol &expected, double tol=0.0) const
Checks if this LabeledSymbol is equal to another, tolerance is ignored.
Definition: LabeledSymbol.h:66
gtsam::mrsymbolLabel
unsigned char mrsymbolLabel(Key key)
Return the label portion of a symbol key.
Definition: LabeledSymbol.h:166
gtsam::tol
const G double tol
Definition: Group.h:79
uint64_t
unsigned __int64 uint64_t
Definition: ms_stdint.h:95
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
gtsam::mrsymbol
Key mrsymbol(unsigned char c, unsigned char label, size_t j)
Create a symbol key from a character, label and index, i.e. xA5.
Definition: LabeledSymbol.h:158


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:39