2
// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
#ifndef GNASH_CLASS_HIERARCHY_H
20
#define GNASH_CLASS_HIERARCHY_H
26
#include "as_object.h"
28
#include "SafeStack.h"
37
class asBoundAccessor;
40
/// Register all of the ActionScript classes, with their dependencies.
47
/// The file name which contains the library, relative to the
48
/// plugins directory.
49
std::string file_name;
51
/// \brief Initialization function name
53
/// The name of the function which will yield the prototype
54
/// object. It should be a function with signature:
55
/// void init_name(as_object &obj);
56
/// which sets its prototype as the member 'name' in the
57
/// object. See extensions/mysql/mysql_db.cpp function
59
std::string init_name;
61
/// \brief The name of the class.
62
string_table::key name;
65
/// The name of the inherited class.
66
/// Ordinarily should be CLASS_OBJECT
67
string_table::key super_name;
70
/// The name of the namespace in which this belongs.
71
string_table::key namespace_name;
74
/// The version at which this should be added.
80
/// The type of function to use for initing.
81
typedef void (*init_func)(as_object& obj);
84
/// The initialization function
86
/// See extensionClass.init_name for the necessary function.
87
init_func initializer;
89
/// The name of the class.
90
string_table::key name;
93
/// The name of the inherited class. Object is assumed if
94
/// none is given. (Unless name is itself Object)
95
string_table::key super_name;
98
/// The name of the namespace in which this belongs.
99
string_table::key namespace_name;
102
/// The version at which this should be added.
107
/// Declare an ActionScript class, with information on how
108
/// to load it from an extension.
111
/// The extensionClass structure which defines the class.
113
/// @return true, unless the class with c.name already existed.
114
bool declareClass(extensionClass& c);
117
/// Declare an ActionScript class, with information on how
118
/// to instantiate it from the core.
121
/// The nativeClass structure which defines the class.
123
/// @return true, unless the class with c.name already existed.
124
bool declareClass(const nativeClass& c);
127
/// Declare all of the native and extension classes from the
128
/// tables contained in the source file.
130
void massDeclare(int version);
132
/// The global namespace
134
/// Get the global namespace. This is not the Global object -- it only
135
/// contains the classes, not any globally available functions or anything
137
asNamespace* getGlobalNs() { return mGlobalNamespace; }
140
as_object* newOfType(string_table::key /*whattype*/) { return NULL; }
142
/// Find a namespace with the given uri.
145
/// The namespace with the given uri or NULL if it doesn't exist.
146
asNamespace *findNamespace(string_table::key uri)
148
namespacesContainer::iterator i;
149
if (mNamespaces.empty())
151
i = mNamespaces.find(uri);
152
if (i == mNamespaces.end())
158
/// Obtain a new anonymous namespace. Use this to let the object keep track
159
/// of all namespaces, even private ones. Namespaces obtained in this way
160
/// can't ever be found. (They must be kept and passed to the appropriate
163
asNamespace* anonNamespace(string_table::key uri)
165
mAnonNamespaces.grow(1);
166
asNamespace *n = &mAnonNamespaces.top(0);
172
/// Add a namespace to the set. Don't use to add unnamed namespaces.
173
/// Will overwrite existing namespaces 'kind' and 'prefix' values.
174
/// Returns the added space.
175
asNamespace* addNamespace(string_table::key uri)
177
asNamespace *n = findNamespace(uri);
180
// The set should create it automatically here. TODO: Make sure
181
mNamespaces[uri].setURI(uri);
182
return &mNamespaces[uri];
185
/// Set the extension object, since it wasn't set on construction.
186
void setExtension(Extension *e) { mExtension = e; }
188
/// Set the global object, for registrations.
189
void setGlobal(as_object *g) { mGlobal = g; }
191
/// Mark objects for garbage collector.
192
void markReachableResources() const;
194
/// Create a new asClass object for use.
196
{ mClassMemory.grow(1); return &mClassMemory.top(0); }
198
asException *newException()
199
{ mExceptionMemory.grow(1); return &mExceptionMemory.top(0); }
201
/// Create a new asMethod object for use.
202
asMethod *newMethod()
203
{ mMethodMemory.grow(1); return &mMethodMemory.top(0); }
205
asBoundValue *newBoundValue()
206
{ mBoundValueMemory.grow(1); return &mBoundValueMemory.top(0); }
208
asBoundAccessor *newBoundAccessor()
209
{ mBoundAccessorMemory.grow(1); return &mBoundAccessorMemory.top(0); }
212
/// Construct the declaration object. Later set the global and
213
/// extension objects using setGlobal and setExtension
215
mGlobal(NULL), mGlobalNamespace(NULL), mExtension(NULL),
217
mClassMemory(), mExceptionMemory(),
219
mBoundValueMemory(), mBoundAccessorMemory()
220
{ mGlobalNamespace = anonNamespace(0); }
223
/// Delete our private namespaces.
228
asNamespace *mGlobalNamespace;
229
Extension *mExtension;
231
typedef std::map<string_table::key, asNamespace> namespacesContainer;
232
namespacesContainer mNamespaces;
233
SafeStack<asNamespace> mAnonNamespaces;
234
SafeStack<asClass> mClassMemory;
235
SafeStack<asException> mExceptionMemory;
236
SafeStack<asMethod> mMethodMemory;
237
SafeStack<asBoundValue> mBoundValueMemory;
238
SafeStack<asBoundAccessor> mBoundAccessorMemory;
241
std::ostream& operator << (std::ostream& os, const ClassHierarchy::nativeClass& c);
242
std::ostream& operator << (std::ostream& os, const ClassHierarchy::extensionClass& c);
244
} /* namespace gnash */
245
#endif /* GNASH_CLASS_HIERARCHY_H */