Gnash  0.8.11dev
Namespace.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc.
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef GNASH_AS_NAMESPACE_H
20 #define GNASH_AS_NAMESPACE_H
21 
22 #include "string_table.h"
23 #include <map>
24 
25 // Forward declarations
26 namespace gnash {
27  namespace abc {
28  class Class;
29  }
30  class ClassHierarchy;
31  class string_table;
32 }
33 
34 namespace gnash {
35 namespace abc {
36 
38 //
41 //
45 //
48 class Namespace
49 {
50 public:
51 
54  :
55  _parent(0),
56  _uri(0),
57  _prefix(0),
58  _scripts(),
59  mRecursePrevent(false),
60  _private(false),
61  _protected(false),
62  _package(false)
63  {}
64 
65  void markReachableResources() const { /* TODO */ }
66 
68  void setParent(Namespace* p) { _parent = p; }
69 
70  Namespace* getParent() { return _parent; }
71 
73  void setURI(string_table::key name) { _uri = name; }
74 
76  string_table::key getURI() const { return _uri; }
77 
79  string_table::key getPrefix() const { return _prefix; }
80 
84  {
85  if (getScriptInternal(name)) return false;
86  _scripts[static_cast<std::size_t>(name)] = a;
87  return true;
88  }
89 
90  void stubPrototype(ClassHierarchy& ch, string_table::key name);
91 
95  {
96  if (mRecursePrevent) return NULL;
97 
98  Class* found = getScriptInternal(name);
99 
100  if (found || !getParent()) return found;
101 
102  mRecursePrevent = true;
103  found = getParent()->getScript(name);
104  mRecursePrevent = false;
105  return found;
106  }
107 
108  void dump(string_table& st);
109 
110  void setPrivate() { _private = true; }
111  void unsetPrivate() { _private = false; }
112  bool isPrivate() { return _private; }
113 
114  void setProtected() { _protected = true; }
115  void unsetProtected() { _protected = false; }
116  bool isProtected() { return _protected; }
117 
118  void setPackage() { _package = true; }
119  void unsetPackage() { _package = false; }
120  bool isPackage() { return _package; }
121 
122 private:
123 
124  Namespace* _parent;
125  string_table::key _uri;
126  string_table::key _prefix;
127 
128  typedef std::map<string_table::key, Class*> container;
129  container _scripts;
130  mutable bool mRecursePrevent;
131 
132  bool _private;
133  bool _protected;
134  bool _package;
135 
136  Class* getScriptInternal(string_table::key name) const
137  {
138  container::const_iterator i;
139 
140  if (_scripts.empty()) return NULL;
141 
142  i = _scripts.find(name);
143 
144  if (i == _scripts.end()) return NULL;
145  return i->second;
146  }
147 };
148 
149 } // namespace abc
150 } // namespace gnash
151 
152 #endif
Definition: GnashKey.h:147
bool addScript(string_table::key name, Class *a)
Definition: Namespace.h:83
void unsetProtected()
Definition: Namespace.h:115
string_table::key getPrefix() const
What is the XML prefix?
Definition: Namespace.h:79
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
Namespace()
Create an empty namespace.
Definition: Namespace.h:53
bool isPrivate()
Definition: Namespace.h:112
Represent an ActionScript Namespace.
Definition: Namespace.h:48
Register all of the ActionScript classes, with their dependencies.
Definition: ClassHierarchy.h:40
A general use string table.
Definition: string_table.h:41
void setParent(Namespace *p)
Our parent (for protected)
Definition: Namespace.h:68
A class to represent AS3 Classes.
Definition: Class.h:75
Class * getScript(string_table::key name)
Definition: Namespace.h:94
void setURI(string_table::key name)
Set the uri.
Definition: Namespace.h:73
void markReachableResources() const
Definition: Namespace.h:65
bool isProtected()
Definition: Namespace.h:116
void unsetPrivate()
Definition: Namespace.h:111
Namespace * getParent()
Definition: Namespace.h:70
void setPackage()
Definition: Namespace.h:118
string_table::key getURI() const
What is the Uri of the namespace?
Definition: Namespace.h:76
Definition: GnashKey.h:162
Definition: GnashKey.h:155
void unsetPackage()
Definition: Namespace.h:119
void setPrivate()
Definition: Namespace.h:110
std::size_t key
Definition: string_table.h:83
bool isPackage()
Definition: Namespace.h:120
std::string name
Definition: LocalConnection_as.cpp:149
void setProtected()
Definition: Namespace.h:114