Fixed Symbol problem - related to using std::numeric_limits::max() statically on keys created outside of functions

release/4.3a0
Alex Cunningham 2012-06-09 19:43:14 +00:00
parent f45c236585
commit 9e26b32daa
3 changed files with 43 additions and 34 deletions

View File

@ -703,6 +703,14 @@
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders> <runAllBuilders>true</runAllBuilders>
</target> </target>
<target name="testKey.run" path="build/gtsam/nonlinear" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments>-j5</buildArguments>
<buildTarget>testKey.run</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="schedulingExample.run" path="build/gtsam_unstable/discrete" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="schedulingExample.run" path="build/gtsam_unstable/discrete" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments>-j5</buildArguments> <buildArguments>-j5</buildArguments>

View File

@ -16,8 +16,6 @@
* @author: Richard Roberts * @author: Richard Roberts
*/ */
#pragma once
#include <gtsam/nonlinear/Symbol.h> #include <gtsam/nonlinear/Symbol.h>
#include <boost/mpl/char.hpp> #include <boost/mpl/char.hpp>
@ -27,6 +25,7 @@
#include <boost/lambda/construct.hpp> #include <boost/lambda/construct.hpp>
#include <boost/lambda/lambda.hpp> #include <boost/lambda/lambda.hpp>
#include <limits.h>
#include <list> #include <list>
#include <iostream> #include <iostream>
@ -35,8 +34,7 @@ namespace gtsam {
static const size_t keyBits = sizeof(Key) * 8; static const size_t keyBits = sizeof(Key) * 8;
static const size_t chrBits = sizeof(unsigned char) * 8; static const size_t chrBits = sizeof(unsigned char) * 8;
static const size_t indexBits = keyBits - chrBits; static const size_t indexBits = keyBits - chrBits;
static const Key chrMask = Key(std::numeric_limits<unsigned char>::max()) static const Key chrMask = Key(UCHAR_MAX) << indexBits; // For some reason, std::numeric_limits<unsigned char>::max() fails
<< indexBits;
static const Key indexMask = ~chrMask; static const Key indexMask = ~chrMask;
Symbol::Symbol(Key key) { Symbol::Symbol(Key key) {
@ -45,8 +43,11 @@ namespace gtsam {
} }
Key Symbol::key() const { Key Symbol::key() const {
if (j_ > indexMask) if (j_ > indexMask) {
throw std::invalid_argument("Symbol index is too large"); boost::format msg("Symbol index is too large, j=%d, indexMask=%d");
msg % j_ % indexMask;
throw std::invalid_argument(msg.str());
}
Key key = (Key(c_) << indexBits) | j_; Key key = (Key(c_) << indexBits) | j_;
return key; return key;
} }

View File

@ -25,7 +25,7 @@ using namespace boost::assign;
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
Key aKey = gtsam::symbol_shorthand::X(4); // FIXME: throws index too large exception in Symbol.key() Key aKey = gtsam::symbol_shorthand::X(4);
/* ************************************************************************* */ /* ************************************************************************* */
TEST(Key, KeySymbolConversion) { TEST(Key, KeySymbolConversion) {