My favorites | English | Sign in

Protocol Buffers

repeated_field.h

#include <google/protobuf/repeated_field.h>
namespace google::protobuf

RepeatedField and RepeatedPtrField are used by generated protocol message classes to manipulate repeated fields.

These classes are very similar to STL's vector, but include a number of optimizations found to be useful specifically in the case of Protocol Buffers. RepeatedPtrField is particularly different from STL vector as it manages ownership of the pointers that it contains.

Typically, clients should not need to access RepeatedField objects directly, but should instead use the accessor functions generated automatically by the protocol compiler.

Classes in this file

RepeatedField is used to represent repeated fields of a primitive type (in other words, everything except strings and nested Messages).
RepeatedPtrField is like RepeatedField, but used for repeated strings or Messages.

template class RepeatedField

#include <google/protobuf/repeated_field.h>
namespace google::protobuf

template <typename Element>

RepeatedField is used to represent repeated fields of a primitive type (in other words, everything except strings and nested Messages).

Most users will not ever use a RepeatedField directly; they will use the get-by-index, set-by-index, and add accessors that are generated for all repeated fields.

Members

typedef
Element * iterator
STL-like iterator support.
typedef
const Element * const_iterator
RepeatedField()
~RepeatedField()
int
size() const
Element
Get(int index) const
Element *
Mutable(int index)
void
Set(int index, Element value)
void
Add(Element value)
void
RemoveLast()
Remove the last element in the array. more...
void
Clear()
void
MergeFrom(const RepeatedField & other)
void
Reserve(int new_size)
Reserve space to expand the field to at least the given size. more...
Element *
mutable_data()
Gets the underlying array. more...
const Element *
data() const
void
Swap(RepeatedField * other)
Swap entire contents with "other".
void
SwapElements(int index1, int index2)
Swap two elements.
iterator
begin()
const_iterator
begin() const
iterator
end()
const_iterator
end() const
int
SpaceUsedExcludingSelf() const
Returns the number of bytes used by the repeated field, excluding sizeof(*this).

void RepeatedField::RemoveLast()

Remove the last element in the array.

We don't provide a way to remove any element other than the last because it invites inefficient use, such as O(n^2) filtering loops that should have been O(n). If you want to remove an element other than the last, the best way to do it is to re-arrange the elements so that the one you want removed is at the end, then call RemoveLast().


void RepeatedField::Reserve(
        int new_size)

Reserve space to expand the field to at least the given size.

If the array is grown, it will always be at least doubled in size.


Element * RepeatedField::mutable_data()

Gets the underlying array.

This pointer is possibly invalidated by any add or remove operation.

template class RepeatedPtrField

#include <google/protobuf/repeated_field.h>
namespace google::protobuf

template <typename Element>

RepeatedPtrField is like RepeatedField, but used for repeated strings or Messages.

Members

RepeatedPtrField()
~RepeatedPtrField()
int
size() const
const Element &
Get(int index) const
Element *
Mutable(int index)
Element *
Add()
void
RemoveLast()
Remove the last element in the array.
void
Clear()
void
MergeFrom(const RepeatedPtrField & other)
void
Reserve(int new_size)
Reserve space to expand the field to at least the given size. more...
Element **
mutable_data()
Gets the underlying array. more...
const Element *const *
data() const
void
Swap(RepeatedPtrField * other)
Swap entire contents with "other".
void
SwapElements(int index1, int index2)
Swap two elements.

void RepeatedPtrField::Reserve(
        int new_size)

Reserve space to expand the field to at least the given size.

This only resizes the pointer array; it doesn't allocate any objects. If the array is grown, it will always be at least doubled in size.


Element ** RepeatedPtrField::mutable_data()

Gets the underlying array.

This pointer is possibly invalidated by any add or remove operation.