Simplified parsing as we moved on from this boost version
							parent
							
								
									f59342882a
								
							
						
					
					
						commit
						fd7640b1b7
					
				|  | @ -38,19 +38,7 @@ namespace gtsam { | |||
|     using boost::phoenix::push_back; | ||||
| 
 | ||||
|     // Special rows, true and false
 | ||||
|     Signature::Row createF() { | ||||
|       Signature::Row r(2); | ||||
|       r[0] = 1; | ||||
|       r[1] = 0; | ||||
|       return r; | ||||
|     } | ||||
|     Signature::Row createT() { | ||||
|       Signature::Row r(2); | ||||
|       r[0] = 0; | ||||
|       r[1] = 1; | ||||
|       return r; | ||||
|     } | ||||
|     Signature::Row T = createT(), F = createF(); | ||||
|     Signature::Row F{1, 0}, T{0, 1};   | ||||
| 
 | ||||
|     // Special tables (inefficient, but do we care for user input?)
 | ||||
|     Signature::Table logic(bool ff, bool ft, bool tf, bool tt) { | ||||
|  | @ -69,40 +57,13 @@ namespace gtsam { | |||
|         table = or_ | and_ | rows; | ||||
|         or_ = qi::lit("OR")[qi::_val = logic(false, true, true, true)]; | ||||
|         and_ = qi::lit("AND")[qi::_val = logic(false, false, false, true)]; | ||||
|         rows = +(row | true_ | false_); // only loads first of the rows under boost 1.42
 | ||||
|         rows = +(row | true_ | false_); | ||||
|         row = qi::double_ >> +("/" >> qi::double_); | ||||
|         true_ = qi::lit("T")[qi::_val = T]; | ||||
|         false_ = qi::lit("F")[qi::_val = F]; | ||||
|       } | ||||
|     } grammar; | ||||
| 
 | ||||
|     // Create simpler parsing function to avoid the issue of only parsing a single row
 | ||||
|     bool parse_table(const string& spec, Signature::Table& table) { | ||||
|       // check for OR, AND on whole phrase
 | ||||
|       It f = spec.begin(), l = spec.end(); | ||||
|       if (qi::parse(f, l, | ||||
|             qi::lit("OR")[ph::ref(table) = logic(false, true, true, true)]) || | ||||
|           qi::parse(f, l, | ||||
|             qi::lit("AND")[ph::ref(table) = logic(false, false, false, true)])) | ||||
|         return true; | ||||
| 
 | ||||
|       // tokenize into separate rows
 | ||||
|       istringstream iss(spec); | ||||
|       string token; | ||||
|       while (iss >> token) { | ||||
|         Signature::Row values; | ||||
|         It tf = token.begin(), tl = token.end(); | ||||
|         bool r = qi::parse(tf, tl, | ||||
|             qi::double_[push_back(ph::ref(values), qi::_1)] >> +("/" >> qi::double_[push_back(ph::ref(values), qi::_1)]) | | ||||
|             qi::lit("T")[ph::ref(values) = T] | | ||||
|             qi::lit("F")[ph::ref(values) = F] ); | ||||
|         if (!r) | ||||
|           return false; | ||||
|         table.push_back(values); | ||||
|       } | ||||
| 
 | ||||
|       return true; | ||||
|     } | ||||
|   } // \namespace parser
 | ||||
| 
 | ||||
|   ostream& operator <<(ostream &os, const Signature::Row &row) { | ||||
|  | @ -166,14 +127,11 @@ namespace gtsam { | |||
|   Signature& Signature::operator=(const string& spec) { | ||||
|     spec_.reset(spec); | ||||
|     Table table; | ||||
|     // NOTE: using simpler parse function to ensure boost back compatibility
 | ||||
| //    parser::It f = spec.begin(), l = spec.end();
 | ||||
|     bool success = //
 | ||||
| //        qi::phrase_parse(f, l, parser::grammar.table, qi::space, table); // using full grammar
 | ||||
|           parser::parse_table(spec, table); | ||||
|     parser::It f = spec.begin(), l = spec.end(); | ||||
|     bool success = | ||||
|         qi::phrase_parse(f, l, parser::grammar.table, qi::space, table); | ||||
|     if (success) { | ||||
|       for(Row& row: table) | ||||
|         normalize(row); | ||||
|       for (Row& row : table) normalize(row); | ||||
|       table_.reset(table); | ||||
|     } | ||||
|     return *this; | ||||
|  |  | |||
|  | @ -103,7 +103,7 @@ namespace gtsam { | |||
|     /** Add a parent */ | ||||
|     Signature& operator,(const DiscreteKey& parent); | ||||
| 
 | ||||
|     /** Add the CPT spec - Fails in boost 1.40 */ | ||||
|     /** Add the CPT spec */ | ||||
|     Signature& operator=(const std::string& spec); | ||||
| 
 | ||||
|     /** Add the CPT spec directly as a table */ | ||||
|  | @ -122,7 +122,6 @@ namespace gtsam { | |||
|   /**
 | ||||
|    * Helper function to create Signature objects | ||||
|    * example: Signature s(D % "99/1"); | ||||
|    * Uses string parser, which requires BOOST 1.42 or higher | ||||
|    */ | ||||
|   GTSAM_EXPORT Signature operator%(const DiscreteKey& key, const std::string& parent); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue