Streaming for Symbols
parent
6c665b818b
commit
4e2713026c
|
|
@ -66,5 +66,10 @@ boost::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
|
||||||
return bind(&Symbol::chr, bind(make, _1)) == c;
|
return bind(&Symbol::chr, bind(make, _1)) == c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &os, const Symbol &symbol) {
|
||||||
|
os << StreamedKey(symbol);
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,9 @@ public:
|
||||||
*/
|
*/
|
||||||
static boost::function<bool(Key)> ChrTest(unsigned char c);
|
static boost::function<bool(Key)> ChrTest(unsigned char c);
|
||||||
|
|
||||||
|
/// Output stream operator that can be used with key_formatter (see Key.h).
|
||||||
|
friend std::ostream &operator<<(std::ostream &, const Symbol &);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/** Serialization function */
|
/** Serialization function */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
|
* Atlanta, Georgia 30332-0415
|
||||||
|
* All Rights Reserved
|
||||||
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
|
* See LICENSE for the license information
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @file testSymbol.cpp
|
||||||
|
* @author Frank Dellaert
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtsam/inference/Symbol.h>
|
||||||
|
|
||||||
|
#include <CppUnitLite/TestHarness.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace gtsam;
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
// A custom (nonsensical) formatter.
|
||||||
|
string myFormatter(Key key) {
|
||||||
|
return "special";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Symbol, Formatting) {
|
||||||
|
Symbol symbol('c', 3);
|
||||||
|
|
||||||
|
// use key_formatter with a function pointer
|
||||||
|
stringstream ss2;
|
||||||
|
ss2 << key_formatter(myFormatter) << symbol;
|
||||||
|
EXPECT("special" == ss2.str());
|
||||||
|
|
||||||
|
// use key_formatter with a function object.
|
||||||
|
stringstream ss3;
|
||||||
|
ss3 << key_formatter(MultiRobotKeyFormatter) << symbol;
|
||||||
|
EXPECT("c3" == ss3.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
int main() {
|
||||||
|
TestResult tr;
|
||||||
|
return TestRegistry::runAllTests(tr);
|
||||||
|
}
|
||||||
|
/* ************************************************************************* */
|
||||||
|
|
||||||
Loading…
Reference in New Issue