H3D API  2.4.1
H3DScriptNode.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __H3DSCRIPTNODE_H__
30 #define __H3DSCRIPTNODE_H__
31 
32 #include <H3D/X3DChildNode.h>
33 #include <H3D/X3DUrlObject.h>
34 #include <H3D/DEFNodes.h>
35 
36 namespace H3D {
37 
40  struct H3DAPI_API H3DScriptNode : public X3DChildNode,
41  public X3DUrlObject {
42 
43  // Constructor
44  H3DScriptNode( Inst< MFString > _url = 0 );
45 
47  ~H3DScriptNode();
48 
49  // Standard node functions:
50  // Script interfacing functions, implemented as pure virtuals, to
51  // be implemented for each specifc scripting language
52 
53  virtual bool initialiseParser() {
54  name = getInstanceName();
55  return true;
56  };
57 
58  virtual string getInstanceName() {
59  ostringstream namestr;
60  namestr << "H3DScriptNode_" << this;
61  return namestr.str();
62  };
63 
64  virtual void loadScript( const string &script_filename, const string &script_content= "" )= 0;
65 
66  virtual Field* lookupField( const string &_name ) const = 0;
67 
71  void addNamedNodes( X3D::DEFNodes *dn );
72 
75  void addNamedNode( const string &_name, Node *n );
76 
79  int removeNamedNode( const string &_name );
80 
82  void clearNamedNodes();
83 
86  Node *getNamedNode( const string &_name );
87 
90  protected:
91  typedef std::map< string, Node * > NamedNodes;
92  NamedNodes named_nodes;
93 
94  // Callback for removing named nodes when the nodes are destructed.
95  static void removeNamedNodeCB( Node *n, void *data );
96  };
97 }
98 
99 #endif
Contains the DEFNodes class.
Header file for X3DChildNode, X3D scene-graph node.
Header file for X3DUrlObject, X3D scene-graph node.
The Field class.
Definition: Field.h:46
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
This abstract node type indicates that the concrete nodes which are instantiated based on it may be u...
Definition: X3DChildNode.h:42
This abstract interface is inherited by all nodes that contain data located on the World Wide Web,...
Definition: X3DUrlObject.h:51
Provides a mapping between defined DEF names in X3D and the nodes they refer to.
Definition: DEFNodes.h:92
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
The base class for script nodes.
Definition: H3DScriptNode.h:41
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: H3DScriptNode.h:89