diff --git a/.cproject b/.cproject
index cbe6f0b56..b0eb31888 100644
--- a/.cproject
+++ b/.cproject
@@ -2409,6 +2409,14 @@
true
true
+
+ make
+ -j4
+ testReturnValue.run
+ true
+ true
+ true
+
make
-j5
diff --git a/wrap/Argument.h b/wrap/Argument.h
index c49075932..367d494c9 100644
--- a/wrap/Argument.h
+++ b/wrap/Argument.h
@@ -124,8 +124,6 @@ struct ArgumentList: public std::vector {
};
-static const bool T = true;
-
/* ************************************************************************* */
// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
struct ArgumentGrammar: public classic::grammar {
@@ -175,7 +173,7 @@ struct ArgumentListGrammar: public classic::grammar {
wrap::ArgumentList& result_; ///< successful parse will be placed in here
- Argument arg0, arg;
+ Argument arg, arg0;
ArgumentGrammar argument_g;
/// Construct type grammar and specify where result is placed
@@ -192,17 +190,10 @@ struct ArgumentListGrammar: public classic::grammar {
Rule argument_p, argumentList_p;
definition(ArgumentListGrammar const& self) {
-
- using namespace wrap;
using namespace classic;
-
- // NOTE: allows for pointers to all types
- // Slightly more permissive than before on basis/eigen type qualification
argument_p = self.argument_g //
- [push_back_a(self.result_, self.arg)] //
-// [assign_a(self.arg, self.arg0)]
- ;
-
+ [classic::push_back_a(self.result_, self.arg)] //
+ [assign_a(self.arg, self.arg0)];
argumentList_p = '(' >> !argument_p >> *(',' >> argument_p) >> ')';
}
diff --git a/wrap/Qualified.h b/wrap/Qualified.h
index 50805ec50..7f707319d 100644
--- a/wrap/Qualified.h
+++ b/wrap/Qualified.h
@@ -106,7 +106,7 @@ public:
return namespaces_.empty() && name_.empty();
}
- void clear() {
+ virtual void clear() {
namespaces_.clear();
name_.clear();
category = VOID;
@@ -231,5 +231,9 @@ public:
};
// type_grammar
+// Needed for other parsers in Argument.h and ReturnType.h
+static const bool T = true;
+
+
}// \namespace wrap
diff --git a/wrap/ReturnType.h b/wrap/ReturnType.h
index e619a18d1..5301e71a6 100644
--- a/wrap/ReturnType.h
+++ b/wrap/ReturnType.h
@@ -22,13 +22,19 @@ struct ReturnType: Qualified {
bool isPtr;
/// Makes a void type
- ReturnType() :
- isPtr(false) {
+ ReturnType(bool ptr = false) :
+ isPtr(ptr) {
}
- /// Make a Class type, no namespaces
- ReturnType(const std::string& name) :
- Qualified(name,Qualified::CLASS), isPtr(false) {
+ /// Constructor, no namespaces
+ ReturnType(const std::string& name, Qualified::Category c = Qualified::CLASS,
+ bool ptr = false) :
+ Qualified(name, c), isPtr(ptr) {
+ }
+
+ virtual void clear() {
+ Qualified::clear();
+ isPtr = false;
}
/// Check if this type is in a set of valid types
diff --git a/wrap/ReturnValue.h b/wrap/ReturnValue.h
index abfcec2b0..1ab844043 100644
--- a/wrap/ReturnValue.h
+++ b/wrap/ReturnValue.h
@@ -35,6 +35,22 @@ struct ReturnValue {
isPair(false), type1(type) {
}
+ /// Constructor
+ ReturnValue(const ReturnType& t1, const ReturnType& t2) :
+ isPair(true), type1(t1), type2(t2) {
+ }
+
+ virtual void clear() {
+ type1.clear();
+ type2.clear();
+ isPair = false;
+ }
+
+ bool operator==(const ReturnValue& other) const {
+ return isPair == other.isPair && type1 == other.type1
+ && type2 == other.type2;
+ }
+
/// Substitute template argument
ReturnValue expandTemplate(const TemplateSubstitution& ts) const;
diff --git a/wrap/tests/testReturnValue.cpp b/wrap/tests/testReturnValue.cpp
new file mode 100644
index 000000000..be245e75e
--- /dev/null
+++ b/wrap/tests/testReturnValue.cpp
@@ -0,0 +1,89 @@
+/* ----------------------------------------------------------------------------
+
+ * 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 testReturnValue.cpp
+ * @brief Unit test for ReturnValue class & parser
+ * @author Frank Dellaert
+ * @date Nov 30, 2014
+ **/
+
+#include
+#include
+#include
+
+using namespace std;
+using namespace wrap;
+
+//******************************************************************************
+// http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
+struct ReturnValueGrammar: public classic::grammar {
+
+ wrap::ReturnValue& result_; ///< successful parse will be placed in here
+
+ TypeGrammar returnType1_g, returnType2_g;
+
+ /// Construct type grammar and specify where result is placed
+ ReturnValueGrammar(wrap::ReturnValue& result) :
+ result_(result), returnType1_g(result.type1), returnType2_g(result.type2) {
+ }
+
+ /// Definition of type grammar
+ template
+ struct definition: basic_rules {
+
+ typedef classic::rule Rule;
+
+ Rule pair_p, returnValue_p;
+
+ definition(ReturnValueGrammar const& self) {
+
+ using namespace wrap;
+ using namespace classic;
+
+ pair_p = (str_p("pair") >> '<' >> self.returnType1_g >> ','
+ >> self.returnType2_g >> '>')[assign_a(self.result_.isPair, T)];
+
+ returnValue_p = pair_p | self.returnType1_g;
+ }
+
+ Rule const& start() const {
+ return returnValue_p;
+ }
+
+ };
+};
+// ReturnValueGrammar
+
+//******************************************************************************
+TEST( ReturnValue, grammar ) {
+
+ using classic::space_p;
+
+ // Create type grammar that will place result in actual
+ ReturnValue actual;
+ ReturnValueGrammar g(actual);
+
+ EXPECT(parse("VectorNotEigen", g, space_p).full);
+ EXPECT(actual==ReturnValue(ReturnType("VectorNotEigen",Qualified::CLASS)));
+ actual.clear();
+
+ EXPECT(parse("double", g, space_p).full);
+ EXPECT(actual==ReturnValue(ReturnType("double",Qualified::BASIS)));
+ actual.clear();
+}
+
+//******************************************************************************
+int main() {
+ TestResult tr;
+ return TestRegistry::runAllTests(tr);
+}
+//******************************************************************************