164110ea6c95a8fb730f30e6882c89b68ced9070
1 #ifndef __JAVABIND_H__
2 #define __JAVABIND_H__
3 /**
4 * This is a simple mechanism to bind Inkscape to Java, and thence
5 * to all of the nice things that can be layered upon that.
6 *
7 * Authors:
8 * Bob Jamison
9 *
10 * Copyright (C) 2007-2008 Bob Jamison
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 */
27 #include <glibmm.h>
28 #include <vector>
31 namespace Inkscape
32 {
34 namespace Bind
35 {
38 /**
39 * Select which String implementation we want to use
40 */
41 typedef Glib::ustring String;
45 /**
46 *
47 */
48 class Value
49 {
50 public:
52 /**
53 * Types for this value
54 */
55 typedef enum
56 {
57 BIND_VOID,
58 BIND_INT,
59 BIND_BOOLEAN,
60 BIND_DOUBLE,
61 BIND_STRING,
62 BIND_OBJECT
63 } ValueType;
65 /**
66 *
67 */
68 Value()
69 {
70 init();
71 }
73 /**
74 *
75 */
76 Value(const Value &other)
77 {
78 assign(other);
79 }
81 /**
82 *
83 */
84 Value &operator=(const Value &other)
85 {
86 assign(other);
87 return *this;
88 }
90 /**
91 *
92 */
93 virtual ~Value()
94 {
95 }
97 /**
98 *
99 */
100 int getType()
101 { return type; }
103 /**
104 *
105 */
106 void setBoolean(bool val)
107 { type = BIND_BOOLEAN; ival = (int)val; }
109 /**
110 *
111 */
112 bool getBoolean()
113 {
114 if (type == BIND_BOOLEAN)
115 return (bool)ival;
116 else
117 return false;
118 }
120 /**
121 *
122 */
123 void setInt(int val)
124 { type = BIND_INT; ival = val; }
126 /**
127 *
128 */
129 bool getInt()
130 {
131 if (type == BIND_INT)
132 return ival;
133 else
134 return 0;
135 }
137 /**
138 *
139 */
140 void setDouble(double val)
141 { type = BIND_DOUBLE; dval = val; }
143 /**
144 *
145 */
146 double getDouble()
147 {
148 if (type == BIND_DOUBLE)
149 return dval;
150 else
151 return 0.0;
152 }
154 /**
155 *
156 */
157 void setString(const String &val)
158 { type = BIND_STRING; sval = val; }
160 /**
161 *
162 */
163 String getString()
164 {
165 if (type == BIND_STRING)
166 return sval;
167 else
168 return "";
169 }
172 private:
174 void init()
175 {
176 type = BIND_INT;
177 ival = 0;
178 dval = 0.0;
179 sval = "";
180 }
182 void assign(const Value &other)
183 {
184 type = other.type;
185 ival = other.ival;
186 dval = other.dval;
187 sval = other.sval;
188 }
190 int type;
191 long ival;
192 double dval;
193 String sval;
195 };
201 /**
202 *
203 */
204 class JavaBindery
205 {
206 public:
208 /**
209 *
210 */
211 JavaBindery()
212 {}
214 /**
215 *
216 */
217 virtual ~JavaBindery()
218 {}
220 /**
221 *
222 */
223 virtual bool loadJVM()
224 {
225 return false;
226 }
228 /**
229 *
230 */
231 virtual bool callStatic(int /*type*/,
232 const String &/*className*/,
233 const String &/*methodName*/,
234 const String &/*signature*/,
235 const std::vector<Value> &/*params*/,
236 Value &/*retval*/)
237 {
238 return false;
239 }
241 /**
242 *
243 */
244 virtual bool callMain(const String &/*className*/)
245 {
246 return false;
247 }
249 /**
250 *
251 */
252 virtual bool isLoaded()
253 {
254 return false;
255 }
257 /**
258 *
259 */
260 virtual bool doBinding()
261 {
262 return false;
263 }
265 virtual String stdOutGet()
266 {
267 return stdOutBuf;
268 }
270 virtual void stdOutClear()
271 {
272 stdOutBuf.clear();
273 }
275 virtual String stdErrGet()
276 {
277 return stdErrBuf;
278 }
280 virtual void stdErrClear()
281 {
282 stdErrBuf.clear();
283 }
285 virtual void stdOut(int ch)
286 {
287 stdOutBuf.push_back((char)ch);
288 }
290 virtual void stdErr(int ch)
291 {
292 stdErrBuf.push_back((char)ch);
293 }
296 /**
297 * Return a singleton instance of this bindery
298 */
299 static JavaBindery *getInstance();
301 protected:
304 String stdOutBuf;
305 String stdErrBuf;
307 };
313 } // namespace Bind
314 } // namespace Inkscape
316 #endif /* __JAVABIND_H__ */
317 //########################################################################
318 //# E N D O F F I L E
319 //########################################################################