gtsam  3.2.1
gtsam
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Symbol.h
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 <boost/serialization/nvp.hpp>
22 
23 #include <gtsam/inference/Key.h>
24 
25 namespace gtsam {
26 
33 class GTSAM_EXPORT Symbol {
34 protected:
35  unsigned char c_;
36  size_t j_;
37 
38 public:
39 
41  Symbol() :
42  c_(0), j_(0) {
43  }
44 
46  Symbol(const Symbol& key) :
47  c_(key.c_), j_(key.j_) {
48  }
49 
51  Symbol(unsigned char c, size_t j) :
52  c_(c), j_(j) {
53  }
54 
56  Symbol(Key key);
57 
59  Key key() const;
60 
62  operator Key() const { return key(); }
63 
65  void print(const std::string& s = "") const;
66 
68  bool equals(const Symbol& expected, double tol = 0.0) const;
69 
71  unsigned char chr() const {
72  return c_;
73  }
74 
76  size_t index() const {
77  return j_;
78  }
79 
81  operator std::string() const;
82 
84  bool operator<(const Symbol& comp) const {
85  return c_ < comp.c_ || (comp.c_ == c_ && j_ < comp.j_);
86  }
87 
89  bool operator==(const Symbol& comp) const {
90  return comp.c_ == c_ && comp.j_ == j_;
91  }
92 
94  bool operator==(Key comp) const {
95  return comp == (Key)(*this);
96  }
97 
99  bool operator!=(const Symbol& comp) const {
100  return comp.c_ != c_ || comp.j_ != j_;
101  }
102 
104  bool operator!=(Key comp) const {
105  return comp != (Key)(*this);
106  }
107 
113  static boost::function<bool(Key)> ChrTest(unsigned char c);
114 
115 private:
116 
118  friend class boost::serialization::access;
119  template<class ARCHIVE>
120  void serialize(ARCHIVE & ar, const unsigned int version) {
121  ar & BOOST_SERIALIZATION_NVP(c_);
122  ar & BOOST_SERIALIZATION_NVP(j_);
123  }
124 };
125 
127 inline Key symbol(unsigned char c, size_t j) { return (Key)Symbol(c,j); }
128 
130 inline unsigned char symbolChr(Key key) { return Symbol(key).chr(); }
131 
133 inline size_t symbolIndex(Key key) { return Symbol(key).index(); }
134 
135 namespace symbol_shorthand {
136 inline Key A(size_t j) { return Symbol('a', j); }
137 inline Key B(size_t j) { return Symbol('b', j); }
138 inline Key C(size_t j) { return Symbol('c', j); }
139 inline Key D(size_t j) { return Symbol('d', j); }
140 inline Key E(size_t j) { return Symbol('e', j); }
141 inline Key F(size_t j) { return Symbol('f', j); }
142 inline Key G(size_t j) { return Symbol('g', j); }
143 inline Key H(size_t j) { return Symbol('h', j); }
144 inline Key I(size_t j) { return Symbol('i', j); }
145 inline Key J(size_t j) { return Symbol('j', j); }
146 inline Key K(size_t j) { return Symbol('k', j); }
147 inline Key L(size_t j) { return Symbol('l', j); }
148 inline Key M(size_t j) { return Symbol('m', j); }
149 inline Key N(size_t j) { return Symbol('n', j); }
150 inline Key O(size_t j) { return Symbol('o', j); }
151 inline Key P(size_t j) { return Symbol('p', j); }
152 inline Key Q(size_t j) { return Symbol('q', j); }
153 inline Key R(size_t j) { return Symbol('r', j); }
154 inline Key S(size_t j) { return Symbol('s', j); }
155 inline Key T(size_t j) { return Symbol('t', j); }
156 inline Key U(size_t j) { return Symbol('u', j); }
157 inline Key V(size_t j) { return Symbol('v', j); }
158 inline Key W(size_t j) { return Symbol('w', j); }
159 inline Key X(size_t j) { return Symbol('x', j); }
160 inline Key Y(size_t j) { return Symbol('y', j); }
161 inline Key Z(size_t j) { return Symbol('z', j); }
162 }
163 
164 } // namespace gtsam
165 
bool operator!=(Key comp) const
Comparison for use in maps.
Definition: Symbol.h:104
size_t index() const
Retrieve key index.
Definition: Symbol.h:76
bool operator==(Key comp) const
Comparison for use in maps.
Definition: Symbol.h:94
Character and index key used in VectorValues, GaussianFactorGraph, GaussianFactor, etc.
Definition: Symbol.h:33
Symbol(const Symbol &key)
Copy constructor.
Definition: Symbol.h:46
void print(const Matrix &A, const string &s, ostream &stream)
print a matrix
Definition: Matrix.cpp:183
unsigned char symbolChr(Key key)
Return the character portion of a symbol key.
Definition: Symbol.h:130
Template to create a binary predicate.
Definition: Testable.h:102
size_t Key
Integer nonlinear key type.
Definition: types.h:59
bool operator==(const Symbol &comp) const
Comparison for use in maps.
Definition: Symbol.h:89
bool operator!=(const Symbol &comp) const
Comparison for use in maps.
Definition: Symbol.h:99
Key symbol(unsigned char c, size_t j)
Create a symbol key from a character and index, i.e.
Definition: Symbol.h:127
Symbol()
Default constructor.
Definition: Symbol.h:41
size_t symbolIndex(Key key)
Return the index portion of a symbol key.
Definition: Symbol.h:133
Symbol(unsigned char c, size_t j)
Constructor.
Definition: Symbol.h:51
bool operator<(const Symbol &comp) const
Comparison for use in maps.
Definition: Symbol.h:84
unsigned char chr() const
Retrieve key character.
Definition: Symbol.h:71