From: Braden M. <br...@us...> - 2006-03-12 07:38:48
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15853/src/libopenvrml/openvrml Modified Files: Vrml97Parser.g X3DVrmlParser.g browser.cpp browser.h Log Message: Store scene metadata (in X3D scenes). Index: X3DVrmlParser.g =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/X3DVrmlParser.g,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** X3DVrmlParser.g 9 Mar 2006 09:07:17 -0000 1.16 --- X3DVrmlParser.g 12 Mar 2006 07:38:44 -0000 1.17 *************** *** 227,231 **** vrmlScene[const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes] options { defaultErrorHandler=false; } { --- 227,232 ---- vrmlScene[const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes, ! std::map<std::string, std::string> & meta_data] options { defaultErrorHandler=false; } { *************** *** 235,239 **** } : profileStatement ! (componentStatement)* (metaStatement)* (statement[scene, nodes, root_scope])* ; --- 236,240 ---- } : profileStatement ! (componentStatement)* (metaStatement[meta_data])* (statement[scene, nodes, root_scope])* ; *************** *** 250,258 **** ; ! metaStatement { std::string key, value; } ! : KEYWORD_META key=stringValue value=stringValue ; --- 251,261 ---- ; ! metaStatement[std::map<std::string, std::string> & meta_data] { std::string key, value; } ! : KEYWORD_META key=stringValue value=stringValue { ! meta_data[key] = value; ! } ; Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.143 retrieving revision 1.144 diff -C2 -d -r1.143 -r1.144 *** browser.cpp 9 Mar 2006 09:07:17 -0000 1.143 --- browser.cpp 12 Mar 2006 07:38:44 -0000 1.144 *************** *** 5582,5585 **** --- 5582,5586 ---- * @param[in] scene a scene. * @param[out] nodes the root nodes. + * @param[out] meta the scene metadata. * * @exception openvrml::bad_media_type *************** *** 5591,5595 **** const std::string & type, const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes) { try { --- 5592,5597 ---- const std::string & type, const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes, ! std::map<std::string, std::string> & meta) { try { *************** *** 5601,5609 **** Vrml97Scanner scanner(in); Vrml97Parser parser(scanner, uri); ! parser.vrmlScene(scene, nodes); } else if (iequals(type, x3d_vrml_media_type)) { X3DVrmlScanner scanner(in); X3DVrmlParser parser(scanner, uri); ! parser.vrmlScene(scene, nodes); } else { throw bad_media_type(type); --- 5603,5611 ---- Vrml97Scanner scanner(in); Vrml97Parser parser(scanner, uri); ! parser.vrmlScene(scene, nodes, meta); } else if (iequals(type, x3d_vrml_media_type)) { X3DVrmlScanner scanner(in); X3DVrmlParser parser(scanner, uri); ! parser.vrmlScene(scene, nodes, meta); } else { throw bad_media_type(type); *************** *** 5653,5662 **** // ! // We don't actually do anything with this; but the parser ! // wants it. // ! std::vector<boost::intrusive_ptr<node> > nodes; ! parse_vrml(*in, in->url(), in->type(), *this->scene_, nodes); shared_ptr<openvrml::proto_node_class> proto_node_class; --- 5655,5666 ---- // ! // We don't actually do anything with these; but the parser ! // wants them. // ! vector<boost::intrusive_ptr<node> > nodes; ! std::map<string, string> meta; ! parse_vrml(*in, in->url(), in->type(), ! *this->scene_, nodes, meta); shared_ptr<openvrml::proto_node_class> proto_node_class; *************** *** 8267,8271 **** try { assert(this->scene_); ! parse_vrml(in, stream_id, type, *this->scene_, nodes); } catch (openvrml::bad_media_type & ex) { throw std::invalid_argument(ex.what()); --- 8271,8276 ---- try { assert(this->scene_); ! std::map<string, string> meta; ! parse_vrml(in, stream_id, type, *this->scene_, nodes, meta); } catch (openvrml::bad_media_type & ex) { throw std::invalid_argument(ex.what()); *************** *** 8902,8905 **** --- 8907,8926 ---- */ + /** + * @internal + * + * @var boost::mutex openvrml::scene::meta_mutex_ + * + * @brief Mutex protecting @a meta_. + */ + + /** + * @internal + * + * @var std::map<std::string, std::string> openvrml::scene::meta_ + * + * @brief Scene metadata map. + */ + namespace { *************** *** 9107,9114 **** { boost::recursive_mutex::scoped_lock nodes_lock(this->nodes_mutex_); ! boost::mutex::scoped_lock url_lock(this->url_mutex_); this->url_ = in.url(); ! parse_vrml(in, in.url(), in.type(), *this, this->nodes_); } --- 9128,9137 ---- { boost::recursive_mutex::scoped_lock nodes_lock(this->nodes_mutex_); ! boost::mutex::scoped_lock ! url_lock(this->url_mutex_), ! meta_lock(this->meta_mutex_); this->url_ = in.url(); ! parse_vrml(in, in.url(), in.type(), *this, this->nodes_, this->meta_); } *************** *** 9137,9140 **** --- 9160,9228 ---- /** + * @brief Get metadata. + * + * @param[in] key metadata key. + * + * @return the metadata value associated with @p key. + * + * @exception std::invalid_argument if there is no value associated with + * @p key. + * @exception std::bad_alloc if memory allocation fails. + */ + const std::string openvrml::scene::meta(const std::string & key) const + OPENVRML_THROW2(std::invalid_argument, std::bad_alloc) + { + boost::mutex::scoped_lock lock(this->meta_mutex_); + + using std::map; + using std::string; + + const map<string, string>::const_iterator pos = this->meta_.find(key); + if (pos == this->meta_.end()) { + throw std::invalid_argument("no metadata value associated with \"" + + key + "\""); + } + return pos->second; + } + + /** + * @brief Set metadata. + * + * @param[in] key metadata key. + * @param[in] value metadata value. + * + * @exception std::bad_alloc if memory allocation fails. + */ + void openvrml::scene::meta(const std::string & key, const std::string & value) + OPENVRML_THROW1(std::bad_alloc) + { + boost::mutex::scoped_lock lock(this->meta_mutex_); + this->meta_[key] = value; + } + + /** + * @brief Get the metadata keys. + * + * @return the metadata keys. + */ + const std::vector<std::string> openvrml::scene::meta_keys() const + OPENVRML_THROW1(std::bad_alloc) + { + boost::mutex::scoped_lock lock(this->meta_mutex_); + + using std::map; + using std::string; + using std::vector; + + vector<string> result; + for (map<string, string>::const_iterator entry = this->meta_.begin(); + entry != this->meta_.end(); + ++entry) { + result.push_back(entry->first); + } + return result; + } + + /** * @brief Root nodes for the scene. * Index: browser.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.h,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** browser.h 9 Mar 2006 05:19:17 -0000 1.49 --- browser.h 12 Mar 2006 07:38:44 -0000 1.50 *************** *** 364,367 **** --- 364,370 ---- std::string url_; + mutable boost::mutex meta_mutex_; + std::map<std::string, std::string> meta_; + public: explicit scene(openvrml::browser & browser, scene * parent = 0) *************** *** 375,378 **** --- 378,387 ---- void load(resource_istream & in); void initialize(double timestamp) OPENVRML_THROW1(std::bad_alloc); + const std::string meta(const std::string & key) const + OPENVRML_THROW2(std::invalid_argument, std::bad_alloc); + void meta(const std::string & key, const std::string & value) + OPENVRML_THROW1(std::bad_alloc); + const std::vector<std::string> meta_keys() const + OPENVRML_THROW1(std::bad_alloc); const std::vector<boost::intrusive_ptr<node> > & nodes() const OPENVRML_NOTHROW; Index: Vrml97Parser.g =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/Vrml97Parser.g,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** Vrml97Parser.g 9 Mar 2006 09:07:17 -0000 1.58 --- Vrml97Parser.g 12 Mar 2006 07:38:44 -0000 1.59 *************** *** 614,620 **** vrmlScene[const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes] options { defaultErrorHandler=false; } { std::auto_ptr<openvrml::scope> root_scope_auto_ptr = create_root_scope(scene.browser(), this->uri); --- 614,623 ---- vrmlScene[const openvrml::scene & scene, ! std::vector<boost::intrusive_ptr<openvrml::node> > & nodes, ! std::map<std::string, std::string> & meta_data] options { defaultErrorHandler=false; } { + boost::ignore_unused_variable_warning(meta_data); + std::auto_ptr<openvrml::scope> root_scope_auto_ptr = create_root_scope(scene.browser(), this->uri); |