|
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsStaticAtom_h__ |
|
7 #define nsStaticAtom_h__ |
|
8 |
|
9 #include "nsIAtom.h" |
|
10 #include "nsStringBuffer.h" |
|
11 #include "prlog.h" |
|
12 |
|
13 typedef char16_t nsStaticAtomStringType; |
|
14 |
|
15 #define NS_STATIC_ATOM(buffer_name, atom_ptr) { (nsStringBuffer*) &buffer_name, atom_ptr } |
|
16 #define NS_STATIC_ATOM_BUFFER(buffer_name, str_data) static nsFakeStringBuffer< sizeof(str_data) > buffer_name = { 1, sizeof(str_data) * sizeof(nsStaticAtomStringType), MOZ_UTF16(str_data) }; |
|
17 |
|
18 /** |
|
19 * Holds data used to initialize large number of atoms during startup. Use |
|
20 * the above macros to initialize these structs. They should never be accessed |
|
21 * directly other than from AtomTable.cpp |
|
22 */ |
|
23 struct nsStaticAtom { |
|
24 nsStringBuffer* mStringBuffer; |
|
25 nsIAtom ** mAtom; |
|
26 }; |
|
27 |
|
28 /** |
|
29 * This is a struct with the same binary layout as a nsStringBuffer. |
|
30 */ |
|
31 template <uint32_t size> |
|
32 struct nsFakeStringBuffer { |
|
33 int32_t mRefCnt; |
|
34 uint32_t mSize; |
|
35 nsStaticAtomStringType mStringData[size]; |
|
36 }; |
|
37 |
|
38 // Register an array of static atoms with the atom table |
|
39 template<uint32_t N> |
|
40 nsresult |
|
41 NS_RegisterStaticAtoms(const nsStaticAtom (&atoms)[N]) |
|
42 { |
|
43 extern nsresult RegisterStaticAtoms(const nsStaticAtom*, uint32_t aAtomCount); |
|
44 return RegisterStaticAtoms(atoms, N); |
|
45 } |
|
46 |
|
47 #endif |