Go to the documentation of this file.
48 #ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__
49 #define GOOGLE_PROTOBUF_REPEATED_FIELD_H__
60 #include <type_traits>
62 #include <google/protobuf/stubs/logging.h>
63 #include <google/protobuf/stubs/common.h>
65 #include <google/protobuf/arena.h>
66 #include <google/protobuf/message_lite.h>
67 #include <google/protobuf/port.h>
71 #include <google/protobuf/port_def.inc>
74 #error "You cannot SWIG proto headers"
95 template <
typename Iter>
97 return static_cast<int>(std::distance(
begin,
end));
100 template <
typename Iter>
102 std::input_iterator_tag ) {
106 template <
typename Iter>
108 typedef typename std::iterator_traits<Iter>::iterator_category Category;
113 template <
typename T>
125 inline typename std::enable_if<(kSize == 0),
void>::
type memswap(
char*,
char*) {
128 #define PROTO_MEMSWAP_DEF_SIZE(reg_type, max_size) \
129 template <int kSize> \
130 typename std::enable_if<(kSize >= sizeof(reg_type) && kSize < (max_size)), \
132 memswap(char* p, char* q) { \
133 SwapBlock<reg_type>(p, q); \
134 memswap<kSize - sizeof(reg_type)>(p + sizeof(reg_type), \
135 q + sizeof(reg_type)); \
142 #ifdef __SIZEOF_INT128__
149 #undef PROTO_MEMSWAP_DEF_SIZE
157 template <
typename Element>
160 alignof(
Arena) >=
alignof(Element),
161 "We only support types that have an alignment smaller than Arena");
169 template <
typename Iter,
170 typename =
typename std::enable_if<std::is_constructible<
184 const Element&
Get(
int index)
const;
190 const Element&
at(
int index)
const;
200 template <
typename Iter>
212 PROTOBUF_ATTRIBUTE_REINITIALIZES
void Clear();
217 template <
typename Iter>
243 const Element*
data()
const;
369 return reinterpret_cast<Rep*
>(
addr);
385 if (
rep !=
nullptr) {
389 for (; e < limit; e++) {
394 #if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation)
396 ::operator
delete(
static_cast<void*
>(
rep),
bytes);
398 ::operator
delete(
static_cast<void*
>(
rep));
487 friend class ::google::protobuf::internal::ParseContext;
496 template <
typename Element,
498 struct ElementCopier {
506 template <
typename Element>
508 : current_size_(0), total_size_(0), arena_or_elements_(nullptr) {}
510 template <
typename Element>
512 : current_size_(0), total_size_(0), arena_or_elements_(
arena) {}
514 template <
typename Element>
516 : current_size_(0), total_size_(0), arena_or_elements_(nullptr) {
517 if (other.current_size_ != 0) {
518 Reserve(other.
size());
519 AddNAlreadyReserved(other.
size());
524 template <
typename Element>
525 template <
typename Iter,
typename>
527 : current_size_(0), total_size_(0), arena_or_elements_(nullptr) {
531 template <
typename Element>
539 if (total_size_ > 0) {
540 InternalDeallocate(
rep(), total_size_);
544 template <
typename Element>
547 if (
this != &other)
CopyFrom(other);
551 template <
typename Element>
554 #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
556 #else // PROTOBUF_FORCE_COPY_IN_MOVE
560 if (other.GetArena()) {
563 InternalSwap(&other);
565 #endif // !PROTOBUF_FORCE_COPY_IN_MOVE
568 template <
typename Element>
573 if (
this != &other) {
575 #ifdef PROTOBUF_FORCE_COPY_IN_MOVE
581 InternalSwap(&other);
587 template <
typename Element>
589 return current_size_ == 0;
592 template <
typename Element>
594 return current_size_;
597 template <
typename Element>
602 template <
typename Element>
605 elements()[current_size_++] =
value;
608 template <
typename Element>
611 return &elements()[current_size_++];
614 template <
typename Element>
617 << total_size_ <<
", " << current_size_;
622 Element*
ret = unsafe_elements() + current_size_;
627 template <
typename Element>
637 template <
typename Element>
641 return elements()[
index];
644 template <
typename Element>
648 return elements()[
index];
651 template <
typename Element>
655 return elements()[
index];
658 template <
typename Element>
662 return &elements()[
index];
665 template <
typename Element>
672 template <
typename Element>
675 if (
static_cast<int>(
size) == total_size_) {
679 Reserve(total_size_ + 1);
684 current_size_ =
size + 1;
687 template <
typename Element>
690 if (
static_cast<int>(
size) == total_size_) Reserve(total_size_ + 1);
692 current_size_ =
size + 1;
696 template <
typename Element>
697 template <
typename Iter>
715 FastAdder fast_adder(
this);
720 template <
typename Element>
726 template <
typename Element>
734 if (elements !=
nullptr) {
735 for (
int i = 0;
i <
num; ++
i) elements[
i] = this->
Get(
i + start);
740 for (
int i =
start +
num;
i < this->current_size_; ++
i)
742 this->Truncate(this->current_size_ -
num);
746 template <
typename Element>
751 template <
typename Element>
754 if (other.current_size_ != 0) {
755 int existing_size =
size();
756 Reserve(existing_size + other.
size());
757 AddNAlreadyReserved(other.
size());
758 CopyArray(Mutable(existing_size), &other.Get(0), other.
size());
762 template <
typename Element>
764 if (&other ==
this)
return;
769 template <
typename Element>
770 template <
typename Iter>
776 template <
typename Element>
782 template <
typename Element>
784 const_iterator
first, const_iterator last) {
785 size_type first_offset =
first - cbegin();
787 Truncate(
std::copy(last, cend(),
begin() + first_offset) - cbegin());
789 return begin() + first_offset;
792 template <
typename Element>
794 return unsafe_elements();
797 template <
typename Element>
799 return unsafe_elements();
802 template <
typename Element>
808 "offsetof() requires standard layout before c++17");
810 sizeof(this->arena_or_elements_) -
812 reinterpret_cast<char*
>(
this) + offsetof(
RepeatedField, current_size_),
813 reinterpret_cast<char*
>(other) + offsetof(
RepeatedField, current_size_));
816 template <
typename Element>
818 if (
this == other)
return;
819 #ifdef PROTOBUF_FORCE_COPY_IN_SWAP
821 #else // PROTOBUF_FORCE_COPY_IN_SWAP
822 if (
GetArena() == other->GetArena()) {
823 #endif // !PROTOBUF_FORCE_COPY_IN_SWAP
827 temp.MergeFrom(*
this);
829 other->UnsafeArenaSwap(&
temp);
833 template <
typename Element>
835 if (
this == other)
return;
839 template <
typename Element>
842 swap(elements()[index1], elements()[index2]);
845 template <
typename Element>
848 return unsafe_elements();
850 template <
typename Element>
853 return unsafe_elements();
855 template <
typename Element>
858 return unsafe_elements();
860 template <
typename Element>
862 return unsafe_elements() + current_size_;
864 template <
typename Element>
867 return unsafe_elements() + current_size_;
869 template <
typename Element>
872 return unsafe_elements() + current_size_;
875 template <
typename Element>
877 return total_size_ > 0 ? (total_size_ *
sizeof(Element) + kRepHeaderSize) : 0;
906 template <
typename Element>
908 if (total_size_ >=
new_size)
return;
909 Rep* old_rep = total_size_ > 0 ?
rep() : nullptr;
916 <<
"Requested size is too large to fit into size_t.";
918 kRepHeaderSize +
sizeof(Element) *
static_cast<size_t>(
new_size);
919 if (
arena ==
nullptr) {
920 new_rep =
static_cast<Rep*
>(::operator
new(
bytes));
922 new_rep =
reinterpret_cast<Rep*
>(Arena::CreateArray<char>(
arena,
bytes));
924 new_rep->arena =
arena;
925 int old_total_size = total_size_;
931 arena_or_elements_ = new_rep->elements;
941 Element*
e = &elements()[0];
942 Element* limit =
e + total_size_;
943 for (;
e < limit;
e++) {
946 if (current_size_ > 0) {
947 MoveArray(&elements()[0], old_rep->elements, current_size_);
951 InternalDeallocate(old_rep, old_total_size);
955 template <
typename Element>
958 if (current_size_ > 0) {
963 template <
typename Element>
969 template <
typename Element>
972 internal::ElementCopier<Element>()(
to,
from, array_size);
977 template <
typename Element,
bool HasTrivialCopy>
978 void ElementCopier<Element, HasTrivialCopy>::operator()(Element*
to,
984 template <
typename Element>
985 struct ElementCopier<Element,
true> {
987 memcpy(
to,
from,
static_cast<size_t>(array_size) *
sizeof(Element));
1007 template <
typename T>
1008 class RepeatedFieldBackInsertIterator {
1018 : field_(mutable_field) {}
1037 template <
typename T>
1040 return internal::RepeatedFieldBackInsertIterator<T>(mutable_field);
1055 #include <google/protobuf/port_undef.inc>
1057 #endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__
friend class TestRepeatedFieldHelper
void Swap(T &lhs, T &rhs) noexcept(IsNothrowSwappable< T >::value)
const_iterator cbegin() const
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FastAdderImpl)
Arena * GetArena(MessageLite *msg, int64 arena_offset)
const Descriptor::ReservedRange value
static const int kInitialSize
Element * elements() const
void * arena_or_elements_
FastAdderImpl(RepeatedField *rf)
static bool reserve(upb_pb_encoder *e, size_t bytes)
const_iterator cend() const
void operator()(Element *to, const Element *from, int array_size)
void ExtractSubrange(int start, int num, Element *elements)
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
static PyObject * CopyFrom(CMessage *self, PyObject *arg)
void Add(const Element &val)
int SpaceUsedExcludingSelf() const
const Element * data() const
#define GOOGLE_CHECK_LT(A, B)
static PyObject * Add(PyObject *self, PyObject *file_descriptor_proto)
Element & operator[](int index)
void Add(const Element &value)
iterator erase(const_iterator position)
#define T(upbtypeconst, upbtype, ctype, default_value)
RepeatedField * repeated_field_
grpc_core::ScopedArenaPtr arena
static GraphId Get(const IdMap &id, int num)
static const size_t kRepHeaderSize
std::reverse_iterator< const_iterator > const_reverse_iterator
def Iter(n, format, sep='')
const Element & operator[](int index) const
std::reverse_iterator< iterator > reverse_iterator
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void Truncate(int new_size)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
struct RepeatedField RepeatedField
int CalculateReserveSize(int total_size, int new_size)
PROTOBUF_ATTRIBUTE_REINITIALIZES void Assign(Iter begin, Iter end)
RepeatedField * repeated_field_
ptrdiff_t difference_type
void InternalSwap(RepeatedField *other)
int ToIntSize(size_t size)
#define GOOGLE_CHECK_GE(A, B)
constexpr int kRepeatedFieldUpperClampLimit
FastAdderImpl(RepeatedField *rf)
unsigned __int64 uint64_t
void UnsafeArenaSwap(RepeatedField *other)
Element * AddAlreadyReserved()
void Resize(int new_size, const Element &value)
std::enable_if<(kSize==0), void >::type memswap(char *, char *)
const Element & at(int index) const
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
reverse_iterator rbegin()
const typedef Element * const_iterator
Element * AddNAlreadyReserved(int elements)
void MoveArray(Element *to, Element *from, int size)
std::output_iterator_tag iterator_category
void CopyFrom(const RepeatedField &other)
RepeatedFieldBackInsertIterator< T > & operator++()
int CalculateReserve(Iter begin, Iter end, std::forward_iterator_tag)
const typedef value_type * const_pointer
RepeatedField & operator=(const RepeatedField &other)
void operator()(Element *to, const Element *from, int array_size)
void CopyArray(Element *to, const Element *from, int size)
void Set(int index, const Element &value)
internal::RepeatedFieldBackInsertIterator< T > RepeatedFieldBackInserter(RepeatedField< T > *const mutable_field)
void InternalDeallocate(Rep *rep, int size)
UniquePtr< SSL_SESSION > ret
const_reverse_iterator rend() const
void CopyArray(const T *from, size_t size, U *to)
FastAdderImpl<> FastAdder
std::ptrdiff_t difference_type
RepeatedFieldBackInsertIterator< T > & operator++(int)
void Swap(RepeatedField *other)
const Element & Get(int index) const
constexpr int kRepeatedFieldLowerClampLimit
const_reverse_iterator rbegin() const
void SwapBlock(char *p, char *q)
const typedef value_type & const_reference
void InternalArenaConstructable_
#define PROTO_MEMSWAP_DEF_SIZE(reg_type, max_size)
RepeatedFieldBackInsertIterator< T > & operator=(const T &value)
void MergeFrom(const RepeatedField &other)
PolymorphicAction< internal::AssignAction< T1, T2 > > Assign(T1 *ptr, T2 val)
RepeatedFieldBackInsertIterator< T > & operator*()
Element * Mutable(int index)
size_t SpaceUsedExcludingSelfLong() const
RepeatedFieldBackInsertIterator(RepeatedField< T > *const mutable_field)
void Reserve(int new_size)
Element * unsafe_elements() const
void SwapElements(int index1, int index2)
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:03