From: <br...@us...> - 2008-09-24 23:32:38
|
Revision: 3691 http://openvrml.svn.sourceforge.net/openvrml/?rev=3691&view=rev Author: braden Date: 2008-09-24 23:32:24 +0000 (Wed, 24 Sep 2008) Log Message: ----------- Moved dlopen/LoadLibrary wrapper functions, the XML parser wrapper, and the uri class to the openvrml::local namespace. This facilitates breaking up browser.cpp a bit. openvrml::scene has been moved to its own header and implementation file and the openvrml::script implementation has been moved back to its own file. Modified Paths: -------------- trunk/ChangeLog trunk/src/Makefile.am trunk/src/libopenvrml/openvrml/browser.cpp trunk/src/libopenvrml/openvrml/browser.h trunk/src/libopenvrml/openvrml/node.cpp trunk/src/libopenvrml/openvrml/node.h trunk/src/libopenvrml/openvrml/script.h trunk/src/libopenvrml/private.h trunk/src/node/vrml97/anchor.cpp trunk/src/node/vrml97/audio_clip.cpp trunk/src/node/vrml97/background.cpp trunk/src/node/vrml97/image_texture.cpp trunk/src/node/vrml97/inline.cpp trunk/src/node/vrml97/movie_texture.cpp trunk/src/node/vrml97/point_light.cpp trunk/src/node/vrml97/spot_light.cpp trunk/src/node/vrml97/time_sensor.cpp trunk/src/node/vrml97/viewpoint.cpp trunk/src/script/java.cpp trunk/src/script/javascript.cpp Added Paths: ----------- trunk/src/libopenvrml/openvrml/bad_url.cpp trunk/src/libopenvrml/openvrml/bad_url.h trunk/src/libopenvrml/openvrml/local/ trunk/src/libopenvrml/openvrml/local/dl.cpp trunk/src/libopenvrml/openvrml/local/dl.h trunk/src/libopenvrml/openvrml/local/uri.cpp trunk/src/libopenvrml/openvrml/local/uri.h trunk/src/libopenvrml/openvrml/local/xml_reader.cpp trunk/src/libopenvrml/openvrml/local/xml_reader.h trunk/src/libopenvrml/openvrml/scene.cpp trunk/src/libopenvrml/openvrml/scene.h trunk/src/libopenvrml/openvrml/script.cpp Removed Paths: ------------- trunk/src/libopenvrml/openvrml/local/dl.cpp trunk/src/libopenvrml/openvrml/local/dl.h trunk/src/libopenvrml/openvrml/local/uri.cpp trunk/src/libopenvrml/openvrml/local/uri.h trunk/src/libopenvrml/openvrml/local/xml_reader.cpp trunk/src/libopenvrml/openvrml/local/xml_reader.h Property Changed: ---------------- trunk/ trunk/src/node/x3d-core/metadata_double.cpp trunk/src/node/x3d-core/metadata_double.h trunk/src/node/x3d-core/metadata_float.cpp trunk/src/node/x3d-core/metadata_float.h trunk/src/node/x3d-core/metadata_integer.cpp trunk/src/node/x3d-core/metadata_integer.h trunk/src/node/x3d-core/metadata_set.cpp trunk/src/node/x3d-core/metadata_set.h trunk/src/node/x3d-core/metadata_string.cpp trunk/src/node/x3d-core/metadata_string.h trunk/src/node/x3d-dis/espdu_transform.cpp trunk/src/node/x3d-dis/espdu_transform.h trunk/src/node/x3d-dis/receiver_pdu.cpp trunk/src/node/x3d-dis/receiver_pdu.h trunk/src/node/x3d-dis/signal_pdu.cpp trunk/src/node/x3d-dis/signal_pdu.h trunk/src/node/x3d-dis/transmitter_pdu.cpp trunk/src/node/x3d-dis/transmitter_pdu.h trunk/src/node/x3d-environmental-effects/texture_background.cpp trunk/src/node/x3d-environmental-effects/texture_background.h trunk/src/node/x3d-event-utilities/boolean_filter.cpp trunk/src/node/x3d-event-utilities/boolean_filter.h trunk/src/node/x3d-event-utilities/boolean_sequencer.cpp trunk/src/node/x3d-event-utilities/boolean_sequencer.h trunk/src/node/x3d-event-utilities/boolean_toggle.cpp trunk/src/node/x3d-event-utilities/boolean_toggle.h trunk/src/node/x3d-event-utilities/boolean_trigger.cpp trunk/src/node/x3d-event-utilities/boolean_trigger.h trunk/src/node/x3d-event-utilities/integer_sequencer.cpp trunk/src/node/x3d-event-utilities/integer_sequencer.h trunk/src/node/x3d-event-utilities/integer_trigger.cpp trunk/src/node/x3d-event-utilities/integer_trigger.h trunk/src/node/x3d-event-utilities/time_trigger.cpp trunk/src/node/x3d-event-utilities/time_trigger.h trunk/src/node/x3d-geometry2d/arc2d.cpp trunk/src/node/x3d-geometry2d/arc2d.h trunk/src/node/x3d-geometry2d/arc_close2d.cpp trunk/src/node/x3d-geometry2d/arc_close2d.h trunk/src/node/x3d-geometry2d/circle2d.cpp trunk/src/node/x3d-geometry2d/circle2d.h trunk/src/node/x3d-geometry2d/disk2d.cpp trunk/src/node/x3d-geometry2d/disk2d.h trunk/src/node/x3d-geometry2d/polyline2d.cpp trunk/src/node/x3d-geometry2d/polyline2d.h trunk/src/node/x3d-geometry2d/polypoint2d.cpp trunk/src/node/x3d-geometry2d/polypoint2d.h trunk/src/node/x3d-geometry2d/rectangle2d.cpp trunk/src/node/x3d-geometry2d/rectangle2d.h trunk/src/node/x3d-geometry2d/triangle_set2d.cpp trunk/src/node/x3d-geometry2d/triangle_set2d.h trunk/src/node/x3d-geospatial/geo_coordinate.cpp trunk/src/node/x3d-geospatial/geo_coordinate.h trunk/src/node/x3d-geospatial/geo_elevation_grid.cpp trunk/src/node/x3d-geospatial/geo_elevation_grid.h trunk/src/node/x3d-geospatial/geo_location.cpp trunk/src/node/x3d-geospatial/geo_location.h trunk/src/node/x3d-geospatial/geo_lod.cpp trunk/src/node/x3d-geospatial/geo_lod.h trunk/src/node/x3d-geospatial/geo_metadata.cpp trunk/src/node/x3d-geospatial/geo_metadata.h trunk/src/node/x3d-geospatial/geo_origin.cpp trunk/src/node/x3d-geospatial/geo_origin.h trunk/src/node/x3d-geospatial/geo_position_interpolator.cpp trunk/src/node/x3d-geospatial/geo_position_interpolator.h trunk/src/node/x3d-geospatial/geo_touch_sensor.cpp trunk/src/node/x3d-geospatial/geo_touch_sensor.h trunk/src/node/x3d-geospatial/geo_viewpoint.cpp trunk/src/node/x3d-geospatial/geo_viewpoint.h trunk/src/node/x3d-grouping/static_group.cpp trunk/src/node/x3d-grouping/static_group.h trunk/src/node/x3d-h-anim/h_anim_displacer.cpp trunk/src/node/x3d-h-anim/h_anim_displacer.h trunk/src/node/x3d-h-anim/h_anim_humanoid.cpp trunk/src/node/x3d-h-anim/h_anim_humanoid.h trunk/src/node/x3d-h-anim/h_anim_joint.cpp trunk/src/node/x3d-h-anim/h_anim_joint.h trunk/src/node/x3d-h-anim/h_anim_segment.cpp trunk/src/node/x3d-h-anim/h_anim_segment.h trunk/src/node/x3d-h-anim/h_anim_site.cpp trunk/src/node/x3d-h-anim/h_anim_site.h trunk/src/node/x3d-interpolation/coordinate_interpolator2d.cpp trunk/src/node/x3d-interpolation/coordinate_interpolator2d.h trunk/src/node/x3d-interpolation/position_interpolator2d.cpp trunk/src/node/x3d-interpolation/position_interpolator2d.h trunk/src/node/x3d-key-device-sensor/key_sensor.cpp trunk/src/node/x3d-key-device-sensor/key_sensor.h trunk/src/node/x3d-key-device-sensor/string_sensor.cpp trunk/src/node/x3d-key-device-sensor/string_sensor.h trunk/src/node/x3d-networking/load_sensor.cpp trunk/src/node/x3d-networking/load_sensor.h trunk/src/node/x3d-rendering/color_rgba.cpp trunk/src/node/x3d-rendering/color_rgba.h trunk/src/node/x3d-rendering/indexed_triangle_fan_set.cpp trunk/src/node/x3d-rendering/indexed_triangle_fan_set.h trunk/src/node/x3d-rendering/indexed_triangle_set.cpp trunk/src/node/x3d-rendering/indexed_triangle_set.h trunk/src/node/x3d-rendering/indexed_triangle_strip_set.cpp trunk/src/node/x3d-rendering/indexed_triangle_strip_set.h trunk/src/node/x3d-rendering/triangle_fan_set.cpp trunk/src/node/x3d-rendering/triangle_fan_set.h trunk/src/node/x3d-rendering/triangle_set.cpp trunk/src/node/x3d-rendering/triangle_set.h trunk/src/node/x3d-rendering/triangle_strip_set.cpp trunk/src/node/x3d-rendering/triangle_strip_set.h trunk/src/node/x3d-shape/fill_properties.cpp trunk/src/node/x3d-shape/fill_properties.h trunk/src/node/x3d-shape/line_properties.cpp trunk/src/node/x3d-shape/line_properties.h trunk/src/node/x3d-texturing/multi_texture.cpp trunk/src/node/x3d-texturing/multi_texture.h trunk/src/node/x3d-texturing/multi_texture_coordinate.cpp trunk/src/node/x3d-texturing/multi_texture_coordinate.h trunk/src/node/x3d-texturing/multi_texture_transform.cpp trunk/src/node/x3d-texturing/multi_texture_transform.h trunk/src/node/x3d-texturing/texture_coordinate_generator.cpp trunk/src/node/x3d-texturing/texture_coordinate_generator.h Property changes on: trunk ___________________________________________________________________ Modified: svn:mergeinfo - /branches/node-modules:3622-3623,3632-3635,3637-3638,3640-3641,3643-3644,3646-3647,3649-3650,3654-3655,3657-3658,3661-3662,3664-3665,3667-3668,3670-3671,3673-3674,3684-3685,3687-3688 + /branches/local:3677-3689 /branches/node-modules:3622-3623,3632-3635,3637-3638,3640-3641,3643-3644,3646-3647,3649-3650,3654-3655,3657-3658,3661-3662,3664-3665,3667-3668,3670-3671,3673-3674,3684-3685,3687-3688 Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2008-09-24 23:31:55 UTC (rev 3690) +++ trunk/ChangeLog 2008-09-24 23:32:24 UTC (rev 3691) @@ -1,5 +1,79 @@ 2008-09-24 Braden McDaniel <br...@en...> + Moved dlopen/LoadLibrary wrapper functions, the XML parser + wrapper, and the uri class to the openvrml::local namespace. This + facilitates breaking up browser.cpp a bit. openvrml::scene has + been moved to its own header and implementation file and the + openvrml::script implementation has been moved back to its own + file. + + * src/Makefile.am + (openvrml_include_HEADERS): Added libopenvrml/openvrml/bad_url.h + and libopenvrml/openvrml/scene.h. + (libopenvrml_libopenvrml_la_SOURCES): Added + libopenvrml/openvrml/bad_url.cpp, libopenvrml/openvrml/script.cpp, + libopenvrml/openvrml/scene.cpp, + libopenvrml/openvrml/local/dl.{cpp,h}, + libopenvrml/openvrml/uri.{cpp,h}, and + libopenvrml/openvrml/local/xml_reader.{cpp,h}. + * src/libopenvrml/private.h: Moved URI grammar to + libopenvrml/openvrml/local/uri.h. + * src/libopenvrml/openvrml/bad_url.cpp: Implementation of + openvrml::bad_url and derived exceptions; moved from browser.cpp. + * src/libopenvrml/openvrml/bad_url.h: openvrml::bad_url and + derived exceptions; moved from browser.h. + * src/libopenvrml/openvrml/browser.cpp: Moved dlopen/LoadLibrary + wrapper functions to libopenvrml/openvrml/local/dl.cpp; moved uri + class implementation to libopenvrml/openvrml/local/uri.cpp; moved + xml_reader class implementation to + libopenvrml/openvrml/local/xml_reader.cpp; moved script_node + implementation to libopenvrml/openvrml/script.cpp. + * src/libopenvrml/openvrml/browser.h: Moved openvrml::script_node + definition to libopenvrml/openvrml/script.h; moved definition of + openvrml::bad_url and derived exceptions to + libopenvrml/openvrml/bad_url.h. + * src/libopenvrml/openvrml/local/dl.cpp: Added; dlopen/LoadLibrary + wrapper function definitions. + * src/libopenvrml/openvrml/local/dl.h: Added; dlopen/LoadLibrary + wrapper function declarations (moved from + libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/local/uri.cpp: Added; uri class + implementation (moved from libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/local/uri.h: Added; uri class + definition and grammar definitions (moved from + libopenvrml/openvrml/browser.cpp and libopenvrml/private.h). + * src/libopenvrml/openvrml/local/xml_reader.cpp: Added; xml_reader + implementation (moved from libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/local/xml_reader.h: Added; xml_reader + class definition (moved from libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/node.cpp: Include scope.h here rather + than in node.h. + * src/libopenvrml/openvrml/node.h: Declare openvrml::scope rather + than include scope.h here. + * src/libopenvrml/openvrml/scene.cpp: Added; openvrml::scene + implementation (moved from libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/scene.h: Added; openvrml::scene + definition (moved from libopenvrml/openvrml/browser.h). + * src/libopenvrml/openvrml/script.cpp: Added; openvrml::script and + openvrml::script_node implementations (moved from + libopenvrml/openvrml/browser.cpp). + * src/libopenvrml/openvrml/script.h: Moved openvrml::script_node + definition here (from libopenvrml/openvrml/browser.h). + * src/node/vrml97/movie_texture.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/audio_clip.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/anchor.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/inline.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/time_sensor.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/image_texture.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/spot_light.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/background.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/point_light.cpp: Include <openvrml/scene.h>. + * src/node/vrml97/viewpoint.cpp: Include <openvrml/scene.h>. + * src/script/java.cpp: Include <openvrml/scene.h>. + * src/script/javascript.cpp: Include <openvrml/scene.h>. + +2008-09-24 Braden McDaniel <br...@en...> + Moved X3D CAD Geometry node implementations into a convenience library. Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2008-09-24 23:31:55 UTC (rev 3690) +++ trunk/src/Makefile.am 2008-09-24 23:32:24 UTC (rev 3691) @@ -37,6 +37,7 @@ openvrml_includedir = $(pkgincludedir)/openvrml openvrml_include_HEADERS = \ + libopenvrml/openvrml/bad_url.h \ libopenvrml/openvrml/basetypes.h \ libopenvrml/openvrml/vrml97_grammar.h \ libopenvrml/openvrml/x3d_vrml_grammar.h \ @@ -48,6 +49,7 @@ libopenvrml/openvrml/node.h \ libopenvrml/openvrml/bounding_volume.h \ libopenvrml/openvrml/script.h \ + libopenvrml/openvrml/scene.h \ libopenvrml/openvrml/browser.h \ libopenvrml/openvrml/viewer.h \ libopenvrml/openvrml/rendering_context.h \ @@ -113,6 +115,7 @@ $(XML_CFLAGS) libopenvrml_libopenvrml_la_SOURCES = \ + libopenvrml/openvrml/bad_url.cpp \ libopenvrml/openvrml/vrml97_grammar.cpp \ libopenvrml/openvrml/x3d_vrml_grammar.cpp \ libopenvrml/openvrml/read_write_mutex.cpp \ @@ -122,7 +125,9 @@ libopenvrml/openvrml/exposedfield.cpp \ libopenvrml/openvrml/scope.cpp \ libopenvrml/openvrml/node.cpp \ + libopenvrml/openvrml/script.cpp \ libopenvrml/openvrml/bounding_volume.cpp \ + libopenvrml/openvrml/scene.cpp \ libopenvrml/openvrml/browser.cpp \ libopenvrml/openvrml/viewer.cpp \ libopenvrml/openvrml/rendering_context.cpp \ @@ -144,7 +149,13 @@ libopenvrml/openvrml/x3d_geospatial.cpp \ libopenvrml/openvrml/x3d_hanim.cpp \ libopenvrml/openvrml/x3d_nurbs.cpp \ - libopenvrml/openvrml/x3d_cad_geometry.cpp + libopenvrml/openvrml/x3d_cad_geometry.cpp \ + libopenvrml/openvrml/local/dl.cpp \ + libopenvrml/openvrml/local/dl.h \ + libopenvrml/openvrml/local/uri.cpp \ + libopenvrml/openvrml/local/uri.h \ + libopenvrml/openvrml/local/xml_reader.cpp \ + libopenvrml/openvrml/local/xml_reader.h libopenvrml_libopenvrml_la_LDFLAGS = \ -version-info $(LIBOPENVRML_LIBRARY_VERSION) \ Copied: trunk/src/libopenvrml/openvrml/bad_url.cpp (from rev 3689, branches/local/src/libopenvrml/openvrml/bad_url.cpp) =================================================================== --- trunk/src/libopenvrml/openvrml/bad_url.cpp (rev 0) +++ trunk/src/libopenvrml/openvrml/bad_url.cpp 2008-09-24 23:32:24 UTC (rev 3691) @@ -0,0 +1,136 @@ +// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 78 -*- +// +// OpenVRML +// +// Copyright 2008 Braden McDaniel +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 3 of the License, or (at your +// option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, see <http://www.gnu.org/licenses/>. +// + +# include "bad_url.h" + +# ifdef HAVE_CONFIG_H +# include <config.h> +# endif + +/** + * @file openvrml/bad_url.h + * + * @brief Exceptions indicating various types of resource retrieval failure. + */ + +/** + * @class openvrml::bad_url openvrml/bad_url.h + * + * @brief Thrown when there is a problem resolving a URI. + */ + +/** + * @brief Construct. + * + * @param[in] message Informative text. + */ +openvrml::bad_url::bad_url(const std::string & message): + std::runtime_error(message) +{} + +/** + * @brief Destroy. + */ +openvrml::bad_url::~bad_url() throw () +{} + + +/** + * @class openvrml::invalid_url openvrml/bad_url.h + * + * @brief Thrown when parsing a URI fails. + */ + +/** + * @brief Construct. + */ +openvrml::invalid_url::invalid_url(): + bad_url("invalid URI") +{} + +/** + * @brief Destroy. + */ +openvrml::invalid_url::~invalid_url() throw () +{} + + +/** + * @class openvrml::bad_media_type openvrml/bad_url.h + * + * @brief Thrown when an unexpected media type is received. + */ + +/** + * @brief Construct. + * + * @param[in] received_type the media type that was unexpectedly received. + */ +openvrml::bad_media_type::bad_media_type(const std::string & received_type) + OPENVRML_NOTHROW: + bad_url("unexpected media type \"" + received_type + "\"") +{} + +/** + * @brief Destroy. + */ +openvrml::bad_media_type::~bad_media_type() throw () +{} + + +/** + * @class openvrml::unreachable_url openvrml/browser.h + * + * @brief Thrown when a URI cannot be reached. + */ + +/** + * @brief Construct. + */ +openvrml::unreachable_url::unreachable_url(): + bad_url("unreachable URI") +{} + +/** + * @brief Destroy. + */ +openvrml::unreachable_url::~unreachable_url() throw () +{} + + +/** + * @class openvrml::no_alternative_url openvrml/bad_url.h + * + * @brief Exception thrown when no URI in an alternative URI list can be + * resolved. + */ + +/** + * @brief Construct. + */ +openvrml::no_alternative_url::no_alternative_url(): + bad_url("no alternative URI could be resolved") +{} + +/** + * @brief Destroy. + */ +openvrml::no_alternative_url::~no_alternative_url() throw () +{} Copied: trunk/src/libopenvrml/openvrml/bad_url.h (from rev 3689, branches/local/src/libopenvrml/openvrml/bad_url.h) =================================================================== --- trunk/src/libopenvrml/openvrml/bad_url.h (rev 0) +++ trunk/src/libopenvrml/openvrml/bad_url.h 2008-09-24 23:32:24 UTC (rev 3691) @@ -0,0 +1,66 @@ +// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 78 -*- +// +// OpenVRML +// +// Copyright 2008 Braden McDaniel +// +// This library is free software; you can redistribute it and/or modify it +// under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation; either version 3 of the License, or (at your +// option) any later version. +// +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +// License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, see <http://www.gnu.org/licenses/>. +// + +# ifndef OPENVRML_BAD_URL_H +# define OPENVRML_BAD_URL_H + +# include <openvrml-common.h> +# include <stdexcept> +# include <string> + +namespace openvrml { + + class OPENVRML_API bad_url : public std::runtime_error { + public: + bad_url(const std::string & message); + virtual ~bad_url() throw (); + }; + + + class OPENVRML_API invalid_url : public bad_url { + public: + invalid_url(); + virtual ~invalid_url() throw (); + }; + + + class OPENVRML_API bad_media_type : public bad_url { + public: + explicit bad_media_type(const std::string & received_type) + OPENVRML_NOTHROW; + virtual ~bad_media_type() throw (); + }; + + + class OPENVRML_API unreachable_url : public bad_url { + public: + unreachable_url(); + virtual ~unreachable_url() throw (); + }; + + + class OPENVRML_API no_alternative_url : public bad_url { + public: + no_alternative_url(); + virtual ~no_alternative_url() throw (); + }; +} + +# endif // ifndef OPENVRML_BAD_URL_H Modified: trunk/src/libopenvrml/openvrml/browser.cpp =================================================================== --- trunk/src/libopenvrml/openvrml/browser.cpp 2008-09-24 23:31:55 UTC (rev 3690) +++ trunk/src/libopenvrml/openvrml/browser.cpp 2008-09-24 23:32:24 UTC (rev 3691) @@ -19,40 +19,9 @@ // along with this library; if not, see <http://www.gnu.org/licenses/>. // -# ifdef HAVE_CONFIG_H -# include <config.h> -# endif - -# include <cerrno> -# include <algorithm> -# include <functional> -# ifdef _WIN32 -# include <sys/timeb.h> -# include <direct.h> -# include <time.h> -# include <shlwapi.h> -# include <XmlLite.h> -# else -# include <sys/time.h> -# include <ltdl.h> -# include <libxml/xmlreader.h> -# endif -# include <boost/algorithm/string/predicate.hpp> -# include <boost/array.hpp> -# include <boost/bind.hpp> -# include <boost/enable_shared_from_this.hpp> -# include <boost/filesystem.hpp> -# include <boost/functional.hpp> -# include <boost/lexical_cast.hpp> -# include <boost/mpl/for_each.hpp> -# include <boost/multi_index/detail/scope_guard.hpp> -# include <boost/ptr_container/ptr_map.hpp> -# include <boost/thread/thread.hpp> -# include <boost/tokenizer.hpp> -# include <boost/utility.hpp> -# include <private.h> # include "browser.h" -# include "vrml97_grammar.h" +# include "scene.h" +# include "scope.h" # include "x3d_vrml_grammar.h" # include "vrml97node.h" # include "x3d_core.h" @@ -71,2999 +40,38 @@ # include "x3d_hanim.h" # include "x3d_nurbs.h" # include "x3d_cad_geometry.h" - -using namespace boost::multi_index::detail; // for scope_guard - -namespace { - - class OPENVRML_LOCAL uri { - class actions { - uri * uri_; - - public: - explicit actions(uri & uri_): - uri_(&uri_), - scheme(*this), - scheme_specific_part(*this), - authority(*this), - userinfo(*this), - host(*this), - port(*this), - path(*this), - query(*this), - fragment(*this) - {} - - struct scheme_action { - explicit scheme_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->scheme_begin = first; - this->actions_->uri_->scheme_end = last; - } - - private: - actions * actions_; - } scheme; - - struct scheme_specific_part_action { - explicit scheme_specific_part_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->scheme_specific_part_begin = first; - this->actions_->uri_->scheme_specific_part_end = last; - } - - private: - actions * actions_; - } scheme_specific_part; - - struct authority_action { - explicit authority_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->authority_begin = first; - this->actions_->uri_->authority_end = last; - } - - private: - actions * actions_; - } authority; - - struct userinfo_action { - explicit userinfo_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->userinfo_begin = first; - this->actions_->uri_->userinfo_end = last; - } - - private: - actions * actions_; - } userinfo; - - struct host_action { - explicit host_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->host_begin = first; - this->actions_->uri_->host_end = last; - } - - private: - actions * actions_; - } host; - - struct port_action { - explicit port_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->port_begin = first; - this->actions_->uri_->port_end = last; - } - - private: - actions * actions_; - } port; - - struct path_action { - explicit path_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->path_begin = first; - this->actions_->uri_->path_end = last; - } - - private: - actions * actions_; - } path; - - struct query_action { - explicit query_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->query_begin = first; - this->actions_->uri_->query_end = last; - } - - private: - actions * actions_; - } query; - - struct fragment_action { - explicit fragment_action(actions & actions_): - actions_(&actions_) - {} - - template <typename Iterator> - void operator()(const Iterator & first, - const Iterator & last) const - { - this->actions_->uri_->fragment_begin = first; - this->actions_->uri_->fragment_end = last; - } - - private: - actions * actions_; - } fragment; - }; - - std::string str_; - std::string::const_iterator scheme_begin, scheme_end; - std::string::const_iterator scheme_specific_part_begin, - scheme_specific_part_end; - std::string::const_iterator authority_begin, authority_end; - std::string::const_iterator userinfo_begin, userinfo_end; - std::string::const_iterator host_begin, host_end; - std::string::const_iterator port_begin, port_end; - std::string::const_iterator path_begin, path_end; - std::string::const_iterator query_begin, query_end; - std::string::const_iterator fragment_begin, fragment_end; - - public: - uri() OPENVRML_THROW1(std::bad_alloc); - explicit uri(const std::string & str) - OPENVRML_THROW2(openvrml::invalid_url, std::bad_alloc); - uri(const uri & id) OPENVRML_THROW1(std::bad_alloc); - - uri & operator=(const uri & id) OPENVRML_THROW1(std::bad_alloc); - - operator std::string() const OPENVRML_THROW1(std::bad_alloc); - - void swap(uri & id) OPENVRML_NOTHROW; - - const std::string scheme() const OPENVRML_THROW1(std::bad_alloc); - const std::string scheme_specific_part() const - OPENVRML_THROW1(std::bad_alloc); - const std::string authority() const OPENVRML_THROW1(std::bad_alloc); - const std::string userinfo() const OPENVRML_THROW1(std::bad_alloc); - const std::string host() const OPENVRML_THROW1(std::bad_alloc); - const std::string port() const OPENVRML_THROW1(std::bad_alloc); - const std::string path() const OPENVRML_THROW1(std::bad_alloc); - const std::string query() const OPENVRML_THROW1(std::bad_alloc); - const std::string fragment() const OPENVRML_THROW1(std::bad_alloc); - - const uri resolve_against(const uri & absolute_uri) const - OPENVRML_THROW1(std::bad_alloc); - }; - - OPENVRML_LOCAL inline bool relative(const uri & id) - { - return id.scheme().empty(); - } -} - - /** - * @file openvrml/script.h - * - * @brief Pluggable scripting engine support. - */ - -/** - * @class openvrml::script openvrml/script.h - * - * @brief Abstract class implemented by scripting language bindings. - * - * The runtime instantiates subclasses of script for each VRML97 Script node; - * and calls its methods appropriately to execute script code. - */ - -/** - * @internal - * - * @typedef openvrml::script::direct_output_map_t - * - * @brief Map of direct outputs. - */ - -/** - * @internal - * - * @var openvrml::script::direct_output_map_t openvrml::script::direct_output_map_ - * - * @brief Map of direct outputs. - */ - -/** - * @var openvrml::script_node & openvrml::script::node - * - * @brief A reference to the script_node that uses this script object. - */ - -/** - * @brief Construct. - * - * @param[in] node a reference to the script_node that uses this script object. - */ -openvrml::script::script(script_node & node): - node(node) -{} - -/** - * @brief Destroy. - */ -openvrml::script::~script() -{} - -/** - * @brief Initialize the Script node. - * - * Delegates to @c script::do_initialize. - * - * @param[in] timestamp the current time. - */ -void openvrml::script::initialize(double timestamp) -{ - this->do_initialize(timestamp); - this->process_direct_output(timestamp); -} - -/** - * @fn void openvrml::script::do_initialize(double timestamp) - * - * @brief Initialize the Script node. - * - * @param[in] timestamp the current time. - */ - -/** - * @brief Process an event. - * - * Delegates to @c script::do_process_event. - * - * @param[in] id eventIn identifier. - * @param[in] value event value. - * @param[in] timestamp the current time. - */ -void openvrml::script::process_event(const std::string & id, - const field_value & value, - double timestamp) -{ - this->do_process_event(id, value, timestamp); - this->process_direct_output(timestamp); -} - -/** - * @fn void openvrml::script::do_process_event(const std::string & id, const field_value & value, double timestamp) - * - * @brief Process an event. - * - * @param[in] id @c eventIn identifier. - * @param[in] value event value. - * @param[in] timestamp the current time. - */ - -/** - * @brief Execute script code after processing events. - * - * Delegates to @c script::do_events_processed. - * - * @param[in] timestamp the current time. - */ -void openvrml::script::events_processed(double timestamp) -{ - this->do_events_processed(timestamp); -} - -/** - * @fn void openvrml::script::do_events_processed(double timestamp) - * - * @brief Execute script code after processing events. - * - * @param[in] timestamp the current time. - */ - -/** - * @brief Shut down the Script node. - * - * Delegates to <code>script::do_shutdown</code>. - * - * @param[in] timestamp the current time. - */ -void openvrml::script::shutdown(double timestamp) -{ - this->do_shutdown(timestamp); - this->process_direct_output(timestamp); -} - -/** - * @fn void openvrml::script::do_shutdown(double timestamp) - * - * @brief Shut down the Script node. - * - * @param[in] timestamp the current time. - */ - -/** - * @brief Whether direct output is enabled for the Script node. - * - * @return @c true if direct output is enabled for the Script node; @c false - * otherwise. - */ -bool openvrml::script::direct_output() const OPENVRML_NOTHROW -{ - return this->node.direct_output.value(); -} - -/** - * @brief Whether the browser may delay sending input events to the script - * until its outputs are needed by the browser. - * - * @return @c true if the browser may delay sending input events to the script - * until its outputs are needed by the browser; @c false otherwise. - */ -bool openvrml::script::must_evaluate() const OPENVRML_NOTHROW -{ - return this->node.must_evaluate.value(); -} - -/** - * @brief Set the value of a field. - * - * @param[in] id field identifier. - * @param[in] value new value. - * - * @exception unsupported_interface if the Script node has no field @p id. - * @exception std::bad_cast if @p value is the wrong type. - * @exception std::bad_alloc if memory allocation fails. - */ -void openvrml::script::field(const std::string & id, const field_value & value) - OPENVRML_THROW3(unsupported_interface, std::bad_cast, std::bad_alloc) -{ - const script_node::field_value_map_t::iterator field = - this->node.field_value_map_.find(id); - if (field == this->node.field_value_map_.end()) { - throw unsupported_interface(this->node.type_, - node_interface::field_id, - id); - } - field->second->assign(value); // throws std::bad_cast, std::bad_alloc -} - -/** - * @brief Add an event for direct output processing at the end of script - * execution. - * - * @param[in] listener the @c event_listener to which the event should be - * sent. - * @param[in] value the value to send. - * - * @exception field_value_type_mismatch if @p listener is not the correct type - * to process events of @p value's type. - * @exception std::bad_alloc if memory allocation fails. - */ -void -openvrml::script::direct_output(event_listener & listener, - const boost::shared_ptr<field_value> & value) - OPENVRML_THROW2(field_value_type_mismatch, std::bad_alloc) -{ - assert(value); - if (listener.type() != value->type()) { - throw field_value_type_mismatch(); - } - this->direct_output_map_[&listener] = value; -} - -namespace { - struct OPENVRML_LOCAL direct_output_processor { - direct_output_processor(openvrml::event_listener & listener, - openvrml::field_value & value, - const double timestamp): - listener_(&listener), - value_(&value), - timestamp_(timestamp) - {} - - template <typename T> - void operator()(T) const - { - if (T::field_value_type_id == this->listener_->type()) { - using boost::polymorphic_downcast; - using openvrml::field_value_listener; - dynamic_cast<field_value_listener<T> &>(*this->listener_) - .process_event(*polymorphic_downcast<T *>(this->value_), - this->timestamp_); - } - } - - private: - openvrml::event_listener * listener_; - openvrml::field_value * value_; - double timestamp_; - }; -} - -/** - * @internal - * - * @brief Process direct outputs in @a script::direct_output_map_. - * - * This function is called at the end of initialization and processing normal - * events. - * - * @post <code>script::direct_output_map_.empty()</code> is @c true. - */ -void openvrml::script::process_direct_output(double timestamp) -{ - for (direct_output_map_t::const_iterator output = - this->direct_output_map_.begin(); - output != this->direct_output_map_.end(); - ++output) { - using boost::mpl::for_each; - using openvrml_::field_value_types; - for_each<field_value_types>(direct_output_processor(*output->first, - *output->second, - timestamp)); - } - this->direct_output_map_.clear(); -} - - -/** - * @class openvrml::script_factory - * - * @brief An abstract factory for @c script%s. - */ - -/** - * @brief Construct. - */ -openvrml::script_factory::script_factory() OPENVRML_NOTHROW -{} - -/** - * @brief Destroy. - */ -openvrml::script_factory::~script_factory() OPENVRML_NOTHROW -{} - -/** - * @fn std::auto_ptr<openvrml::script> openvrml::script_factory::create_script(script_node & node, const boost::shared_ptr<std::istream> & source) - * - * @brief Create a @c script. - * - * Implementations of this function are called in the implementation of - * @c script_node. A @c script instance is created to encapsulate scripting - * logic in a Script node instance. - */ - -/** - * @class openvrml::script_factory_registry - * - * @brief Registry of - * <code>@link script_factory script_factories@endlink</code>. - * - * In general there should be one @c script_factory registered per - * “scripting engine”; i.e., supported language in the Script - * node. An instance of the @c script_factory_registry is passed to - * @c openvrml_register_script_factory, which should be implemented by - * modules that add support for a scripting language. - */ - -/** - * @internal - * - * @var class script_factory_registry::script_node - * - * @brief @c script_node is the only class that should ever need to - * instantiate @c script_factory_registry. - */ - -namespace { - +# include <openvrml/local/uri.h> +# include <openvrml/local/xml_reader.h> +# include <private.h> +# include <boost/algorithm/string/predicate.hpp> +# include <boost/bind.hpp> +# include <boost/enable_shared_from_this.hpp> +# include <boost/filesystem.hpp> +# include <boost/functional.hpp> +# include <boost/lexical_cast.hpp> +# include <boost/mpl/for_each.hpp> +# include <boost/multi_index/detail/scope_guard.hpp> +# include <boost/ptr_container/ptr_map.hpp> +# include <boost/thread/thread.hpp> +# include <boost/utility.hpp> +# include <algorithm> +# include <functional> +# include <cerrno> # ifdef _WIN32 - const char pathsep_char = ';'; +# include <sys/timeb.h> +# include <direct.h> +# include <time.h> # else - const char pathsep_char = ':'; +# include <sys/time.h> # endif - OPENVRML_LOCAL int openvrml_dlinit() - { -# ifdef _WIN32 - return 0; -# else - return lt_dlinit(); +# ifdef HAVE_CONFIG_H +# include <config.h> # endif - } - OPENVRML_LOCAL int openvrml_dlexit() - { -# ifdef _WIN32 - return 0; -# else - return lt_dlexit(); -# endif - } +using namespace boost::multi_index::detail; // for scope_guard - struct OPENVRML_LOCAL win32_search_path_tokenizer { - win32_search_path_tokenizer() - {} - - template <typename Iterator, typename Token> - bool operator()(Iterator & next, Iterator end, Token & tok) - { - while (next != end) { - if (*next == ';') { - ++next; - break; - } - this->tok_.push_back(*next); - ++next; - } - if (!this->tok_.empty()) { - tok = this->tok_; - this->tok_.clear(); - return true; - } - return false; - } - - void reset() - { - this->tok_.clear(); - } - - private: - std::string tok_; - }; - - OPENVRML_LOCAL - int - openvrml_dlforeachfile(const char * search_path, - int (*func)(const char * filename, void * data), - void * data) - { -# ifdef _WIN32 - using boost::filesystem::path; - using boost::filesystem::directory_iterator; - typedef boost::tokenizer<win32_search_path_tokenizer> tokenizer_t; - - std::vector<path> search_dirs; - win32_search_path_tokenizer tokenizer_func; - std::string search_path_str(search_path); - tokenizer_t tokenizer(search_path_str, tokenizer_func); - for (tokenizer_t::const_iterator token = tokenizer.begin(); - token != tokenizer.end(); - ++token) { - search_dirs.push_back(path(*token)); - } - - int result = 0; - for (std::vector<path>::const_iterator dir = search_dirs.begin(); - dir != search_dirs.end(); - ++dir) try { - for (directory_iterator entry(*dir); - entry != directory_iterator(); - ++entry) { - result = (func)(entry->path().external_file_string().c_str(), - data); - if (result != 0) { return result; } - } - } catch (boost::filesystem::filesystem_error &) {} - return result; -# else - return lt_dlforeachfile(search_path, func, data); -# endif - } - -# ifdef _WIN32 - typedef HMODULE openvrml_dlhandle; -# else - typedef lt_dlhandle openvrml_dlhandle; -# endif - - OPENVRML_LOCAL openvrml_dlhandle openvrml_dlopen(const char * filename) - { -# ifdef _WIN32 - const char * last_dot = strrchr(filename, '.'); - if (strcmp(last_dot, ".dll") != 0) { return 0; } - return LoadLibrary(filename); -# else - return lt_dlopenext(filename); -# endif - } - - OPENVRML_LOCAL int openvrml_dlclose(openvrml_dlhandle handle) - { -# ifdef _WIN32 - return FreeLibrary(handle); -# else - return lt_dlclose(handle); -# endif - } - - OPENVRML_LOCAL void * openvrml_dlsym(openvrml_dlhandle handle, - const char * name) - { -# ifdef _WIN32 - return GetProcAddress(handle, name); -# else - return lt_dlsym(handle, name); -# endif - } -} - -extern "C" int openvrml_get_script_factory(const char * filename, void * data); - /** - * @internal - * - * @brief @c script_factory_registry implementation. - * - * @c script_factory_registry uses the p-impl idiom. - */ -class openvrml::script_factory_registry::impl : - boost::noncopyable { - - friend int (::openvrml_get_script_factory)(const char * filename, - void * data); - - typedef std::set<openvrml_dlhandle> module_handle_set; - module_handle_set module_handles_; - - typedef std::map<std::string, boost::shared_ptr<script_factory> > - factory_map; - factory_map media_type_map_; - factory_map uri_scheme_map_; - -public: - impl(); - ~impl() OPENVRML_NOTHROW; - - void register_factories(script_factory_registry & registry); - - bool register_factory( - const std::set<std::string> & media_types, - const std::set<std::string> & uri_schemes, - const boost::shared_ptr<script_factory> & factory) - OPENVRML_THROW2(std::bad_alloc, std::invalid_argument); - - const boost::shared_ptr<script_factory> - find_using_media_type(const std::string & media_type) const; - - const boost::shared_ptr<script_factory> - find_using_uri_scheme(const std::string & uri_scheme) const; -}; - -int openvrml_get_script_factory(const char * const filename, void * data) -{ - assert(data); - - using openvrml::script_factory_registry; - - script_factory_registry::impl & registry = - *static_cast<script_factory_registry::impl *>(data); - - const openvrml_dlhandle handle = openvrml_dlopen(filename); - if (!handle) { return 0; } // Ignore things we can't open. - scope_guard handle_guard = make_guard(openvrml_dlclose, handle); - - // - // Make sure the module has what we're looking for. - // - const void * sym = openvrml_dlsym(handle, - "openvrml_script_LTX_register_factory"); - if (!sym) { return 0; } // handle_guard will close the module. - - const bool succeeded = registry.module_handles_.insert(handle).second; - assert(succeeded); - handle_guard.dismiss(); - return 0; -} - -/** - * @internal - * - * @brief Construct. - */ -openvrml::script_factory_registry::impl::impl() -{ - int result = openvrml_dlinit(); - if (result != 0) { - throw std::runtime_error("dlinit failure"); - } - - std::ostringstream script_path; - script_path << OPENVRML_PKGLIBDIR_ "/script"; - const char * const script_path_env = getenv("OPENVRML_SCRIPT_PATH"); - if (script_path_env) { - script_path << pathsep_char << script_path_env; - } - - result = openvrml_dlforeachfile(script_path.str().c_str(), - openvrml_get_script_factory, - this); - assert(result == 0); // We always return 0 from the callback. -} - -/** - * @internal - * - * @brief Destroy. - */ -openvrml::script_factory_registry::impl::~impl() OPENVRML_NOTHROW -{ - std::for_each(this->module_handles_.begin(), this->module_handles_.end(), - openvrml_dlclose); - openvrml_dlexit(); // Don't care if this fails. What would we do? -} - -void -openvrml::script_factory_registry::impl:: -register_factories(script_factory_registry & registry) -{ - for (module_handle_set::const_iterator handle( - this->module_handles_.begin()); - handle != this->module_handles_.end(); - ++handle) { - void * sym = openvrml_dlsym(*handle, - "openvrml_script_LTX_register_factory"); - assert(sym); // We already made sure this would work. - void (* const register_factory)(script_factory_registry &) = - reinterpret_cast<void (*)(script_factory_registry &)>(sym); - register_factory(registry); - } -} - -namespace { - typedef std::map<std::string, boost::shared_ptr<openvrml::script_factory> > - factory_map_t; - - struct OPENVRML_LOCAL add_factory_entry : std::unary_function<std::string, - void> { - add_factory_entry( - const boost::shared_ptr<openvrml::script_factory> & factory, - factory_map_t & factory_map): - factory_(factory), - factory_map_(&factory_map) - {} - - void operator()(const std::string & id) const - { - const bool succeeded = - this->factory_map_->insert(make_pair(id, this->factory_)) - .second; - assert(succeeded); - } - - private: - const boost::shared_ptr<openvrml::script_factory> factory_; - factory_map_t * const factory_map_; - }; -} - -bool -openvrml::script_factory_registry::impl:: -register_factory(const std::set<std::string> & media_types, - const std::set<std::string> & uri_schemes, - const boost::shared_ptr<script_factory> & factory) - OPENVRML_THROW2(std::bad_alloc, std::invalid_argument) -{ - using std::invalid_argument; - using std::set; - using std::string; - - if (media_types.empty() && uri_schemes.empty()) { - throw invalid_argument("no media types or URI schemes specified"); - } - - if (!factory) { - throw invalid_argument("null script_factory pointer"); - } - - for (set<string>::const_iterator media_type = media_types.begin(); - media_type != media_types.end(); - ++media_type) { - const factory_map::const_iterator pos = - this->media_type_map_.find(*media_type); - if (pos != this->media_type_map_.end()) { return false; } - } - - for (set<string>::const_iterator uri_scheme = uri_schemes.begin(); - uri_scheme != uri_schemes.end(); - ++uri_scheme) { - const factory_map::const_iterator pos = - this->uri_scheme_map_.find(*uri_scheme); - if (pos != this->uri_scheme_map_.end()) { return false; } - } - - std::for_each(media_types.begin(), media_types.end(), - add_factory_entry(factory, this->media_type_map_)); - std::for_each(uri_schemes.begin(), uri_schemes.end(), - add_factory_entry(factory, this->uri_scheme_map_)); - return true; -} - -const boost::shared_ptr<openvrml::script_factory> -openvrml::script_factory_registry::impl:: -find_using_media_type(const std::string & media_type) const -{ - const factory_map::const_iterator pos = - this->media_type_map_.find(media_type); - return (pos != this->media_type_map_.end()) - ? pos->second - : boost::shared_ptr<script_factory>(); -} - -const boost::shared_ptr<openvrml::script_factory> -openvrml::script_factory_registry::impl:: -find_using_uri_scheme(const std::string & uri_scheme) const -{ - const factory_map::const_iterator pos = - this->uri_scheme_map_.find(uri_scheme); - return (pos != this->uri_scheme_map_.end()) - ? pos->second - : boost::shared_ptr<script_factory>(); -} - -/** - * @internal - * - * @brief Construct. - */ -openvrml::script_factory_registry::script_factory_registry(): - impl_(new impl) -{ - this->impl_->register_factories(*this); -} - -/** - * @internal - * - * @brief Destroy. - */ -openvrml::script_factory_registry::~script_factory_registry() -{} - -/** - * @brief Register a factory for creating concrete @c script%s. - * - * This function should be called in a script engine module's implementation - * of @c openvrml_script_LTX_register_factory. - * - * @param[in] media_types the set of MIME media types that identify scripts - * supported by the module. - * @param[in] uri_schemes the set of URI schemes that identify scripts - * supported by the module. - * @param[in] factory the factory. - * - * @return @c true if the factory was registered successfully; @c false - * otherwise - */ -bool -openvrml::script_factory_registry:: -register_factory(const std::set<std::string> & media_types, - const std::set<std::string> & uri_schemes, - const boost::shared_ptr<script_factory> & factory) - OPENVRML_THROW2(std::bad_alloc, std::invalid_argument) -{ - return this->impl_->register_factory(media_types, uri_schemes, factory); -} - -/** - * @class openvrml::script_node_metatype openvrml/script.h - * - * @brief Class object for @c script_node%s. - * - * There is one @c script_node_metatype per browser instance. - * - * @see browser::scriptNodeClass - */ - -/** - * @brief Construct. - * - * @param[in] browser the @c browser to be associated with the - * @c script_node_metatype. - */ -openvrml::script_node_metatype::script_node_metatype(openvrml::browser & browser): - node_metatype("urn:X-openvrml:node:Script", browser) -{} - -/** - * @brief Destroy. - */ -openvrml::script_node_metatype::~script_node_metatype() OPENVRML_NOTHROW -{} - -/** - * @brief Not implemented. - * - * This method is not implemented because the Script node implementation, - * unlike other node implementations, cannot provide the implementation of - * an @c EXTERNPROTO. It is an error to call this method. - */ -const boost::shared_ptr<openvrml::node_type> -openvrml::script_node_metatype::do_create_type(const std::string &, - const node_interface_set &) const - OPENVRML_NOTHROW -{ - assert(false); - return boost::shared_ptr<node_type>(); -} - - -/** - * @class openvrml::script_node openvrml/browser.h - * - * @brief Represents a VRML Script node. - */ - -/** - * @internal - * - * @var class openvrml::script_node::script - * - * @brief Abstract base class for script runtimes. - */ - -/** - * @internal - * - * @brief Registry of script engine modules. - */ -openvrml::script_factory_registry -openvrml::script_node::script_factory_registry_; - -/** - * @typedef openvrml::script_node::field_value_map_t - * - * @brief A @c std::map that keys field values on their field name. - */ - -/** - * @class openvrml::script_node::eventout openvrml/script.h - * - * @brief An @c event_emitter along with the emitted value. - */ - -/** - * @var openvrml::script_node & openvrml::script_node::eventout::node_ - * - * @brief The containing @c script_node. - */ - -/** - * @var boost::scoped_ptr<openvrml::field_value> openvrml::script_node::eventout::value_ - * - * @brief The value. - */ - -/** - * @var bool openvrml::script_node::eventout::modified_ - * - * @brief Flag to indicate whether @a value_ has been modified. - */ - -/** - * @var boost::scoped_ptr<openvrml::event_emitter> openvrml::script_node::eventout::emitter_ - * - * @brief Event emitter. - */ - -/** - * @brief Construct. - * - * @param[in] type field value type identifier. - * @param[in] node @c script_node. - * - * @exception std::bad_alloc if memory allocation fails. - */ -openvrml::script_node::eventout::eventout(const field_value::type_id type, - script_node & node) - OPENVRML_THROW1(std::bad_alloc): - node_(node), - value_(field_value::create(type)), - modified_(false), - emitter_(create_emitter(node, *this->value_)) -{} - -/** - * @brief The value that will be sent from the @c eventOut. - * - * @return the value that will be sent from the @c eventOut. - */ -const openvrml::field_value & openvrml::script_node::eventout::value() const - OPENVRML_NOTHROW -{ - return *this->value_; -} - -/** - * @brief Set the value that will be sent from the @c eventOut. - * - * After calling this function, modified will return @c true until - * @c emit_event is called. - * - * @param[in] val field value. - * - * @exception std::bad_alloc if memory allocation fails. - * @exception std::bad_cast if @p val is not the correct type. - */ -void openvrml::script_node::eventout::value(const field_value & val) - OPENVRML_THROW2(std::bad_alloc, std::bad_cast) -{ - using boost::polymorphic_downcast; - - if (this->value_->type() == field_value::sfnode_id) { - this->node_ - .assign_with_self_ref_check( - dynamic_cast<const sfnode &>(val), - *polymorphic_downcast<sfnode *>(this->value_.get())); - } else if (this->value_->type() == field_value::mfnode_id) { - this->node_ - .assign_with_self_ref_check( - dynamic_cast<const mfnode &>(val), - *polymorphic_downcast<mfnode *>(this->value_.get())); - } else { - this->value_->assign(val); // Throws std::bad_alloc, std::bad_cast. - } - this->modified_ = true; -} - -/** - * @brief Whether the value has been modified. - * - * @return @c true if the value has been changed since @c emit_event was last - * called; @c false otherwise. - */ -bool openvrml::script_node::eventout::modified() const OPENVRML_NOTHROW -{ - return this->modified_; -} - -/** - * @brief The @c event_emitter associated with the @c eventout. - * - * @return the @c event_emitter associated with the @c eventout. - */ -openvrml::event_emitter & openvrml::script_node::eventout::emitter() - OPENVRML_NOTHROW -{ - return *this->emitter_; -} - -/** - * @brief Cause the contained @c event_emitter to emit an event. - * - * Events should be emitted from Script nodes by calling this function instead - * of passing the @c event_emitter directly to @c node::emit_event. - * - * @param[in] timestamp the current time. - * - * @exception std::bad_alloc if memory allocation fails. - */ -void openvrml::script_node::eventout::emit_event(const double timestamp) - OPENVRML_THROW1(std::bad_alloc) -{ - node::emit_event(*this->emitter_, timestamp); - this->modified_ = false; -} - -/** - * @typedef openvrml::script_node::eventout_ptr - * - * @brief Reference-counted smart pointer to an @c eventout. - */ - -/** - * @typedef openvrml::script_node::eventout_map_t - * - * @brief Map of @c eventout instances. - */ - -/** - * @internal - * - * @class openvrml::script_node::script_node_type openvrml/script.h - * - * @brief Type objects for @c script_node%s. - * - * @see script_node::type_ - */ - -/** - * @var openvrml::node_interface_set openvrml::script_node::script_node_type::interfaces_ - * - * @brief Node interfaces. - */ - -namespace { - - // - // The order of the node_interfaces in this array is significant. This - // range is used with std::set_difference, so the elements *must* be in - // lexicographically increasing order according to their "id" member. - // - const boost::array<openvrml::node_interface, 4> - built_in_script_interfaces_ = { - openvrml::node_interface(openvrml::node_interface::field_id, - openvrml::field_value::sfbool_id, - "directOutput"), - openvrml::node_interface(openvrml::node_interface::exposedfield_id, - openvrml::field_value::sfnode_id, - "metadata"), - openvrml::node_interface(openvrml::node_interface::field_id, - openvrml::field_value::sfbool_id, - "mustEvaluate"), - openvrml::node_interface(openvrml::node_interface::exposedfield_id, - openvrml::field_value::mfstring_id, - "url") - }; -} - -/** - * @brief Construct. - * - * @param[in] class_ the @c node_metatype for @c script_node%s. - */ -openvrml::script_node::script_node_type:: -script_node_type(script_node_metatype & class_): - node_type(class_, "Script") -{ - for (size_t i = 0; i < built_in_script_interfaces_.size(); ++i) { - bool succeeded = - this->interfaces_.insert(built_in_script_interfaces_[i]).second; - assert(succeeded); - } -} - -/** - * @brief Destroy. - */ -openvrml::script_node::script_node_type::~script_node_type() OPENVRML_NOTHROW -{} - -/** - * @brief Add an interface. - * - * @param[in] interface - * - * @exception std::bad_alloc if memory allocation fails. - * @exception std::invalid_argument if the @c script_node_type already has an - * interface that conflicts with @p interface. - */ -void -openvrml::script_node::script_node_type:: -add_interface(const node_interface & interface_) - OPENVRML_THROW2(std::bad_alloc, std::invalid_argument) -{ - bool succeeded = this->interfaces_.insert(interface_).second; - if (!succeeded) { - throw std::invalid_argument("Interface conflicts with an interface " - "already in this set."); - } -} - -/** - * @brief Get the interfaces for the @c node. - * - * @return the interfaces for the @c node. - */ -const openvrml::node_interface_set & -openvrml::script_node::script_node_type::do_interfaces() const - OPENVRML_NOTHROW -{ - return this->interfaces_; -} - -/** - * @brief Clone... [truncated message content] |