2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2003-03-21 23:35:14 +03:00
|
|
|
|
|
|
|
#ifndef nsStaticAtom_h__
|
|
|
|
#define nsStaticAtom_h__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
2010-03-08 18:44:59 +03:00
|
|
|
#include "nsStringBuffer.h"
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2016-02-23 08:55:59 +03:00
|
|
|
#define NS_STATIC_ATOM(buffer_name, atom_ptr) \
|
|
|
|
{ (nsStringBuffer*) &buffer_name, atom_ptr }
|
2010-03-08 18:45:00 +03:00
|
|
|
|
2016-02-23 08:55:59 +03:00
|
|
|
#define NS_STATIC_ATOM_BUFFER(buffer_name, str_data) \
|
|
|
|
static nsFakeStringBuffer<sizeof(str_data)> buffer_name = \
|
2016-07-20 07:07:53 +03:00
|
|
|
{ 1, sizeof(str_data) * sizeof(char16_t), (u"" str_data) };
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
/**
|
|
|
|
* Holds data used to initialize large number of atoms during startup. Use
|
|
|
|
* the above macros to initialize these structs. They should never be accessed
|
|
|
|
* directly other than from AtomTable.cpp
|
|
|
|
*/
|
2014-07-09 19:15:21 +04:00
|
|
|
struct nsStaticAtom
|
|
|
|
{
|
2015-01-18 21:57:20 +03:00
|
|
|
// mStringBuffer points to the string buffer for a permanent atom, and is
|
|
|
|
// therefore safe as a non-owning reference.
|
|
|
|
nsStringBuffer* MOZ_NON_OWNING_REF mStringBuffer;
|
2014-07-09 19:15:21 +04:00
|
|
|
nsIAtom** mAtom;
|
2003-03-21 23:35:14 +03:00
|
|
|
};
|
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
/**
|
|
|
|
* This is a struct with the same binary layout as a nsStringBuffer.
|
|
|
|
*/
|
2014-07-09 19:15:21 +04:00
|
|
|
template<uint32_t size>
|
|
|
|
struct nsFakeStringBuffer
|
|
|
|
{
|
|
|
|
int32_t mRefCnt;
|
|
|
|
uint32_t mSize;
|
2016-02-23 08:55:59 +03:00
|
|
|
char16_t mStringData[size];
|
2010-03-08 18:44:59 +03:00
|
|
|
};
|
2003-03-21 23:35:14 +03:00
|
|
|
|
2012-03-09 06:22:57 +04:00
|
|
|
// Register an array of static atoms with the atom table
|
2012-08-22 19:56:38 +04:00
|
|
|
template<uint32_t N>
|
2016-03-18 11:03:43 +03:00
|
|
|
void
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_RegisterStaticAtoms(const nsStaticAtom (&aAtoms)[N])
|
2012-03-09 06:22:57 +04:00
|
|
|
{
|
2016-03-18 11:03:43 +03:00
|
|
|
extern void RegisterStaticAtoms(const nsStaticAtom*, uint32_t aAtomCount);
|
|
|
|
RegisterStaticAtoms(aAtoms, N);
|
2012-03-09 06:22:57 +04:00
|
|
|
}
|
2003-03-21 23:35:14 +03:00
|
|
|
|
|
|
|
#endif
|