Key.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 
18 #pragma once
19 
20 #include <gtsam/base/FastList.h>
21 #include <gtsam/base/FastMap.h>
22 #include <gtsam/base/FastSet.h>
23 #include <gtsam/base/FastVector.h>
24 #include <gtsam/base/Testable.h>
25 #include <gtsam/base/types.h>
26 #include <gtsam/dllexport.h>
27 
28 #include <functional>
29 
30 #include <iosfwd>
31 
32 namespace gtsam {
33 
35 using KeyFormatter = std::function<std::string(Key)>;
36 
37 // Helper function for DefaultKeyFormatter
38 GTSAM_EXPORT std::string _defaultKeyFormatter(Key key);
39 
44 
45 // Helper function for Multi-robot Key Formatter
46 GTSAM_EXPORT std::string _multirobotKeyFormatter(gtsam::Key key);
47 
56 
58 struct StreamedKey {
59  const Key &key_;
60  explicit StreamedKey(const Key &key) : key_(key) {}
61  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
62 };
63 
73  public:
74  explicit key_formatter(KeyFormatter v) : formatter_(v) {}
75  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const key_formatter &);
76  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
77 
78  private:
80  static void *&property(std::ios_base &s);
81  static void set_property(std::ios_base &s, const KeyFormatter &f);
82  static KeyFormatter *get_property(std::ios_base &s);
83 };
84 
87 
88 // TODO(frank): Nothing fast about these :-(
92 
94 GTSAM_EXPORT void PrintKey(
95  Key key, const std::string &s = "",
96  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
97 
99 GTSAM_EXPORT void PrintKeyList(
100  const KeyList &keys, const std::string &s = "",
101  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
102 
104 GTSAM_EXPORT void PrintKeyVector(
105  const KeyVector &keys, const std::string &s = "",
106  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
107 
109 GTSAM_EXPORT void PrintKeySet(
110  const KeySet &keys, const std::string &s = "",
111  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
112 
113 // Define Key to be Testable by specializing gtsam::traits
114 template<typename T> struct traits;
115 
116 template <>
117 struct traits<Key> {
118  static void Print(const Key& val, const std::string& str = "") {
119  PrintKey(val, str);
120  }
121  static bool Equals(const Key& val1, const Key& val2, double tol = 1e-8) {
122  return val1 == val2;
123  }
124 };
125 
126 } // namespace gtsam
127 
128 
129 
130 
const gtsam::Symbol key('X', 0)
void PrintKeyVector(const KeyVector &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:80
void PrintKeySet(const KeySet &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:85
Typedefs for easier changing of types.
A thin wrapper around std::list that uses boost&#39;s fast_pool_allocator.
Concept check for values that can be used in unit tests.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
string _multirobotKeyFormatter(Key key)
Definition: Key.cpp:46
static bool Equals(const Key &val1, const Key &val2, double tol=1e-8)
Definition: Key.h:121
KeyFormatter formatter_
Definition: Key.h:79
static const KeyFormatter DefaultKeyFormatter
Definition: Key.h:43
string _defaultKeyFormatter(Key key)
Definition: Key.cpp:30
Definition: pytypes.h:1403
Array< int, Dynamic, 1 > v
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition: Key.h:58
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
const Key & key_
Definition: Key.h:59
static void Print(const Key &val, const std::string &str="")
Definition: Key.h:118
A thin wrapper around std::vector that uses a custom allocator.
traits
Definition: chartTesting.h:28
A thin wrapper around std::map that uses boost&#39;s fast_pool_allocator.
void PrintKey(Key key, const string &s, const KeyFormatter &keyFormatter)
Utility function to print one key with optional prefix.
Definition: Key.cpp:41
key_formatter(KeyFormatter v)
Definition: Key.h:74
static const gtsam::KeyFormatter MultiRobotKeyFormatter
Definition: Key.h:54
const G double tol
Definition: Group.h:86
const KeyVector keys
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
A thin wrapper around std::set that uses boost&#39;s fast_pool_allocator.
StreamedKey(const Key &key)
Definition: Key.h:60
void PrintKeyList(const KeyList &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:75
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:102
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &, const StreamedKey &)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:29