2017-08-15 00:22:50 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef nsStringFlags_h
|
|
|
|
#define nsStringFlags_h
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "mozilla/TypedEnumBits.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace detail {
|
|
|
|
// NOTE: these flags are declared public _only_ for convenience inside
|
|
|
|
// the string implementation. And they are outside of the string
|
|
|
|
// class so that the type is the same for both narrow and wide
|
|
|
|
// strings.
|
|
|
|
|
|
|
|
// bits for mDataFlags
|
|
|
|
enum class StringDataFlags : uint16_t {
|
|
|
|
// Some terminology:
|
|
|
|
//
|
|
|
|
// "dependent buffer" A dependent buffer is one that the string class
|
|
|
|
// does not own. The string class relies on some
|
|
|
|
// external code to ensure the lifetime of the
|
|
|
|
// dependent buffer.
|
|
|
|
//
|
2018-03-24 03:31:37 +03:00
|
|
|
// "refcounted buffer" A refcounted buffer is one that the string class
|
|
|
|
// allocates. When it allocates a refcounted string
|
2017-08-15 00:22:50 +03:00
|
|
|
// buffer, it allocates some additional space at
|
|
|
|
// the beginning of the buffer for additional
|
|
|
|
// fields, including a reference count and a
|
|
|
|
// buffer length. See nsStringHeader.
|
|
|
|
//
|
|
|
|
// "adopted buffer" An adopted buffer is a raw string buffer
|
|
|
|
// allocated on the heap (using moz_xmalloc)
|
|
|
|
// of which the string class subsumes ownership.
|
|
|
|
//
|
|
|
|
// Some comments about the string data flags:
|
|
|
|
//
|
2018-03-24 03:31:37 +03:00
|
|
|
// REFCOUNTED, OWNED, and INLINE are all mutually exlusive. They
|
2017-08-15 00:22:50 +03:00
|
|
|
// indicate the allocation type of mData. If none of these flags
|
|
|
|
// are set, then the string buffer is dependent.
|
|
|
|
//
|
2018-03-24 03:31:37 +03:00
|
|
|
// REFCOUNTED, OWNED, or INLINE imply TERMINATED. This is because
|
2017-08-15 00:22:50 +03:00
|
|
|
// the string classes always allocate null-terminated buffers, and
|
|
|
|
// non-terminated substrings are always dependent.
|
|
|
|
//
|
|
|
|
// VOIDED implies TERMINATED, and moreover it implies that mData
|
|
|
|
// points to char_traits::sEmptyBuffer. Therefore, VOIDED is
|
2018-03-24 03:31:37 +03:00
|
|
|
// mutually exclusive with REFCOUNTED, OWNED, and INLINE.
|
2020-01-08 00:37:12 +03:00
|
|
|
//
|
|
|
|
// INLINE requires StringClassFlags::INLINE to be set on the type.
|
2017-08-15 00:22:50 +03:00
|
|
|
|
|
|
|
// IsTerminated returns true
|
|
|
|
TERMINATED = 1 << 0,
|
2018-11-29 00:06:09 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// IsVoid returns true
|
|
|
|
VOIDED = 1 << 1,
|
2018-11-29 00:06:09 +03:00
|
|
|
|
2018-03-24 03:31:37 +03:00
|
|
|
// mData points to a heap-allocated, shareable, refcounted buffer
|
|
|
|
REFCOUNTED = 1 << 2,
|
2018-11-29 00:06:09 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// mData points to a heap-allocated, raw buffer
|
|
|
|
OWNED = 1 << 3,
|
2018-11-29 00:06:09 +03:00
|
|
|
|
2017-09-27 13:19:33 +03:00
|
|
|
// mData points to a writable, inline buffer
|
|
|
|
INLINE = 1 << 4,
|
2018-11-29 00:06:09 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
// mData points to a string literal; DataFlags::TERMINATED will also be set
|
2021-04-20 22:34:03 +03:00
|
|
|
LITERAL = 1 << 5,
|
|
|
|
|
|
|
|
// used to check for invalid flags -- all bits above the last item
|
|
|
|
INVALID_MASK = (uint16_t) ~((LITERAL << 1) - 1)
|
2017-08-15 00:22:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// bits for mClassFlags
|
|
|
|
enum class StringClassFlags : uint16_t {
|
2020-01-08 00:37:12 +03:00
|
|
|
// |this|'s buffer is inline, and requires the type to be binary-compatible
|
|
|
|
// with nsTAutoStringN
|
|
|
|
INLINE = 1 << 0,
|
|
|
|
// |this| requires its buffer is null-terminated
|
2021-04-20 22:34:03 +03:00
|
|
|
NULL_TERMINATED = 1 << 1,
|
|
|
|
// used to check for invalid flags -- all bits above the last item
|
|
|
|
INVALID_MASK = (uint16_t) ~((NULL_TERMINATED << 1) - 1)
|
2017-08-15 00:22:50 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringDataFlags)
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(StringClassFlags)
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|