| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |  * 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 Template.h | 
					
						
							|  |  |  |  * @brief Template name | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  * @date Nov 11, 2014 | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <wrap/Qualified.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// The template specification that goes before a method or a class
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  | class Template { | 
					
						
							|  |  |  |   std::string argName_; | 
					
						
							|  |  |  |   std::vector<Qualified> argValues_; | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |   std::vector<int> intList_; | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |   friend struct TemplateGrammar; | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   /// The only way to get values into a Template is via our friendly Grammar
 | 
					
						
							|  |  |  |   Template() { | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |   void clear() { | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |     argName_.clear(); | 
					
						
							|  |  |  |     argValues_.clear(); | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |     intList_.clear(); | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |   } | 
					
						
							|  |  |  |   const std::string& argName() const { | 
					
						
							|  |  |  |     return argName_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |   const std::vector<int>& intList() const { | 
					
						
							|  |  |  |     return intList_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |   const std::vector<Qualified>& argValues() const { | 
					
						
							|  |  |  |     return argValues_; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |   bool empty() const { | 
					
						
							|  |  |  |     return argValues_.empty() && intList_.empty(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |   size_t nrValues() const { | 
					
						
							|  |  |  |     return argValues_.size(); | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |   const Qualified& operator[](size_t i) const { | 
					
						
							|  |  |  |     return argValues_[i]; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   bool valid() const { | 
					
						
							|  |  |  |     return !argName_.empty() && argValues_.size() > 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
 | 
					
						
							|  |  |  | struct IntListGrammar: public classic::grammar<IntListGrammar > { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   typedef std::vector<int> IntList; | 
					
						
							|  |  |  |   IntList& result_; ///< successful parse will be placed in here
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Construct type grammar and specify where result is placed
 | 
					
						
							|  |  |  |   IntListGrammar(IntList& result) : | 
					
						
							|  |  |  |       result_(result) { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Definition of type grammar
 | 
					
						
							|  |  |  |   template<typename ScannerT> | 
					
						
							|  |  |  |   struct definition { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     classic::rule<ScannerT> integer_p, intList_p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     definition(IntListGrammar const& self) { | 
					
						
							|  |  |  |       using namespace classic; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       integer_p = int_p[push_back_a(self.result_)]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       intList_p = '{' >> !integer_p >> *(',' >> integer_p) >> '}'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     classic::rule<ScannerT> const& start() const { | 
					
						
							|  |  |  |       return intList_p; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | // IntListGrammar
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | // http://boost-spirit.com/distrib/spirit_1_8_2/libs/spirit/doc/grammar.html
 | 
					
						
							|  |  |  | struct TemplateGrammar: public classic::grammar<TemplateGrammar> { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Template& result_; ///< successful parse will be placed in here
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   TypeListGrammar<'{', '}'> argValues_g; ///< TypeList parser
 | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |   IntListGrammar intList_g; ///< TypeList parser
 | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Construct type grammar and specify where result is placed
 | 
					
						
							|  |  |  |   TemplateGrammar(Template& result) : | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |       result_(result), argValues_g(result.argValues_), //
 | 
					
						
							|  |  |  |       intList_g(result.intList_) { | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// Definition of type grammar
 | 
					
						
							|  |  |  |   template<typename ScannerT> | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   struct definition: BasicRules<ScannerT> { | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |     classic::rule<ScannerT> templateArgValues_p; | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     definition(TemplateGrammar const& self) { | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |       using classic::str_p; | 
					
						
							|  |  |  |       using classic::assign_a; | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |       templateArgValues_p = (str_p("template") >> '<' | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  |           >> (BasicRules<ScannerT>::name_p)[assign_a(self.result_.argName_)] | 
					
						
							| 
									
										
										
										
											2016-02-08 12:33:48 +08:00
										 |  |  |           >> '=' >> (self.argValues_g | self.intList_g) >> '>'); | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |     classic::rule<ScannerT> const& start() const { | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  |       return templateArgValues_p; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | // TemplateGrammar
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:35 +08:00
										 |  |  | /// Cool initializer for tests
 | 
					
						
							|  |  |  | static inline boost::optional<Template> CreateTemplate(const std::string& s) { | 
					
						
							|  |  |  |   Template result; | 
					
						
							|  |  |  |   TemplateGrammar g(result); | 
					
						
							|  |  |  |   bool success = parse(s.c_str(), g, classic::space_p).full; | 
					
						
							|  |  |  |   if (success) | 
					
						
							|  |  |  |     return result; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return boost::none; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace wrap
 | 
					
						
							| 
									
										
										
										
											2014-12-01 19:43:12 +08:00
										 |  |  | 
 |