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_NAME_H
20 #define GNASH_AS_NAME_H
21 
22 #include <vector>
23 
24 namespace gnash {
25     class as_object;
26     class Property;
27     namespace abc {
28         class Namespace;
29     }
30 }
31 
32 namespace gnash {
33 namespace abc {
34 
35 /// This type should always be used for the index of AbcBlocks' names.
36 //
37 /// It serves to distinguish them from global names, which are identified
38 /// by a string_table::key. This identifies global names' position in the
39 /// string_table. AbcBlock resources have nothing to do with the string_table
40 /// and their URI does not correspond to a string_table entry, so it
41 /// makes no sense whatsoever to use string_table::key to index them.
42 typedef size_t URI;
43 
44 /// An MultiName represents a single ABC multiname.
45 //
46 /// All MultiNames are internal to a single AbcBlock. Most are created during
47 /// parsing, though the Machine can also create them for the lifetime of
48 /// a single script run (which corresponds to an AbcBlock).
49 //
50 /// This means it is possible to store internal ABC URI of multiname here.
51 class MultiName
52 {
53 public:
54 
55 	enum Kind
56 	{
57 		KIND_Qname = 0x07,
58 		KIND_QnameA = 0x0D,
59 		KIND_RTQname = 0x0F,
60 		KIND_RTQnameA = 0x10,
61 		KIND_RTQnameL = 0x11,
62 		KIND_RTQnameLA = 0x12,
63 		KIND_Multiname = 0x09,
64 		KIND_MultinameA = 0x0E,
65 		KIND_MultinameL = 0x1B,
66 		KIND_MultinameLA = 0x1C
67 	};
68 
MultiName()69 	MultiName()
70         :
71         _flags(0),
72         _namespaceSet(0),
73         _abcName(0),
74         _globalName(0),
75 		_namespace(0)
76 	{}
77 
setFlags(Kind kind)78     void setFlags(Kind kind) {
79         _flags = kind;
80     }
81 
flags()82     std::uint8_t flags() const {
83         return _flags;
84     }
85 
86     /// If true, the name needs a run-time string value to complete it.
isRuntime()87 	bool isRuntime() { return _flags & FLAG_RTNAME; }
88 
89 	/// If true, the name needs a run-time namespace to complete it.
isRtns()90 	bool isRtns() { return _flags & FLAG_RTNS; }
91 
isQName()92 	bool isQName() { return _flags & FLAG_QNAME; }
setQName()93 	void setQName() { _flags |= FLAG_QNAME; }
94 
setNamespace(Namespace * ns)95 	void setNamespace(Namespace *ns) { _namespace = ns; }
getNamespace()96 	Namespace* getNamespace() const { return _namespace; }
97 
getABCName()98     abc::URI getABCName() const { return _abcName; }
setABCName(abc::URI n)99 	void setABCName(abc::URI n) { _abcName = n;}
100 
getGlobalName()101 	string_table::key getGlobalName() const { return _globalName;}
setGlobalName(string_table::key n)102 	void setGlobalName(string_table::key n) { _globalName = n;}
103 
setAttr()104 	void setAttr() { _flags |= FLAG_ATTR; }
105 
fill(as_object *)106 	void fill(as_object*) {}
107 
108 	Property* findProperty();
109 
namespaceSet(std::vector<Namespace * > * v)110     void namespaceSet(std::vector<Namespace*>* v) {
111         _namespaceSet = v;
112     }
113 
namespaceSet()114     const std::vector<Namespace*>* namespaceSet() const {
115         return _namespaceSet;
116     }
117 
118 private:
119 
120 	enum Flag
121 	{
122 		FLAG_ATTR = 0x01,
123 		FLAG_QNAME = 0x02,
124 		FLAG_RTNS = 0x04,
125 		FLAG_RTNAME = 0x08,
126 		FLAG_NSSET = 0x10
127 	};
128 
129     std::uint8_t _flags;
130 
131     std::vector<Namespace*>* _namespaceSet;
132 
133     abc::URI _abcName;
134 
135 	string_table::key _globalName;
136 
137 	Namespace* _namespace;
138 
139 };
140 
141 } // namespace abc
142 } // namespace gnash
143 #endif
144