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