aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/message.h
diff options
context:
space:
mode:
authorGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-06-25 19:05:36 +0000
committerGravatar kenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-06-25 19:05:36 +0000
commitceb561d65bfe234a301979a7e3f7ddc244d349b3 (patch)
tree8b86ec6fda6f7bcce0f214940dcaea5fb73c7d9f /src/google/protobuf/message.h
parentf22943c7d0ce19b35a1e3d7f33c8ede3b6fed485 (diff)
Add Swap(), SwapElements(), and RemoveLast() to Reflection. Patch by Scott Stafford.
Diffstat (limited to 'src/google/protobuf/message.h')
-rw-r--r--src/google/protobuf/message.h21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h
index b05ea954..0f0ef887 100644
--- a/src/google/protobuf/message.h
+++ b/src/google/protobuf/message.h
@@ -97,7 +97,7 @@
// // Use the reflection interface to examine the contents.
// const Reflection* reflection = foo->GetReflection();
// assert(reflection->GetString(foo, text_field) == "Hello World!");
-// assert(reflection->CountField(foo, numbers_field) == 3);
+// assert(reflection->FieldSize(foo, numbers_field) == 3);
// assert(reflection->GetInt32(foo, numbers_field, 0) == 1);
// assert(reflection->GetInt32(foo, numbers_field, 1) == 5);
// assert(reflection->GetInt32(foo, numbers_field, 2) == 42);
@@ -494,6 +494,25 @@ class LIBPROTOBUF_EXPORT Reflection {
virtual void ClearField(Message* message,
const FieldDescriptor* field) const = 0;
+ // Remove the last element of a repeated field.
+ // 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
+ // (using Swap()) so that the one you want removed is at the end, then
+ // call RemoveLast().
+ virtual void RemoveLast(Message* message,
+ const FieldDescriptor* field) const = 0;
+
+ // Swap the complete contents of two messages.
+ virtual void Swap(Message* message1, Message* message2) const = 0;
+
+ // Swap two elements of a repeated field.
+ virtual void SwapElements(Message* message,
+ const FieldDescriptor* field,
+ int index1,
+ int index2) const = 0;
+
// List all fields of the message which are currently set. This includes
// extensions. Singular fields will only be listed if HasField(field) would
// return true and repeated fields will only be listed if FieldSize(field)