Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / build / scripts / templates / MakeQualifiedNames.cpp.tmpl
1 {% from "macros.tmpl" import license %}
2 {{ license() }}
3
4 #include "config.h"
5
6 #include "{{namespace}}Names.h"
7
8 #include "wtf/StaticConstructors.h"
9
10 namespace blink {
11 namespace {{namespace}}Names {
12
13 using namespace blink;
14
15 DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI)
16
17 {% if tags %}
18 // Tags
19 {% for tag in tags|sort %}
20 DEFINE_GLOBAL({{namespace}}QualifiedName, {{tag|symbol}}Tag)
21 {% endfor %}
22
23
24 PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags()
25 {
26     OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {{namespace}}QualifiedName*[{{namespace}}TagsCount]);
27     {% for tag in tags|sort %}
28     tags[{{loop.index0}}] = reinterpret_cast<const {{namespace}}QualifiedName*>(&{{tag|symbol}}Tag);
29     {% endfor %}
30     return tags.release();
31 }
32
33 {% endif %}
34 // Attributes
35 {% for attr in attrs|sort %}
36 DEFINE_GLOBAL(QualifiedName, {{attr|symbol}}Attr)
37 {% endfor %}
38
39 PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs()
40 {
41     OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName*[{{namespace}}AttrsCount]);
42     {% for attr in attrs|sort %}
43     attrs[{{loop.index0}}] = reinterpret_cast<const blink::QualifiedName*>(&{{attr|symbol}}Attr);
44     {% endfor %}
45     return attrs.release();
46 }
47
48 void init()
49 {
50     // Use placement new to initialize the globals.
51     AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::ConstructFromLiteral);
52
53     // Namespace
54     new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_prefix}}NS);
55     {% for name, tag_list in (tags + attrs)|groupby('name')|sort %}
56     StringImpl* {{tag_list[0]|symbol}}Impl = StringImpl::createStatic("{{name}}", {{name|length}}, {{name|hash}});
57     {% endfor %}
58
59     // Tags
60     {% for tag in tags|sort %}
61     QualifiedName::createStatic((void*)&{{tag|symbol}}Tag, {{tag|symbol}}Impl, {{namespace_prefix}}NS);
62     {% endfor %}
63
64     // Attrs
65     {% for attr in attrs|sort %}
66     {% if use_namespace_for_attrs %}
67     QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl, {{namespace_prefix}}NS);
68     {% else %}
69     QualifiedName::createStatic((void*)&{{attr|symbol}}Attr, {{attr|symbol}}Impl);
70     {% endif %}
71     {% endfor %}
72 }
73
74 } // {{namespace}}
75 } // namespace blink