Rosetta Utilities  2014.35
Namespaces | Macros | Functions
Tag.cc File Reference

An object for reading/writing a simple xml-like language. More...

#include <utility/tag/Tag.hh>
#include <iostream>
#include <cstdio>
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_attribute.hpp>
#include <boost/spirit/include/classic_closure.hpp>
#include <boost/spirit/include/phoenix1_primitives.hpp>
#include <boost/spirit/include/phoenix1_operators.hpp>
#include <boost/spirit/include/phoenix1_functions.hpp>
#include <boost/spirit/include/phoenix1_binders.hpp>
#include <boost/spirit/include/phoenix1_casts.hpp>
#include <utility/string_util.hh>
#include <utility/exit.hh>
#include <utility/excn/Exceptions.hh>
#include <boost/foreach.hpp>
#include <boost/spirit/include/classic_position_iterator.hpp>
#include <boost/spirit/include/classic_functor_parser.hpp>
#include <platform/types.hh>
#include <string>
#include <sstream>

Namespaces

 utility
 unresizable vector whose size is known at compile time, which may be allocated on the stack, and which indexes from 1.
 
 utility::tag
 

Macros

#define foreach   BOOST_FOREACH
 

Functions

std::ostream & utility::tag::operator<< (std::ostream &out, Tag const &tag)
 
std::ostream & utility::tag::operator<< (std::ostream &out, TagCOP const &tag_ptr)
 

Detailed Description

An object for reading/writing a simple xml-like language.

Detailed:
Reads simple xml-like files, such as:

<loop_design> <params max_cycles="100"> <loop begin="A:10" end="A:15" length="5-6/"> </loop_design>

When read into a tag, the following code would be valid: std::ifstream fin; fin.open("loop_design.tag") TagCOP tag = Tag::create( fin ); runtime_assert( tag->getName() == "loop_design" ); int max_cycles = tag->getTag("params")->getOption<int>("max_cycles");

Files must obey the following grammar:

EBNF for a simple xml-like language:

top := !xml_schema_tag misc* tag misc* xml_schema_tag := <?xml (char - '?')* '?>' misc := comment_tag | (char - '<') comment_tag := '' tag := leaf_tag | branch_tag leaf_tag := '<' name options* '/>' option := name '=' ( name | quote ) name := (alnum | '_' | '-' | '.' | '*' | ',' )+ quote := '"' (alnum - '"')* '"' branch_tag := '<' name options* '>' ( tag | misc )* '</' name '>' *whitespace allowed between all tokens

Less complex than XML, also: no need to quote options, and text outside of tags is ignored. Implemented with the boost spirit library.

To debug the schema: 1) uncomment this:

#define BOOST_SPIRIT_DEBUG

2) add in the definition function below

BOOST_SPIRIT_DEBUG_NODE(rule_name);

for each rule defined.

NOTE: As of r53105, Rosetta doesn't compile with line 162 in boost_1_46_1/boost/spirit/home/debug/debug_node.hpp when BOOST_SPIRIT_DEBUG is enabled.

Author
Paul Murphy
(schema modified by Matthew O'Meara)

Macro Definition Documentation

#define foreach   BOOST_FOREACH

Variable Documentation

rule<Scanner,tag_closure::context_t> branch_tag
rule<Scanner,string_closure::context_t> close_tag
rule<Scanner> comment_tag
functor_parser<error_report_parser> error_report_p
vector< file_position > errors
rule<Scanner,name_and_options_closure::context_t> leaf_tag
rule<Scanner> misc
rule<Scanner,string_closure::context_t> name
rule<Scanner,name_and_options_closure::context_t> name_and_options
rule<Scanner,string_closure::context_t> name_or_quote
rule<Scanner,name_and_options_closure::context_t> open_tag
rule<Scanner,option_closure::context_t> option
rule<Scanner,options_closure::context_t> options
rule<Scanner,string_closure::context_t> quote
rule<Scanner,tag_closure::context_t> tag
rule<Scanner> top
member1 value

Referenced by utility::json_spirit::Config_map< String >::add(), utility::json_spirit::Semantic_actions< Value_type, Iter_type >::add_first(), utility::json_spirit::Semantic_actions< Value_type, Iter_type >::add_to_current(), utility::keys::KeyVector< K, T >::assign(), utility::keys::ClassKeyVector< K, T, C >::assign(), utility::keys::SmallKeyVector< PathVectorOptionKey, PathVectorOption >::assign(), utility::keys::ClassKeyMap< K, T, C >::assign(), utility::keys::SmallKeyMap< K, T >::assign(), numeric::clamp(), numeric::Polynomial_1d::eval(), utility::json_spirit::get_int(), utility::json_spirit::get_mArray(), utility::json_spirit::get_mObject(), basic::options::get_option(), utility::json_spirit::get_real(), utility::json_spirit::get_string(), utility::json_spirit::get_string_or_empty(), utility::heap::heap_up(), numeric::hsv_to_rgb(), utility::keys::ClassKeyMap< K, T, C >::insert(), utility::keys::SmallKeyMap< K, T >::insert(), utility::options::Option::is_group(), numeric::kdtree::is_legal_greater_than(), numeric::kdtree::is_legal_kdtree_below_node(), numeric::kdtree::is_legal_less_than(), numeric::isnan(), Kernel::kernel_precomputed(), numeric::MathTensor< Real >::MathTensor(), utility::keys::KeyVector< K, T >::operator=(), utility::keys::ClassKeyVector< K, T, C >::operator=(), utility::keys::SmallKeyVector< PathVectorOptionKey, PathVectorOption >::operator=(), utility::libsvm::Svm_rosetta::predict(), utility::libsvm::Svm_rosetta::predict_probability(), numeric::interpolation::Histogram< typename, typename >::read_from_db(), utility::json_spirit::read_mArray(), basic::read_metric_value_scalar(), basic::read_metric_value_vector1(), utility::json_spirit::read_mObject(), utility::json_spirit::read_string(), utility::json_spirit::read_string_or_throw(), basic::options::realafteroption(), numeric::expression_parser::ArithmeticScanner::scan_literal(), utility::SimulateMPI::set_mpi_rank(), basic::options::set_option(), numeric::interpolation::Histogram< typename, typename >::set_params(), numeric::expression_parser::LiteralExpression::set_value(), numeric::expression_parser::VariableExpression::set_value(), utility::tag::Tag::setOption(), and utility::json_spirit::write_stream().

rule<Scanner> xml_schema_tag