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