gtsam
Loading...
Searching...
No Matches
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>
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
32namespace gtsam {
33
35using KeyFormatter = std::function<std::string(Key)>;
36
37// Helper function for DefaultKeyFormatter
38GTSAM_EXPORT std::string _defaultKeyFormatter(Key key);
39
49extern GTSAM_EXPORT KeyFormatter DefaultKeyFormatter;
50
51// Helper function for Multi-robot Key Formatter
52GTSAM_EXPORT std::string _multirobotKeyFormatter(gtsam::Key key);
53
60extern GTSAM_EXPORT KeyFormatter MultiRobotKeyFormatter;
61
63struct StreamedKey {
64 const Key &key_;
65 explicit StreamedKey(const Key &key) : key_(key) {}
66 GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
67};
68
77class key_formatter {
78 public:
79 explicit key_formatter(KeyFormatter v) : formatter_(v) {}
80 GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const key_formatter &);
81 GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
82
83 private:
84 KeyFormatter formatter_;
85 static void *&property(std::ios_base &s);
86 static void set_property(std::ios_base &s, const KeyFormatter &f);
87 static KeyFormatter *get_property(std::ios_base &s);
88};
89
92
93// TODO(frank): Nothing fast about these :-(
94using KeyList = FastList<Key>;
95using KeySet = FastSet<Key>;
96using KeyGroupMap = FastMap<Key, int>;
97
99GTSAM_EXPORT void PrintKey(
100 Key key, const std::string &s = "",
101 const KeyFormatter &keyFormatter = DefaultKeyFormatter);
102
104GTSAM_EXPORT void PrintKeyList(
105 const KeyList &keys, const std::string &s = "",
106 const KeyFormatter &keyFormatter = DefaultKeyFormatter);
107
109GTSAM_EXPORT void PrintKeyVector(
110 const KeyVector &keys, const std::string &s = "",
111 const KeyFormatter &keyFormatter = DefaultKeyFormatter);
112
114GTSAM_EXPORT void PrintKeySet(
115 const KeySet &keys, const std::string &s = "",
116 const KeyFormatter &keyFormatter = DefaultKeyFormatter);
117
118// Define Key to be Testable by specializing gtsam::traits
119template<typename T> struct traits;
120
121template <>
122struct traits<Key> {
123 static void Print(const Key& val, const std::string& str = "") {
124 PrintKey(val, str);
125 }
126 static bool Equals(const Key& val1, const Key& val2, double tol = 1e-8) {
127 return val1 == val2;
128 }
129};
130
131} // namespace gtsam
A thin wrapper around std::vector that uses a custom allocator.
Typedefs for easier changing of types.
A thin wrapper around std::list that uses boost's fast_pool_allocator.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
A thin wrapper around std::set that uses boost's fast_pool_allocator.
Concept check for values that can be used in unit tests.
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
FastVector is a type alias to a std::vector with a custom memory allocator.
Definition FastVector.h:33
Global functions in a separate testing namespace.
Definition chartTesting.h:28
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition Key.cpp:30
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition Key.h:91
void PrintKeyVector(const KeyVector &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition Key.cpp:84
void PrintKey(Key key, const string &s, const KeyFormatter &keyFormatter)
Utility function to print one key with optional prefix.
Definition Key.cpp:45
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
void PrintKeyList(const KeyList &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition Key.cpp:79
void PrintKeySet(const KeySet &keys, const string &s, const KeyFormatter &keyFormatter)
Utility function to print sets of keys with optional prefix.
Definition Key.cpp:89
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
KeyFormatter MultiRobotKeyFormatter
A KeyFormatter that will check for LabeledSymbol keys, as well as Symbol and plain integer keys.
Definition Key.cpp:31
FastList is a thin wrapper around std::list that uses the boost fast_pool_allocator instead of the de...
Definition FastList.h:43
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
FastSet is a thin wrapper around std::set that uses the boost fast_pool_allocator instead of the defa...
Definition FastSet.h:54
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition Group.h:37
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition Key.h:63