gtsam  4.1.0
gtsam
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 <boost/function.hpp>
29 
30 #include <iosfwd>
31 
32 namespace gtsam {
33 
35 typedef boost::function<std::string(Key)> KeyFormatter;
36 
37 // Helper function for DefaultKeyFormatter
38 GTSAM_EXPORT std::string _defaultKeyFormatter(Key key);
39 
43 static const KeyFormatter DefaultKeyFormatter = &_defaultKeyFormatter;
44 
45 // Helper function for Multi-robot Key Formatter
46 GTSAM_EXPORT std::string _multirobotKeyFormatter(gtsam::Key key);
47 
54 static const gtsam::KeyFormatter MultiRobotKeyFormatter =
55  &_multirobotKeyFormatter;
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:
79  KeyFormatter formatter_;
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 
86 typedef FastVector<Key> KeyVector;
87 
88 // TODO(frank): Nothing fast about these :-(
89 typedef FastList<Key> KeyList;
90 typedef FastSet<Key> KeySet;
92 
94 GTSAM_EXPORT void PrintKey(Key key, const std::string& s = "",
95  const KeyFormatter& keyFormatter = DefaultKeyFormatter);
96 
98 GTSAM_EXPORT void PrintKeyList(const KeyList& keys, const std::string& s = "",
99  const KeyFormatter& keyFormatter = DefaultKeyFormatter);
100 
102 GTSAM_EXPORT void PrintKeyVector(const KeyVector& keys, const std::string& s =
103  "", const KeyFormatter& keyFormatter = DefaultKeyFormatter);
104 
106 GTSAM_EXPORT void PrintKeySet(const KeySet& keys, const std::string& s = "",
107  const KeyFormatter& keyFormatter = DefaultKeyFormatter);
108 
109 // Define Key to be Testable by specializing gtsam::traits
110 template<typename T> struct traits;
111 
112 template <>
113 struct traits<Key> {
114  static void Print(const Key& val, const std::string& str = "") {
115  PrintKey(val, str);
116  }
117  static bool Equals(const Key& val1, const Key& val2, double tol = 1e-8) {
118  return val1 == val2;
119  }
120 };
121 
122 } // namespace gtsam
123 
124 
125 
126 
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
Testable.h
Concept check for values that can be used in unit tests.
gtsam::key_formatter
Output stream manipulator that will format gtsam::Keys according to the given KeyFormatter,...
Definition: Key.h:72
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::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:61
gtsam::StreamedKey
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition: Key.h:58
FastMap.h
A thin wrapper around std::map that uses boost's fast_pool_allocator.
types.h
Typedefs for easier changing of types.
gtsam::FastList
Definition: FastList.h:38
gtsam
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
gtsam::FastSet< Key >
gtsam::KeyFormatter
boost::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
FastList.h
A thin wrapper around std::list that uses boost's fast_pool_allocator.
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:86
gtsam::FastMap
Definition: FastMap.h:38
gtsam::PrintKey
void PrintKey(Key key, const string &s, const KeyFormatter &keyFormatter)
Utility function to print one key with optional prefix.
Definition: Key.cpp:40
gtsam::PrintKeyList
void PrintKeyList(const KeyList &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:72
FastSet.h
A thin wrapper around std::set that uses boost's fast_pool_allocator.
gtsam::PrintKeyVector
void PrintKeyVector(const KeyVector &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:77
gtsam::PrintKeySet
void PrintKeySet(const KeySet &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition: Key.cpp:82