From: Braden M. <br...@us...> - 2006-10-23 06:39:33
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31812/src/libopenvrml/openvrml Modified Files: browser.cpp node.cpp Log Message: Moved the URI grammar to private.h so that it can be used by multiple implementation files. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.192 retrieving revision 1.193 diff -C2 -d -r1.192 -r1.193 *** browser.cpp 31 Aug 2006 06:45:30 -0000 1.192 --- browser.cpp 23 Oct 2006 06:39:28 -0000 1.193 *************** *** 42,47 **** # include <boost/mpl/for_each.hpp> # include <boost/ptr_container/ptr_map.hpp> - # include <boost/spirit.hpp> - # include <boost/spirit/phoenix.hpp> # include <boost/thread/thread.hpp> # include <boost/utility.hpp> --- 42,45 ---- *************** *** 2845,3445 **** - template <typename SpiritActor, typename Iterator1, typename Iterator2> - class assign_iterators_base { - SpiritActor actor_; - Iterator1 begin_; - Iterator2 end_; - - public: - typedef assign_iterators_base<SpiritActor, Iterator1, Iterator2> - this_type; - - assign_iterators_base(const SpiritActor & actor, - const Iterator1 & begin, - const Iterator2 & end): - actor_(actor), - begin_(begin), - end_(end) - {} - - template <typename T> - struct result { - typedef void type; - }; - - template <typename Tuple> - typename phoenix::actor_result<this_type, Tuple>::type - eval(Tuple) const - { - this->actor_(this->begin_(), this->end_()); - } - }; - - template <typename SpiritActor, typename Iterator1, typename Iterator2> - phoenix::actor<assign_iterators_base<SpiritActor, Iterator1, Iterator2> > - assign_iterators(const SpiritActor & actor, - const Iterator1 & begin, - const Iterator2 & end) - { - return assign_iterators_base<SpiritActor, Iterator1, Iterator2>(actor, - begin, - end); - } - - class OPENVRML_LOCAL null_actions { - public: - struct null_action { - template <typename Iterator> - void operator()(const Iterator &, const Iterator &) const - {} - }; - - null_action scheme, scheme_specific_part, userinfo, host, port, - authority, path, query, fragment; - }; - - - struct OPENVRML_LOCAL uri_reserved_parser : - public boost::spirit::char_parser<uri_reserved_parser> { - - typedef uri_reserved_parser self_t; - - template <typename CharT> - bool test(CharT ch) const - { - return ch == ';' - || ch == '/' - || ch == '?' - || ch == ':' - || ch == '@' - || ch == '&' - || ch == '=' - || ch == '+' - || ch == '$' - || ch == ','; - } - }; - - const uri_reserved_parser uri_reserved_p = uri_reserved_parser(); - - - struct OPENVRML_LOCAL uri_unreserved_parser : - public boost::spirit::char_parser<uri_unreserved_parser> { - - typedef uri_unreserved_parser self_t; - - template <typename CharT> - bool test(CharT ch) const - { - using namespace std; - return isalnum(char_traits<CharT>::to_int_type(ch)) - || ch == '-' - || ch == '_' - || ch == '.' - || ch == '!' - || ch == '~' - || ch == '*' - || ch == '\'' - || ch == '(' - || ch == ')'; - } - }; - - const uri_unreserved_parser uri_unreserved_p = uri_unreserved_parser(); - - - struct OPENVRML_LOCAL uric_grammar : - public boost::spirit::grammar<uric_grammar> { - - template <typename ScannerT> - struct definition { - typedef boost::spirit::rule<ScannerT> rule_type; - - rule_type uric, escaped; - - definition(const uric_grammar & self); - - const boost::spirit::rule<ScannerT> & start() const; - }; - }; - - template <typename ScannerT> - uric_grammar::definition<ScannerT>::definition(const uric_grammar &) - { - using namespace boost::spirit; - - uric - = uri_reserved_p - | uri_unreserved_p - | escaped - ; - - escaped - = '%' >> xdigit_p >> xdigit_p - ; - } - - template <typename ScannerT> - const boost::spirit::rule<ScannerT> & - uric_grammar::definition<ScannerT>::start() const - { - return this->uric; - } - - - template <typename Actions = null_actions> - struct uri_authority_grammar : - public boost::spirit::grammar<uri_authority_grammar<Actions> > { - - template <typename ScannerT> - struct definition { - struct server_closure : - boost::spirit::closure<server_closure, - typename ScannerT::iterator_t, - typename ScannerT::iterator_t> { - typename server_closure::member1 userinfo_begin; - typename server_closure::member2 userinfo_end; - }; - - typedef boost::spirit::rule<ScannerT> rule_type; - typedef boost::spirit::rule<ScannerT, - typename server_closure::context_t> - server_rule_type; - - rule_type authority; - rule_type reg_name; - server_rule_type server; - rule_type userinfo; - rule_type hostport; - rule_type host; - rule_type hostname; - rule_type domainlabel; - rule_type toplabel; - rule_type ipv4address; - rule_type port; - rule_type escaped; - - explicit definition(const uri_authority_grammar & self); - - const boost::spirit::rule<ScannerT> & start() const; - }; - - const Actions & actions; - - explicit uri_authority_grammar(const Actions & actions = Actions()); - }; - - template <typename Actions> - template <typename ScannerT> - uri_authority_grammar<Actions>::definition<ScannerT>:: - definition(const uri_authority_grammar & self) - { - using namespace boost::spirit; - using namespace phoenix; - - authority - = (server | reg_name)[ self.actions.authority ] - ; - - reg_name - = +( uri_unreserved_p - | escaped - | '$' - | ',' - | ';' - | ':' - | '@' - | '&' - | '=' - | '+' - ) - ; - - server - = !( - !( - userinfo[ - server.userinfo_begin = arg1, - server.userinfo_end = arg2 - ] >> '@' - )[ - assign_iterators(self.actions.userinfo, - server.userinfo_begin, - server.userinfo_end) - ] - >> hostport - ) - ; - - userinfo - = *( uri_unreserved_p - | escaped - | ';' - | ':' - | '&' - | '=' - | '+' - | '$' - | ',' - ) - ; - - hostport - = host >> !(':' >> port) - ; - - host - = (hostname | ipv4address)[ self.actions.host ] - ; - - hostname - = *(domainlabel >> '.') >> toplabel >> !ch_p('.') - ; - - domainlabel - = alnum_p >> *(*ch_p('-') >> alnum_p) - ; - - toplabel - = alpha_p >> *(*ch_p('-') >> alnum_p) - ; - - ipv4address - = +digit_p >> '.' >> +digit_p >> '.' >> +digit_p >> '.' - >> +digit_p - ; - - port - = (*digit_p)[ self.actions.port ] - ; - - escaped - = '%' >> xdigit_p >> xdigit_p - ; - } - - template <typename Actions> - template <typename ScannerT> - const boost::spirit::rule<ScannerT> & - uri_authority_grammar<Actions>::definition<ScannerT>::start() const - { - return this->authority; - } - - template <typename Actions> - uri_authority_grammar<Actions>:: - uri_authority_grammar(const Actions & actions): - actions(actions) - {} - - template <typename Actions> - struct uri_abs_path_grammar : - public boost::spirit::grammar<uri_abs_path_grammar<Actions> > { - - template <typename ScannerT> - struct definition { - typedef boost::spirit::rule<ScannerT> rule_type; - - rule_type abs_path; - rule_type path_segments; - rule_type segment; - rule_type param; - rule_type pchar; - rule_type query; - rule_type escaped; - - explicit definition(const uri_abs_path_grammar & self); - - const boost::spirit::rule<ScannerT> & start() const; - }; - - const Actions & actions; - - explicit uri_abs_path_grammar(const Actions & actions = Actions()); - }; - - template <typename Actions> - template <typename ScannerT> - uri_abs_path_grammar<Actions>::definition<ScannerT>:: - definition(const uri_abs_path_grammar & self) - { - using namespace boost::spirit; - using namespace phoenix; - - abs_path - = ('/' >> path_segments)[ self.actions.path ] - ; - - path_segments - = segment >> *('/' >> segment) - ; - - segment - = *pchar >> *(';' >> param) - ; - - param - = *pchar - ; - - pchar - = uri_unreserved_p - | escaped - | ':' - | '@' - | '&' - | '=' - | '+' - | '$' - | ',' - ; - - escaped - = '%' >> xdigit_p >> xdigit_p - ; - } - - template <typename Actions> - template <typename ScannerT> - const boost::spirit::rule<ScannerT> & - uri_abs_path_grammar<Actions>::definition<ScannerT>::start() const - { - return this->abs_path; - } - - template <typename Actions> - uri_abs_path_grammar<Actions>:: - uri_abs_path_grammar(const Actions & actions): - actions(actions) - {} - - - template <typename Actions = null_actions> - struct absolute_uri_grammar : - public boost::spirit::grammar<absolute_uri_grammar<Actions> > { - - template <typename ScannerT> - struct definition { - struct absolute_uri_closure : - boost::spirit::closure<absolute_uri_closure, - typename ScannerT::iterator_t, - typename ScannerT::iterator_t> { - typename absolute_uri_closure::member1 scheme_begin; - typename absolute_uri_closure::member2 scheme_end; - }; - - struct server_closure : - boost::spirit::closure<server_closure, - typename ScannerT::iterator_t, - typename ScannerT::iterator_t> { - typename server_closure::member1 userinfo_begin; - typename server_closure::member2 userinfo_end; - }; - - typedef boost::spirit::rule<ScannerT> rule_type; - typedef boost::spirit::rule< - ScannerT, - typename absolute_uri_closure::context_t> - absolute_uri_rule_type; - typedef boost::spirit::rule<ScannerT, - typename server_closure::context_t> - server_rule_type; - - absolute_uri_rule_type absolute_uri; - rule_type scheme; - rule_type hier_part; - rule_type opaque_part; - rule_type net_path; - uri_abs_path_grammar<Actions> abs_path; - uri_authority_grammar<Actions> authority; - rule_type query; - rule_type uric_no_slash; - uric_grammar uric; - - explicit definition(const absolute_uri_grammar & self); - - const absolute_uri_rule_type & start() const; - }; - - const Actions & actions; - - explicit absolute_uri_grammar(const Actions & actions = Actions()); - }; - - template <typename Actions> - template <typename ScannerT> - absolute_uri_grammar<Actions>::definition<ScannerT>:: - definition(const absolute_uri_grammar & self): - abs_path(self.actions), - authority(self.actions) - { - using namespace boost::spirit; - using namespace phoenix; - - absolute_uri - = ( - scheme[ - absolute_uri.scheme_begin = arg1, - absolute_uri.scheme_end = arg2 - ] >> ':' - )[ - assign_iterators(self.actions.scheme, - absolute_uri.scheme_begin, - absolute_uri.scheme_end) - ] >> (hier_part | opaque_part)[ - self.actions.scheme_specific_part - ] - ; - - scheme - = (alpha_p >> *(alpha_p | digit_p | '+' | '-' | '.')) - ; - - hier_part - = (net_path | abs_path) >> !('?' >> query) - ; - - opaque_part - = uric_no_slash >> *uric - ; - - uric_no_slash - = uric - '/' - ; - - net_path - = "//" >> authority >> !abs_path - ; - - query - = (*uric)[ self.actions.query ] - ; - - } - - template <typename Actions> - template <typename ScannerT> - const typename absolute_uri_grammar<Actions>:: - template definition<ScannerT>::absolute_uri_rule_type & - absolute_uri_grammar<Actions>::definition<ScannerT>::start() const - { - return this->absolute_uri; - } - - template <typename Actions> - absolute_uri_grammar<Actions>:: - absolute_uri_grammar(const Actions & actions): - actions(actions) - {} - - - template <typename Actions = null_actions> - struct uri_grammar : public boost::spirit::grammar<uri_grammar<Actions> > { - - template <typename ScannerT> - struct definition { - typedef boost::spirit::rule<ScannerT> rule_type; - - rule_type uri_reference; - absolute_uri_grammar<Actions> absolute_uri; - rule_type relative_uri; - rule_type net_path; - uri_abs_path_grammar<Actions> abs_path; - rule_type rel_path; - rule_type rel_segment; - uri_authority_grammar<Actions> authority; - rule_type query; - rule_type fragment; - uric_grammar uric; - rule_type escaped; - - explicit definition(const uri_grammar & self); - - const boost::spirit::rule<ScannerT> & start() const; - }; - - const Actions & actions; - - explicit uri_grammar(const Actions & actions = Actions()); - }; - - - template <typename Actions> - uri_grammar<Actions>::uri_grammar(const Actions & actions): - actions(actions) - {} - - template <typename Actions> - template <typename ScannerT> - uri_grammar<Actions>::definition<ScannerT>:: - definition(const uri_grammar & self): - absolute_uri(self.actions), - abs_path(self.actions), - authority(self.actions) - { - using namespace boost::spirit; - using namespace phoenix; - - BOOST_SPIRIT_DEBUG_NODE(uri_reference); - BOOST_SPIRIT_DEBUG_NODE(absolute_uri); - BOOST_SPIRIT_DEBUG_NODE(net_path); - BOOST_SPIRIT_DEBUG_NODE(abs_path); - BOOST_SPIRIT_DEBUG_NODE(rel_path); - BOOST_SPIRIT_DEBUG_NODE(rel_segment); - BOOST_SPIRIT_DEBUG_NODE(authority); - BOOST_SPIRIT_DEBUG_NODE(query); - BOOST_SPIRIT_DEBUG_NODE(fragment); - BOOST_SPIRIT_DEBUG_NODE(uric); - BOOST_SPIRIT_DEBUG_NODE(escaped); - - uri_reference - = !(absolute_uri | relative_uri) >> !('#' >> fragment) - ; - relative_uri - = (net_path | abs_path | rel_path) >> !('?' >> query) - ; - - net_path - = "//" >> authority >> !abs_path - ; - - rel_path - = (rel_segment >> !abs_path)[ self.actions.path ] - ; - - rel_segment - = +( uri_unreserved_p - | escaped - | ';' - | '@' - | '&' - | '=' - | '+' - | '$' - | ',' - ) - ; - - query - = (*uric)[ self.actions.query ] - ; - - fragment - = (*uric)[ self.actions.fragment ] - ; - - escaped - = '%' >> xdigit_p >> xdigit_p - ; - } - - template <typename Actions> - template <typename ScannerT> - const boost::spirit::rule<ScannerT> & - uri_grammar<Actions>::definition<ScannerT>::start() const - { - return this->uri_reference; - } - class OPENVRML_LOCAL uri { class actions { --- 2843,2846 ---- *************** *** 3717,3721 **** actions a(*this); ! uri_grammar<actions> g(a); string::const_iterator begin = this->str_.begin(); --- 3118,3122 ---- actions a(*this); ! openvrml_::uri_grammar<actions> g(a); string::const_iterator begin = this->str_.begin(); *************** *** 5504,5672 **** /** - * @class openvrml::node_metatype_id - * - * @brief Identifier for @c node_metatype%s. - * - * @c node_metatype identifiers take the following form: - * - * <pre> - * absolute-uri ['#' proto-id ['#' proto-id [...]]] - * </pre> - * - * A @c node_metatype identifier is basically like an absolute URI; - * except the fragment identifier syntax has been extended to support referring - * to nested @c PROTO%s. - * - * For example, supposing the following VRML world resides at - * <code>%http://example.com/example.wrl</code>: - * - * <pre> - * \#VRML V2.0 utf8 - * - * PROTO Outer [] { - * PROTO Inner [] { Group {} } - * Group {} - * } - * </pre> - * - * The @c node_metatype_id string for @c Outer would be - * <code>%http://example.com/example.wrl\#Outer</code>; and for @c Inner, - * <code>%http://example.com/example.wrl\#Outer\#Inner</code>. - */ - - /** - * @internal - * - * @var std::string openvrml::node_metatype_id::id_ - * - * @brief The identifier string. - */ - - namespace { - - struct OPENVRML_LOCAL node_metatype_id_grammar : - public boost::spirit::grammar<node_metatype_id_grammar> { - - template <typename ScannerT> - struct definition { - typedef boost::spirit::rule<ScannerT> rule_type; - - rule_type node_metatype_id; - absolute_uri_grammar<> absolute_uri; - uric_grammar uric; - - definition(const node_metatype_id_grammar & self); - - const boost::spirit::rule<ScannerT> & start() const; - }; - }; - - template <typename ScannerT> - node_metatype_id_grammar::definition<ScannerT>:: - definition(const node_metatype_id_grammar &) - { - node_metatype_id - = absolute_uri >> *('#' >> *uric) - ; - } - - template <typename ScannerT> - const boost::spirit::rule<ScannerT> & - node_metatype_id_grammar::definition<ScannerT>::start() const - { - return this->node_metatype_id; - } - } - - /** - * @brief Construct from a <code>const char *</code>. - * - * @param[in] id the identifier. - * - * @exception std::invalid_argument if @p id is not a valid - * @c node_metatype identifier. - * @exception std::bad_alloc if memory allocation fails. - * - * @todo Need to make sure the fragment part is valid. - */ - openvrml::node_metatype_id::node_metatype_id(const char * id) - OPENVRML_THROW2(std::invalid_argument, std::bad_alloc): - id_(id) - { - using namespace boost::spirit; - - node_metatype_id_grammar g; - if (!parse(this->id_.begin(), this->id_.end(), g, space_p).full) { - throw std::invalid_argument('<' + this->id_ + "> is not a valid " - "node_metatype identifier"); - } - } - - /** - * @brief Construct from a @c std::string. - * - * @param[in] id the identifier. - * - * @exception std::invalid_argument if @p id is not a valid - * @c node_metatype identifier. - * @exception std::bad_alloc if memory allocation fails. - * - * @todo Need to make sure the fragment part is valid. - */ - openvrml::node_metatype_id::node_metatype_id(const std::string & id) - OPENVRML_THROW2(std::invalid_argument, std::bad_alloc): - id_(id) - { - using namespace boost::spirit; - - node_metatype_id_grammar g; - if (!parse(this->id_.begin(), this->id_.end(), g, space_p).full) { - throw std::invalid_argument('<' + this->id_ + "> is not a valid " - "node_metatype identifier"); - } - } - - /** - * @brief Convert to a @c std::string. - * - * @return the @c node_metatype identifier as a @c std::string. - */ - openvrml::node_metatype_id::operator std::string() const - { - return this->id_; - } - - /** - * @relates openvrml::node_metatype_id - * - * @param[in] lhs - * @param[in] rhs - * - * @return @c true if @p lhs and @p rhs are equal, @c false otherwise. - */ - bool openvrml::operator==(const node_metatype_id & lhs, - const node_metatype_id & rhs) - OPENVRML_NOTHROW - { - return lhs.id_ == rhs.id_; - } - - /** - * @relates openvrml::node_metatype_id - * - * @param[in] lhs - * @param[in] rhs - * - * @return @c true if @p lhs and @p rhs are not equal, @c false otherwise. - */ - bool openvrml::operator!=(const node_metatype_id & lhs, - const node_metatype_id & rhs) - OPENVRML_NOTHROW - { - return !(lhs == rhs); - } - - - /** * @class openvrml::browser * --- 4905,4908 ---- Index: node.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/node.cpp,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** node.cpp 6 Aug 2006 06:45:24 -0000 1.88 --- node.cpp 23 Oct 2006 06:39:28 -0000 1.89 *************** *** 541,544 **** --- 541,709 ---- /** + * @class openvrml::node_metatype_id + * + * @brief Identifier for @c node_metatype%s. + * + * @c node_metatype identifiers take the following form: + * + * <pre> + * absolute-uri ['#' proto-id ['#' proto-id [...]]] + * </pre> + * + * A @c node_metatype identifier is basically like an absolute URI; + * except the fragment identifier syntax has been extended to support referring + * to nested @c PROTO%s. + * + * For example, supposing the following VRML world resides at + * <code>%http://example.com/example.wrl</code>: + * + * <pre> + * \#VRML V2.0 utf8 + * + * PROTO Outer [] { + * PROTO Inner [] { Group {} } + * Group {} + * } + * </pre> + * + * The @c node_metatype_id string for @c Outer would be + * <code>%http://example.com/example.wrl\#Outer</code>; and for @c Inner, + * <code>%http://example.com/example.wrl\#Outer\#Inner</code>. + */ + + /** + * @internal + * + * @var std::string openvrml::node_metatype_id::id_ + * + * @brief The identifier string. + */ + + namespace { + + struct OPENVRML_LOCAL node_metatype_id_grammar : + public boost::spirit::grammar<node_metatype_id_grammar> { + + template <typename ScannerT> + struct definition { + typedef boost::spirit::rule<ScannerT> rule_type; + + rule_type node_metatype_id; + openvrml_::absolute_uri_grammar<> absolute_uri; + openvrml_::uric_grammar uric; + + definition(const node_metatype_id_grammar & self); + + const boost::spirit::rule<ScannerT> & start() const; + }; + }; + + template <typename ScannerT> + node_metatype_id_grammar::definition<ScannerT>:: + definition(const node_metatype_id_grammar &) + { + node_metatype_id + = absolute_uri >> *('#' >> *uric) + ; + } + + template <typename ScannerT> + const boost::spirit::rule<ScannerT> & + node_metatype_id_grammar::definition<ScannerT>::start() const + { + return this->node_metatype_id; + } + } + + /** + * @brief Construct from a <code>const char *</code>. + * + * @param[in] id the identifier. + * + * @exception std::invalid_argument if @p id is not a valid + * @c node_metatype identifier. + * @exception std::bad_alloc if memory allocation fails. + * + * @todo Need to make sure the fragment part is valid. + */ + openvrml::node_metatype_id::node_metatype_id(const char * id) + OPENVRML_THROW2(std::invalid_argument, std::bad_alloc): + id_(id) + { + using namespace boost::spirit; + + node_metatype_id_grammar g; + if (!parse(this->id_.begin(), this->id_.end(), g, space_p).full) { + throw std::invalid_argument('<' + this->id_ + "> is not a valid " + "node_metatype identifier"); + } + } + + /** + * @brief Construct from a @c std::string. + * + * @param[in] id the identifier. + * + * @exception std::invalid_argument if @p id is not a valid + * @c node_metatype identifier. + * @exception std::bad_alloc if memory allocation fails. + * + * @todo Need to make sure the fragment part is valid. + */ + openvrml::node_metatype_id::node_metatype_id(const std::string & id) + OPENVRML_THROW2(std::invalid_argument, std::bad_alloc): + id_(id) + { + using namespace boost::spirit; + + node_metatype_id_grammar g; + if (!parse(this->id_.begin(), this->id_.end(), g, space_p).full) { + throw std::invalid_argument('<' + this->id_ + "> is not a valid " + "node_metatype identifier"); + } + } + + /** + * @brief Convert to a @c std::string. + * + * @return the @c node_metatype identifier as a @c std::string. + */ + openvrml::node_metatype_id::operator std::string() const + { + return this->id_; + } + + /** + * @relates openvrml::node_metatype_id + * + * @param[in] lhs + * @param[in] rhs + * + * @return @c true if @p lhs and @p rhs are equal, @c false otherwise. + */ + bool openvrml::operator==(const node_metatype_id & lhs, + const node_metatype_id & rhs) + OPENVRML_NOTHROW + { + return lhs.id_ == rhs.id_; + } + + /** + * @relates openvrml::node_metatype_id + * + * @param[in] lhs + * @param[in] rhs + * + * @return @c true if @p lhs and @p rhs are not equal, @c false otherwise. + */ + bool openvrml::operator!=(const node_metatype_id & lhs, + const node_metatype_id & rhs) + OPENVRML_NOTHROW + { + return !(lhs == rhs); + } + + + /** * @class openvrml::node_metatype * |