// Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following disclaimer // in the documentation and/or other materials provided with the // distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef GOOGLE_PROTOBUF_ARENASTRING_H__ #define GOOGLE_PROTOBUF_ARENASTRING_H__ #include <algorithm> #include <string> #include <type_traits> #include <utility> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/arena.h> #include <google/protobuf/port.h> #include <google/protobuf/explicitly_constructed.h> // must be last: #include <google/protobuf/port_def.inc> #ifdef SWIG #error "You cannot SWIG proto headers" #endif namespace google { namespace protobuf { namespace internal { class EpsCopyInputStream; class SwapFieldHelper; // Declared in message_lite.h PROTOBUF_EXPORT extern ExplicitlyConstructedArenaString fixed_address_empty_string; // Lazy string instance to support string fields with non-empty default. // These are initialized on the first call to .get(). class PROTOBUF_EXPORT LazyString { … }; class TaggedStringPtr { … }; static_assert …; // This class encapsulates a pointer to a std::string with or without arena // owned contents, tagged by the bottom bits of the string pointer. It is a // high-level wrapper that almost directly corresponds to the interface required // by string fields in generated code. It replaces the old std::string* pointer // in such cases. // // The string pointer is tagged to be either a default, externally owned value, // a mutable heap allocated value, or an arena allocated value. The object uses // a single global instance of an empty string that is used as the initial // default value. Fields that have empty default values directly use this global // default. Fields that have non empty default values are supported through // lazily initialized default values managed by the LazyString class. // // Generated code and reflection code both ensure that ptr_ is never null. // Because ArenaStringPtr is used in oneof unions, its constructor is a NOP and // the field is always manually initialized via method calls. // // See TaggedStringPtr for more information about the types of string values // being held, and the mutable and ownership invariants for each type. struct PROTOBUF_EXPORT ArenaStringPtr { … }; inline void ArenaStringPtr::InitDefault() { … } inline void ArenaStringPtr::InitExternal(const std::string* str) { … } inline void ArenaStringPtr::InitAllocated(std::string* str, Arena* arena) { … } inline void ArenaStringPtr::Set(const char* s, Arena* arena) { … } inline void ArenaStringPtr::Set(const char* s, size_t n, Arena* arena) { … } inline void ArenaStringPtr::SetBytes(ConstStringParam value, Arena* arena) { … } inline void ArenaStringPtr::SetBytes(std::string&& value, Arena* arena) { … } inline void ArenaStringPtr::SetBytes(const char* s, Arena* arena) { … } inline void ArenaStringPtr::SetBytes(const void* p, size_t n, Arena* arena) { … } // Make sure rhs_arena allocated rhs, and lhs_arena allocated lhs. inline PROTOBUF_NDEBUG_INLINE void ArenaStringPtr::InternalSwap( // ArenaStringPtr* rhs, Arena* rhs_arena, // ArenaStringPtr* lhs, Arena* lhs_arena) { … } inline void ArenaStringPtr::ClearNonDefaultToEmpty() { … } inline std::string* ArenaStringPtr::UnsafeMutablePointer() { … } } // namespace internal } // namespace protobuf } // namespace google #include <google/protobuf/port_undef.inc> #endif // GOOGLE_PROTOBUF_ARENASTRING_H__