Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 00003 // Free Software Foundation, Inc. 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 00019 #ifndef GNASH_AS_NAMESPACE_H 00020 #define GNASH_AS_NAMESPACE_H 00021 00022 #include "string_table.h" 00023 #include <map> 00024 00025 // Forward declarations 00026 namespace gnash { 00027 namespace abc { 00028 class Class; 00029 } 00030 class ClassHierarchy; 00031 class string_table; 00032 } 00033 00034 namespace gnash { 00035 namespace abc { 00036 00038 // 00041 // 00045 // 00048 class Namespace 00049 { 00050 public: 00051 00053 Namespace() 00054 : 00055 _parent(0), 00056 _uri(0), 00057 _prefix(0), 00058 _scripts(), 00059 mRecursePrevent(false), 00060 _private(false), 00061 _protected(false), 00062 _package(false) 00063 {} 00064 00065 void markReachableResources() const { /* TODO */ } 00066 00068 void setParent(Namespace* p) { _parent = p; } 00069 00070 Namespace* getParent() { return _parent; } 00071 00073 void setURI(string_table::key name) { _uri = name; } 00074 00076 string_table::key getURI() const { return _uri; } 00077 00079 string_table::key getPrefix() const { return _prefix; } 00080 00083 bool addScript(string_table::key name, Class* a) 00084 { 00085 if (getScriptInternal(name)) return false; 00086 _scripts[static_cast<std::size_t>(name)] = a; 00087 return true; 00088 } 00089 00090 void stubPrototype(ClassHierarchy& ch, string_table::key name); 00091 00094 Class* getScript(string_table::key name) 00095 { 00096 if (mRecursePrevent) return NULL; 00097 00098 Class* found = getScriptInternal(name); 00099 00100 if (found || !getParent()) return found; 00101 00102 mRecursePrevent = true; 00103 found = getParent()->getScript(name); 00104 mRecursePrevent = false; 00105 return found; 00106 } 00107 00108 void dump(string_table& st); 00109 00110 void setPrivate() { _private = true; } 00111 void unsetPrivate() { _private = false; } 00112 bool isPrivate() { return _private; } 00113 00114 void setProtected() { _protected = true; } 00115 void unsetProtected() { _protected = false; } 00116 bool isProtected() { return _protected; } 00117 00118 void setPackage() { _package = true; } 00119 void unsetPackage() { _package = false; } 00120 bool isPackage() { return _package; } 00121 00122 private: 00123 00124 Namespace* _parent; 00125 string_table::key _uri; 00126 string_table::key _prefix; 00127 00128 typedef std::map<string_table::key, Class*> container; 00129 container _scripts; 00130 mutable bool mRecursePrevent; 00131 00132 bool _private; 00133 bool _protected; 00134 bool _package; 00135 00136 Class* getScriptInternal(string_table::key name) const 00137 { 00138 container::const_iterator i; 00139 00140 if (_scripts.empty()) return NULL; 00141 00142 i = _scripts.find(name); 00143 00144 if (i == _scripts.end()) return NULL; 00145 return i->second; 00146 } 00147 }; 00148 00149 } // namespace abc 00150 } // namespace gnash 00151 00152 #endif