2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
23 ///////////////////////////////////////////////////////////////////////////////
26 * For now, use this for StringHolder, instead of something like
27 * std::default_delete.
29 enum struct FreeType
{
36 * String holder class for storing a reference to a string that is not
37 * owned by us. The type indicates whether/how to deallocate the string upon
42 StringHolder(std::nullptr_t
= nullptr)
43 : m_data(nullptr), m_len(0), m_type(FreeType::NoFree
) {}
44 StringHolder(const char* data
, uint32_t len
, FreeType t
)
45 : m_data(data
), m_len(len
), m_type(t
) {}
46 StringHolder(StringHolder
&& o
) noexcept
47 : m_data(o
.m_data
), m_len(o
.m_len
), m_type(o
.m_type
) {
50 StringHolder(const StringHolder
&) = delete;
54 StringHolder
& operator=(StringHolder
&&) noexcept
;
55 StringHolder
& operator=(const StringHolder
&) = delete;
57 uint32_t size() const { return m_len
; }
59 // The length is not the size of the buffer, but the useful size of it. For
60 // example, we could allocate a big buffer, but only uses part of it. The
61 // capacity of the buffer isn't stored here.
62 void shrinkTo(uint32_t newLen
);
64 const char* data() const { return m_data
; }
66 operator bool() const { return data() != nullptr; }
74 ///////////////////////////////////////////////////////////////////////////////