Code

provide skeleton wrappers for all DOM core classes. add content later
[inkscape.git] / src / dom / jsengine.h
1 #ifndef __JSENGINE_H__
2 #define __JSENGINE_H__
3 /**
4  * Phoebe DOM Implementation.
5  *
6  * This is a C++ approximation of the W3C DOM model, which follows
7  * fairly closely the specifications in the various .idl files, copies of
8  * which are provided for reference.  Most important is this one:
9  *
10  * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11  *
12  * Authors:
13  *   Bob Jamison
14  *
15  * Copyright (C) 2006 Bob Jamison
16  *
17  *  This library is free software; you can redistribute it and/or
18  *  modify it under the terms of the GNU Lesser General Public
19  *  License as published by the Free Software Foundation; either
20  *  version 2.1 of the License, or (at your option) any later version.
21  *
22  *  This library is distributed in the hope that it will be useful,
23  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  *  Lesser General Public License for more details.
26  *
27  *  You should have received a copy of the GNU Lesser General Public
28  *  License along with this library; if not, write to the Free Software
29  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
30  */
33 #include "js/jsapi.h"
36 namespace org
37 {
38 namespace w3c
39 {
40 namespace dom
41 {
43 /**
44  * Encapsulate a Spidermonkey JavaScript interpreter.  Init classes, then
45  * wrap around any objects that are needed. 
46  */
47 class JavascriptEngine
48 {
49 public:
51     /**
52      *  Constructor
53      */
54     JavascriptEngine()
55         { init(); }
57     /**
58      *  Copy constructor
59      */
60     JavascriptEngine(const JavascriptEngine &other)
61         { assign(other); }
63     /**
64      *  Assignment operator
65      */
66     JavascriptEngine &operator=(const JavascriptEngine &other)
67         { assign(other); return *this; }
69     /**
70      *  Destructor
71      */
72     virtual ~JavascriptEngine()
73         {}
75     /**
76      *  Startup the javascript engine
77      */
78     bool startup();
80     /**
81      *  Shutdown the javascript engine
82      */
83     bool shutdown();
87 private:
89     void init()
90         {
91         rt        = NULL;
92         cx        = NULL;
93         globalObj = NULL;
94         }
95     
96     void assign(const JavascriptEngine &other)
97         {
98         rt        = other.rt;
99         cx        = other.cx;
100         globalObj = other.globalObj;
101         }
103     /**
104      *  Bind with the basic DOM classes
105      */
106     bool createClasses();
108     /**
109      * Ouput a printf-formatted error message
110      */
111     void error(char *fmt, ...);
113     /**
114      * Ouput a printf-formatted error message
115      */
116     void trace(char *fmt, ...);
118     JSRuntime *rt;
120     JSContext *cx;
122     JSObject *globalObj;
124 };
128 } // namespace dom
129 } // namespace w3c
130 } // namespace org
133 #endif /* __JSENGINE_H__ */