|
From: Braden M. <br...@us...> - 2006-02-12 04:21:01
|
Update of /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4821/src/libopenvrml/openvrml Modified Files: Vrml97Parser.g browser.cpp browser.h Log Message: Removed externproto_node_type::owning_ptr_to_class, as this created a reference cycle. Index: browser.cpp =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.cpp,v retrieving revision 1.125 retrieving revision 1.126 diff -C2 -d -r1.125 -r1.126 *** browser.cpp 12 Feb 2006 03:15:40 -0000 1.125 --- browser.cpp 12 Feb 2006 04:20:51 -0000 1.126 *************** *** 2256,2259 **** --- 2256,2261 ---- mutable externproto_node_types externproto_node_types_; + boost::scoped_ptr<boost::thread> load_proto_thread_; + public: externproto_node_class(openvrml::scene & scene, *************** *** 2277,2281 **** mutable boost::mutex mutex_; openvrml::node_interface_set interfaces_; - boost::shared_ptr<openvrml::node_class> owning_ptr_to_class_; typedef std::vector<boost::intrusive_ptr<openvrml::externproto_node> > --- 2279,2282 ---- *************** *** 2294,2301 **** virtual ~externproto_node_type() throw (); - void set_owning_ptr_to_class( - const boost::shared_ptr<openvrml::node_class> & node_class) - throw (); - void set_proto_node_type(openvrml::proto_node_class & proto_node_class) throw (std::bad_alloc); --- 2295,2298 ---- *************** *** 5622,5630 **** const std::vector<std::string> & uris) throw (boost::thread_resource_error): ! node_class(scene.browser()) ! { ! boost::function0<void> f = load_proto(*this, scene, uris); ! boost::thread t(f); ! } /** --- 5619,5627 ---- const std::vector<std::string> & uris) throw (boost::thread_resource_error): ! node_class(scene.browser()), ! load_proto_thread_( ! new boost::thread( ! boost::function0<void>(load_proto(*this, scene, uris)))) ! {} /** *************** *** 5632,5636 **** */ externproto_node_class::~externproto_node_class() throw () ! {} const boost::shared_ptr<openvrml::node_type> --- 5629,5635 ---- */ externproto_node_class::~externproto_node_class() throw () ! { ! this->load_proto_thread_->join(); ! } const boost::shared_ptr<openvrml::node_type> *************** *** 5693,5713 **** {} - /** - * @brief Set the owning pointer to the <code>openvrml::node_class</code>. - * - * The base <code>openvrml::node_type</code> simply holds a reference to - * the <code>openvrml::node_class</code>. If we get an EXTERNPROTO with no - * implementation, we need to store an owning pointer to the - * <code>node_class</code> here. See the comment in - * <code>Vrml97Parser::externproto</code> for details. - */ - void externproto_node_type::set_owning_ptr_to_class( - const boost::shared_ptr<openvrml::node_class> & node_class) throw () - { - assert(node_class); - assert(!this->owning_ptr_to_class_); - this->owning_ptr_to_class_ = node_class; - } - void externproto_node_type:: --- 5692,5695 ---- *************** *** 6957,6960 **** --- 6939,6957 ---- /** + * @brief Destroy. + */ + openvrml::browser::node_class_map::~node_class_map() throw () + { + # ifndef NDEBUG + for (map_t::const_iterator entry = this->map_.begin(); + entry != this->map_.end(); + ++entry) { + assert(entry->second.unique() + && "shared_ptr<node_class> was not unique when destroying the browser's node_class_map"); + } + # endif + } + + /** * @fn openvrml::browser::node_class_map::node_class_map(const node_class_map &) * Index: browser.h =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/browser.h,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** browser.h 14 Jan 2006 06:42:28 -0000 1.41 --- browser.h 12 Feb 2006 04:20:51 -0000 1.42 *************** *** 208,211 **** --- 208,212 ---- public: node_class_map(); + ~node_class_map() throw (); node_class_map & operator=(const node_class_map & ncm); Index: Vrml97Parser.g =================================================================== RCS file: /cvsroot/openvrml/openvrml/src/libopenvrml/openvrml/Vrml97Parser.g,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** Vrml97Parser.g 12 Dec 2005 19:23:08 -0000 1.45 --- Vrml97Parser.g 12 Feb 2006 04:20:51 -0000 1.46 *************** *** 977,1004 **** new externproto_node_class(scene, alt_uris)); ! for (vector<string>::const_iterator resource_id = ! alt_uris.begin(); ! resource_id != alt_uris.end(); ! ++resource_id) { ! const ::uri absolute_uri = !relative(::uri(*resource_id)) ! ? ::uri(*resource_id) ! : ::uri(*resource_id) ! .resolve_against(::uri(this->uri)); ! scene.browser().add_node_class(node_class_id(absolute_uri), externproto_class); } node_type = externproto_class->create_type(id->getText(), interfaces); - // - // Hack alert. If we get an empty list of URIs for the - // EXTERNPROTO implementation, we have nothing to put in - // browser::node_class_map_. That means that we'd wind up - // with no owning pointer to the node class except for the - // one in this scope (which is about to go away). So, we - // store an owning pointer in the externproto_node_type. - // - boost::dynamic_pointer_cast<externproto_node_type>(node_type) - ->set_owning_ptr_to_class(externproto_class); } --- 977,1008 ---- new externproto_node_class(scene, alt_uris)); ! if (alt_uris.empty()) { ! // ! // If the list of alternative URIs (i.e., implementation ! // identifiers) is empty, we need to generate one to put in ! // the browser's node_class map. (The node_class map is ! // where the owning pointer to the node_class is kept. ! // ! node_class_id class_id = this->uri + '#' + id->getText(); ! scene.browser().add_node_class(class_id, externproto_class); + } else { + for (vector<string>::const_iterator resource_id = + alt_uris.begin(); + resource_id != alt_uris.end(); + ++resource_id) { + const ::uri absolute_uri = + !relative(::uri(*resource_id)) + ? ::uri(*resource_id) + : ::uri(*resource_id).resolve_against( + ::uri(this->uri)); + scene.browser().add_node_class( + node_class_id(absolute_uri), + externproto_class); + } } node_type = externproto_class->create_type(id->getText(), interfaces); } |