Made a cpp file that makes the header cleaner, and avoids superheavy includes.
parent
1de8d6ecf3
commit
aeb2474d55
|
@ -0,0 +1,73 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* 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 Symbol.cpp
|
||||||
|
* @date June 9, 2012
|
||||||
|
* @author: Frank Dellaert
|
||||||
|
* @author: Richard Roberts
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <gtsam/nonlinear/Symbol.h>
|
||||||
|
|
||||||
|
#include <boost/mpl/char.hpp>
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/lambda/bind.hpp>
|
||||||
|
#include <boost/lambda/construct.hpp>
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace gtsam {
|
||||||
|
|
||||||
|
static const size_t keyBits = sizeof(Key) * 8;
|
||||||
|
static const size_t chrBits = sizeof(unsigned char) * 8;
|
||||||
|
static const size_t indexBits = keyBits - chrBits;
|
||||||
|
static const Key chrMask = Key(std::numeric_limits<unsigned char>::max())
|
||||||
|
<< indexBits;
|
||||||
|
static const Key indexMask = ~chrMask;
|
||||||
|
|
||||||
|
Symbol::Symbol(Key key) {
|
||||||
|
c_ = (unsigned char) ((key & chrMask) >> indexBits);
|
||||||
|
j_ = key & indexMask;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key Symbol::key() const {
|
||||||
|
if (j_ > indexMask)
|
||||||
|
throw std::invalid_argument("Symbol index is too large");
|
||||||
|
Key key = (Key(c_) << indexBits) | j_;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Symbol::print(const std::string& s) const {
|
||||||
|
std::cout << s << (std::string) (*this) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Symbol::equals(const Symbol& expected, double tol) const {
|
||||||
|
return (*this) == expected;
|
||||||
|
}
|
||||||
|
|
||||||
|
Symbol::operator std::string() const {
|
||||||
|
return str(boost::format("%c%d") % c_ % j_);
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::function<bool(Key)> Symbol::ChrTest(unsigned char c) {
|
||||||
|
namespace bl = boost::lambda;
|
||||||
|
return bl::bind(&Symbol::chr, bl::bind(bl::constructor<Symbol>(), bl::_1))
|
||||||
|
== c;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace gtsam
|
||||||
|
|
|
@ -19,17 +19,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <gtsam/nonlinear/Key.h>
|
#include <gtsam/nonlinear/Key.h>
|
||||||
|
|
||||||
#include <boost/mpl/char.hpp>
|
|
||||||
#include <boost/format.hpp>
|
|
||||||
#include <boost/serialization/nvp.hpp>
|
#include <boost/serialization/nvp.hpp>
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/lambda/bind.hpp>
|
|
||||||
#include <boost/lambda/construct.hpp>
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
@ -45,6 +35,7 @@ protected:
|
||||||
size_t j_;
|
size_t j_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Default constructor */
|
/** Default constructor */
|
||||||
Symbol() :
|
Symbol() :
|
||||||
c_(0), j_(0) {
|
c_(0), j_(0) {
|
||||||
|
@ -61,39 +52,19 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constructor that decodes an integer Key */
|
/** Constructor that decodes an integer Key */
|
||||||
Symbol(Key key) {
|
Symbol(Key key);
|
||||||
const size_t keyBits = sizeof(Key) * 8;
|
|
||||||
const size_t chrBits = sizeof(unsigned char) * 8;
|
|
||||||
const size_t indexBits = keyBits - chrBits;
|
|
||||||
const Key chrMask = Key(std::numeric_limits<unsigned char>::max()) << indexBits;
|
|
||||||
const Key indexMask = ~chrMask;
|
|
||||||
c_ = (unsigned char)((key & chrMask) >> indexBits);
|
|
||||||
j_ = key & indexMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** return Key (integer) representation */
|
/** return Key (integer) representation */
|
||||||
Key key() const {
|
Key key() const;
|
||||||
const size_t keyBits = sizeof(Key) * 8;
|
|
||||||
const size_t chrBits = sizeof(unsigned char) * 8;
|
|
||||||
const size_t indexBits = keyBits - chrBits;
|
|
||||||
const Key chrMask = Key(std::numeric_limits<unsigned char>::max()) << indexBits;
|
|
||||||
const Key indexMask = ~chrMask;
|
|
||||||
if(j_ > indexMask)
|
|
||||||
throw std::invalid_argument("Symbol index is too large");
|
|
||||||
Key key = (Key(c_) << indexBits) | j_;
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Cast to integer */
|
/** Cast to integer */
|
||||||
operator Key() const { return key(); }
|
operator Key() const { return key(); }
|
||||||
|
|
||||||
// Testable Requirements
|
/// Print
|
||||||
void print(const std::string& s = "") const {
|
void print(const std::string& s = "") const;
|
||||||
std::cout << s << (std::string) (*this) << std::endl;
|
|
||||||
}
|
/// Check equality
|
||||||
bool equals(const Symbol& expected, double tol = 0.0) const {
|
bool equals(const Symbol& expected, double tol = 0.0) const;
|
||||||
return (*this) == expected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Retrieve key character */
|
/** Retrieve key character */
|
||||||
unsigned char chr() const {
|
unsigned char chr() const {
|
||||||
|
@ -106,23 +77,29 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a string from the key */
|
/** Create a string from the key */
|
||||||
operator std::string() const {
|
operator std::string() const;
|
||||||
return str(boost::format("%c%d") % c_ % j_);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Comparison for use in maps */
|
/** Comparison for use in maps */
|
||||||
bool operator<(const Symbol& comp) const {
|
bool operator<(const Symbol& comp) const {
|
||||||
return c_ < comp.c_ || (comp.c_ == c_ && j_ < comp.j_);
|
return c_ < comp.c_ || (comp.c_ == c_ && j_ < comp.j_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Comparison for use in maps */
|
||||||
bool operator==(const Symbol& comp) const {
|
bool operator==(const Symbol& comp) const {
|
||||||
return comp.c_ == c_ && comp.j_ == j_;
|
return comp.c_ == c_ && comp.j_ == j_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Comparison for use in maps */
|
||||||
bool operator==(Key comp) const {
|
bool operator==(Key comp) const {
|
||||||
return comp == (Key)(*this);
|
return comp == (Key)(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Comparison for use in maps */
|
||||||
bool operator!=(const Symbol& comp) const {
|
bool operator!=(const Symbol& comp) const {
|
||||||
return comp.c_ != c_ || comp.j_ != j_;
|
return comp.c_ != c_ || comp.j_ != j_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Comparison for use in maps */
|
||||||
bool operator!=(Key comp) const {
|
bool operator!=(Key comp) const {
|
||||||
return comp != (Key)(*this);
|
return comp != (Key)(*this);
|
||||||
}
|
}
|
||||||
|
@ -132,10 +109,7 @@ public:
|
||||||
* Values::filter() function to retrieve all key-value pairs with the
|
* Values::filter() function to retrieve all key-value pairs with the
|
||||||
* requested character.
|
* requested character.
|
||||||
*/
|
*/
|
||||||
static boost::function<bool(Key)> ChrTest(unsigned char c) {
|
static boost::function<bool(Key)> ChrTest(unsigned char c);
|
||||||
namespace bl = boost::lambda;
|
|
||||||
return bl::bind(&Symbol::chr, bl::bind(bl::constructor<Symbol>(), bl::_1)) == c;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue