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 
49 extern GTSAM_EXPORT KeyFormatter DefaultKeyFormatter;
50 
51 // Helper function for Multi-robot Key Formatter
52 GTSAM_EXPORT std::string _multirobotKeyFormatter(gtsam::Key key);
53 
62 
64 struct StreamedKey {
65  const Key &key_;
66  explicit StreamedKey(const Key &key) : key_(key) {}
67  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
68 };
69 
79  public:
81  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const key_formatter &);
82  GTSAM_EXPORT friend std::ostream &operator<<(std::ostream &, const StreamedKey &);
83 
84  private:
86  static void *&property(std::ios_base &s);
87  static void set_property(std::ios_base &s, const KeyFormatter &f);
88  static KeyFormatter *get_property(std::ios_base &s);
89 };
90 
93 
94 // TODO(frank): Nothing fast about these :-(
98 
100 GTSAM_EXPORT void PrintKey(
101  Key key, const std::string &s = "",
102  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
103 
105 GTSAM_EXPORT void PrintKeyList(
106  const KeyList &keys, const std::string &s = "",
107  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
108 
110 GTSAM_EXPORT void PrintKeyVector(
111  const KeyVector &keys, const std::string &s = "",
112  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
113 
115 GTSAM_EXPORT void PrintKeySet(
116  const KeySet &keys, const std::string &s = "",
117  const KeyFormatter &keyFormatter = DefaultKeyFormatter);
118 
119 // Define Key to be Testable by specializing gtsam::traits
120 template<typename T> struct traits;
121 
122 template <>
123 struct traits<Key> {
124  static void Print(const Key& val, const std::string& str = "") {
125  PrintKey(val, str);
126  }
127  static bool Equals(const Key& val1, const Key& val2, double tol = 1e-8) {
128  return val1 == val2;
129  }
130 };
131 
132 } // namespace gtsam
FastVector.h
A thin wrapper around std::vector that uses a custom allocator.
s
RealScalar s
Definition: level1_cplx_impl.h:126
e
Array< double, 1, 3 > e(1./3., 0.5, 2.)
types.h
Typedefs for easier changing of types.
Testable.h
Concept check for values that can be used in unit tests.
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
gtsam::FastVector
std::vector< T, typename internal::FastDefaultVectorAllocator< T >::type > FastVector
Definition: FastVector.h:34
gtsam::StreamedKey::key_
const Key & key_
Definition: Key.h:65
gtsam::FastMap
Definition: FastMap.h:39
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:83
gtsam::FastSet
Definition: FastSet.h:51
gtsam::key_formatter::get_property
static KeyFormatter * get_property(std::ios_base &s)
Definition: Key.cpp:108
gtsam::KeyVector
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:92
gtsam::StreamedKey::operator<<
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &, const StreamedKey &)
gtsam::DefaultKeyFormatter
KeyFormatter DefaultKeyFormatter
Assign default key formatter.
Definition: Key.cpp:30
gtsam::key_formatter::formatter_
KeyFormatter formatter_
Definition: Key.h:85
gtsam::_multirobotKeyFormatter
string _multirobotKeyFormatter(Key key)
Definition: Key.cpp:49
FastSet.h
A thin wrapper around std::set that uses boost's fast_pool_allocator.
gtsam::PrintKey
void PrintKey(Key key, const string &s, const KeyFormatter &keyFormatter)
Utility function to print one key with optional prefix.
Definition: Key.cpp:44
gtsam::StreamedKey::StreamedKey
StreamedKey(const Key &key)
Definition: Key.h:66
gtsam::MultiRobotKeyFormatter
static const gtsam::KeyFormatter MultiRobotKeyFormatter
Definition: Key.h:60
gtsam::KeyFormatter
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
gtsam::key_formatter::property
static void *& property(std::ios_base &s)
Definition: Key.cpp:95
gtsam::FastList
Definition: FastList.h:43
gtsam::traits< Key >::Print
static void Print(const Key &val, const std::string &str="")
Definition: Key.h:124
str
Definition: pytypes.h:1558
key
const gtsam::Symbol key('X', 0)
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
gtsam::key_formatter::set_property
static void set_property(std::ios_base &s, const KeyFormatter &f)
Definition: Key.cpp:102
gtsam::StreamedKey
To use the key_formatter on Keys, they must be wrapped in a StreamedKey.
Definition: Key.h:64
gtsam
traits
Definition: SFMdata.h:40
gtsam::traits
Definition: Group.h:36
gtsam::key_formatter::operator<<
GTSAM_EXPORT friend std::ostream & operator<<(std::ostream &, const key_formatter &)
gtsam::key_formatter
Definition: Key.h:78
gtsam::_defaultKeyFormatter
string _defaultKeyFormatter(Key key)
Definition: Key.cpp:33
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
gtsam::traits< Key >::Equals
static bool Equals(const Key &val1, const Key &val2, double tol=1e-8)
Definition: Key.h:127
gtsam::tol
const G double tol
Definition: Group.h:79
FastList.h
A thin wrapper around std::list that uses boost's fast_pool_allocator.
gtsam::key_formatter::key_formatter
key_formatter(KeyFormatter v)
Definition: Key.h:80
gtsam::Key
std::uint64_t Key
Integer nonlinear key type.
Definition: types.h:97
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:88
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:78
FastMap.h
A thin wrapper around std::map that uses boost's fast_pool_allocator.


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:33:00