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.

File Members

These definitions are not part of any class.
template internal::RepeatedFieldBackInsertIterator< T >
RepeatedFieldBackInserter(RepeatedField< T > *const mutable_field)
Provides a back insert iterator for RepeatedField instances, similar to std::back_inserter().
template internal::RepeatedPtrFieldBackInsertIterator< T >
RepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Provides a back insert iterator for RepeatedPtrField instances, similar to std::back_inserter().
template internal::RepeatedPtrFieldBackInsertIterator< T >
RepeatedFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Special back insert iterator for RepeatedPtrField instances, just in case someone wants to write generic template code that can access both RepeatedFields and RepeatedPtrFields using a common name.
template internal::AllocatedRepeatedPtrFieldBackInsertIterator< T >
AllocatedRepeatedPtrFieldBackInserter(RepeatedPtrField< T > *const mutable_field)
Provides a back insert iterator for RepeatedPtrField instances similar to std::back_inserter() which transfers the ownership while copying elements.

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
typedef
Element value_type
typedef
value_type & reference
typedef
const value_type & const_reference
typedef
value_type * pointer
typedef
const value_type * const_pointer
typedef
int size_type
typedef
ptrdiff_t difference_type
typedef
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator support.
typedef
std::reverse_iterator< iterator > reverse_iterator
RepeatedField()
RepeatedField(const RepeatedField & other)
template
RepeatedField(Iter begin, const Iter & end)
~RepeatedField()
RepeatedField &
operator=(const RepeatedField & other)
int
size() const
const Element &
Get(int index) const
Element *
Mutable(int index)
void
Set(int index, const Element & value)
void
Add(const Element & value)
Element *
Add()
void
RemoveLast()
Remove the last element in the array.
void
ExtractSubrange(int start, int num, Element * elements)
Extract elements with indices in "[[]start .. start+num-1]". more...
void
Clear()
void
MergeFrom(const RepeatedField & other)
void
CopyFrom(const RepeatedField & other)
void
Reserve(int new_size)
Reserve space to expand the field to at least the given size. more...
void
Truncate(int new_size)
Resize the RepeatedField to a new, smaller size. This is O(1).
void
AddAlreadyReserved(const Element & value)
Element *
AddAlreadyReserved()
int
Capacity() const
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
reverse_iterator
rbegin()
const_reverse_iterator
rbegin() const
reverse_iterator
rend()
const_reverse_iterator
rend() const
int
SpaceUsedExcludingSelf() const
Returns the number of bytes used by the repeated field, excluding sizeof(*this)

void RepeatedField::ExtractSubrange(
        int start,
        int num,
        Element * elements)

Extract elements with indices in "[[]start .. start+num-1]".

Copy them into "elements[[]0 .. num-1]" if "elements" is not NULL. Caution: implementation also moves elements with indices [[]start+num ..]. Calling this routine inside a loop can cause quadratic behavior.


void RepeatedField::Reserve(
        int new_size)

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

Avoid inlining of Reserve(): new, copy, and delete[[]] lead to a significant amount of code bloat.

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

typedef
internal::RepeatedPtrIterator< Element > iterator
STL-like iterator support.
typedef
internal::RepeatedPtrIterator< const Element > const_iterator
typedef
Element value_type
typedef
value_type & reference
typedef
const value_type & const_reference
typedef
value_type * pointer
typedef
const value_type * const_pointer
typedef
int size_type
typedef
ptrdiff_t difference_type
typedef
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator support.
typedef
std::reverse_iterator< iterator > reverse_iterator
typedef
internal::RepeatedPtrOverPtrsIterator< Element, void * > pointer_iterator
Custom STL-like iterator that iterates over and returns the underlying pointers to Element rather than Element itself.
typedef
internal::RepeatedPtrOverPtrsIterator< const Element, const void * > const_pointer_iterator
RepeatedPtrField()
RepeatedPtrField(const RepeatedPtrField & other)
template
RepeatedPtrField(Iter begin, const Iter & end)
~RepeatedPtrField()
RepeatedPtrField &
operator=(const RepeatedPtrField & other)
int
size() const
const Element &
Get(int index) const
Element *
Mutable(int index)
Element *
Add()
void
RemoveLast()
Remove the last element in the array. more...
void
DeleteSubrange(int start, int num)
Delete elements with indices in the range [[]start . more...
void
Clear()
void
MergeFrom(const RepeatedPtrField & other)
void
CopyFrom(const RepeatedPtrField & other)
void
Reserve(int new_size)
Reserve space to expand the field to at least the given size. more...
int
Capacity() const
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.
iterator
begin()
const_iterator
begin() const
iterator
end()
const_iterator
end() const
reverse_iterator
rbegin()
const_reverse_iterator
rbegin() const
reverse_iterator
rend()
const_reverse_iterator
rend() const
pointer_iterator
pointer_begin()
const_pointer_iterator
pointer_begin() const
pointer_iterator
pointer_end()
const_pointer_iterator
pointer_end() const
int
SpaceUsedExcludingSelf() const
Returns (an estimate of) the number of bytes used by the repeated field, excluding sizeof(*this).

Advanced memory management

When hardcore memory management becomes necessary -- as it sometimes does here at Google -- the following methods may be useful.
void
AddAllocated(Element * value)
Add an already-allocated object, passing ownership to the RepeatedPtrField.
Element *
ReleaseLast()
Remove the last element and return it, passing ownership to the caller. more...
void
ExtractSubrange(int start, int num, Element ** elements)
Extract elements with indices in the range "[[]start .. start+num-1]". more...
int
ClearedCount() const
Get the number of cleared objects that are currently being kept around for reuse.
void
AddCleared(Element * value)
Add an element to the pool of cleared objects, passing ownership to the RepeatedPtrField. more...
Element *
ReleaseCleared()
Remove a single element from the cleared pool and return it, passing ownership to the caller. more...

void RepeatedPtrField::RemoveLast()

Remove the last element in the array.

Ownership of the element is retained by the array.


void RepeatedPtrField::DeleteSubrange(
        int start,
        int num)

Delete elements with indices in the range [[]start .

. start+num-1]. Caution: implementation moves all elements with indices [[]start+num .. ]. Calling this routine inside a loop can cause quadratic behavior.


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.


Element * RepeatedPtrField::ReleaseLast()

Remove the last element and return it, passing ownership to the caller.

Requires: size() > 0


void RepeatedPtrField::ExtractSubrange(
        int start,
        int num,
        Element ** elements)

Extract elements with indices in the range "[[]start .. start+num-1]".

The caller assumes ownership of the extracted elements and is responsible for deleting them when they are no longer needed. If "elements" is non-NULL, then pointers to the extracted elements are stored in "elements[[]0 .. num-1]" for the convenience of the caller. If "elements" is NULL, then the caller must use some other mechanism to perform any further operations (like deletion) on these elements. Caution: implementation also moves elements with indices [[]start+num ..]. Calling this routine inside a loop can cause quadratic behavior.


void RepeatedPtrField::AddCleared(
        Element * value)

Add an element to the pool of cleared objects, passing ownership to the RepeatedPtrField.

The element must be cleared prior to calling this method.


Element * RepeatedPtrField::ReleaseCleared()

Remove a single element from the cleared pool and return it, passing ownership to the caller.

The element is guaranteed to be cleared. Requires: ClearedCount() > 0

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.