Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Unified Diff: third_party/protobuf/src/google/protobuf/repeated_field_reflection.h

Issue 2590803003: Revert "third_party/protobuf: Update to HEAD (83d681ee2c)" (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/repeated_field_reflection.h
diff --git a/third_party/protobuf/src/google/protobuf/reflection.h b/third_party/protobuf/src/google/protobuf/repeated_field_reflection.h
old mode 100755
new mode 100644
similarity index 59%
copy from third_party/protobuf/src/google/protobuf/reflection.h
copy to third_party/protobuf/src/google/protobuf/repeated_field_reflection.h
index d5a6653cb9f82cf5ea18c0b92699e5e4710b56b5..44d14d5b3ca2efe2d7f4d851b918176bb192ada8
--- a/third_party/protobuf/src/google/protobuf/reflection.h
+++ b/third_party/protobuf/src/google/protobuf/repeated_field_reflection.h
@@ -28,296 +28,21 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// This header defines the RepeatedFieldRef class template used to access
-// repeated fields with protobuf reflection API.
-#ifndef GOOGLE_PROTOBUF_REFLECTION_H__
-#define GOOGLE_PROTOBUF_REFLECTION_H__
+// This header file is protobuf internal. Users should not include this
+// file directly.
+#ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_REFLECTION_H__
+#define GOOGLE_PROTOBUF_REPEATED_FIELD_REFLECTION_H__
#include <memory>
#ifndef _SHARED_PTR_H
#include <google/protobuf/stubs/shared_ptr.h>
#endif
-#include <google/protobuf/message.h>
-#include <google/protobuf/generated_enum_util.h>
+#include <google/protobuf/generated_enum_reflection.h>
namespace google {
namespace protobuf {
namespace internal {
-template<typename T, typename Enable = void>
-struct RefTypeTraits;
-} // namespace internal
-
-template<typename T>
-RepeatedFieldRef<T> Reflection::GetRepeatedFieldRef(
- const Message& message, const FieldDescriptor* field) const {
- return RepeatedFieldRef<T>(message, field);
-}
-
-template<typename T>
-MutableRepeatedFieldRef<T> Reflection::GetMutableRepeatedFieldRef(
- Message* message, const FieldDescriptor* field) const {
- return MutableRepeatedFieldRef<T>(message, field);
-}
-
-// RepeatedFieldRef definition for non-message types.
-template<typename T>
-class RepeatedFieldRef<
- T, typename internal::enable_if<!internal::is_base_of<Message, T>::value>::type> {
- typedef typename internal::RefTypeTraits<T>::iterator IteratorType;
- typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
-
- public:
- bool empty() const {
- return accessor_->IsEmpty(data_);
- }
- int size() const {
- return accessor_->Size(data_);
- }
- T Get(int index) const {
- return accessor_->template Get<T>(data_, index);
- }
-
- typedef IteratorType iterator;
- typedef IteratorType const_iterator;
- typedef T value_type;
- typedef T& reference;
- typedef const T& const_reference;
- typedef int size_type;
- typedef ptrdiff_t difference_type;
-
- iterator begin() const {
- return iterator(data_, accessor_, true);
- }
- iterator end() const {
- return iterator(data_, accessor_, false);
- }
-
- private:
- friend class Reflection;
- RepeatedFieldRef(
- const Message& message,
- const FieldDescriptor* field) {
- const Reflection* reflection = message.GetReflection();
- data_ = reflection->RepeatedFieldData(
- const_cast<Message*>(&message), field,
- internal::RefTypeTraits<T>::cpp_type, NULL);
- accessor_ = reflection->RepeatedFieldAccessor(field);
- }
-
- const void* data_;
- const AccessorType* accessor_;
-};
-
-// MutableRepeatedFieldRef definition for non-message types.
-template<typename T>
-class MutableRepeatedFieldRef<
- T, typename internal::enable_if<!internal::is_base_of<Message, T>::value>::type> {
- typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
-
- public:
- bool empty() const {
- return accessor_->IsEmpty(data_);
- }
- int size() const {
- return accessor_->Size(data_);
- }
- T Get(int index) const {
- return accessor_->template Get<T>(data_, index);
- }
-
- void Set(int index, const T& value) const {
- accessor_->template Set<T>(data_, index, value);
- }
- void Add(const T& value) const {
- accessor_->template Add<T>(data_, value);
- }
- void RemoveLast() const {
- accessor_->RemoveLast(data_);
- }
- void SwapElements(int index1, int index2) const {
- accessor_->SwapElements(data_, index1, index2);
- }
- void Clear() const {
- accessor_->Clear(data_);
- }
-
- void Swap(const MutableRepeatedFieldRef& other) const {
- accessor_->Swap(data_, other.accessor_, other.data_);
- }
-
- template<typename Container>
- void MergeFrom(const Container& container) const {
- typedef typename Container::const_iterator Iterator;
- for (Iterator it = container.begin(); it != container.end(); ++it) {
- Add(*it);
- }
- }
- template<typename Container>
- void CopyFrom(const Container& container) const {
- Clear();
- MergeFrom(container);
- }
-
- private:
- friend class Reflection;
- MutableRepeatedFieldRef(
- Message* message,
- const FieldDescriptor* field) {
- const Reflection* reflection = message->GetReflection();
- data_ = reflection->RepeatedFieldData(
- message, field, internal::RefTypeTraits<T>::cpp_type, NULL);
- accessor_ = reflection->RepeatedFieldAccessor(field);
- }
-
- void* data_;
- const AccessorType* accessor_;
-};
-
-// RepeatedFieldRef definition for message types.
-template<typename T>
-class RepeatedFieldRef<
- T, typename internal::enable_if<internal::is_base_of<Message, T>::value>::type> {
- typedef typename internal::RefTypeTraits<T>::iterator IteratorType;
- typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
-
- public:
- bool empty() const {
- return accessor_->IsEmpty(data_);
- }
- int size() const {
- return accessor_->Size(data_);
- }
- // This method returns a reference to the underlying message object if it
- // exists. If a message object doesn't exist (e.g., data stored in serialized
- // form), scratch_space will be filled with the data and a reference to it
- // will be returned.
- //
- // Example:
- // RepeatedFieldRef<Message> h = ...
- // unique_ptr<Message> scratch_space(h.NewMessage());
- // const Message& item = h.Get(index, scratch_space.get());
- const T& Get(int index, T* scratch_space) const {
- return *static_cast<const T*>(accessor_->Get(data_, index, scratch_space));
- }
- // Create a new message of the same type as the messages stored in this
- // repeated field. Caller takes ownership of the returned object.
- T* NewMessage() const {
- return static_cast<T*>(default_instance_->New());
- }
-
- typedef IteratorType iterator;
- typedef IteratorType const_iterator;
- typedef T value_type;
- typedef T& reference;
- typedef const T& const_reference;
- typedef int size_type;
- typedef ptrdiff_t difference_type;
-
- iterator begin() const {
- return iterator(data_, accessor_, true, NewMessage());
- }
- iterator end() const {
- // The end iterator must not be dereferenced, no need for scratch space.
- return iterator(data_, accessor_, false, NULL);
- }
-
- private:
- friend class Reflection;
- RepeatedFieldRef(
- const Message& message,
- const FieldDescriptor* field) {
- const Reflection* reflection = message.GetReflection();
- data_ = reflection->RepeatedFieldData(
- const_cast<Message*>(&message), field,
- internal::RefTypeTraits<T>::cpp_type,
- internal::RefTypeTraits<T>::GetMessageFieldDescriptor());
- accessor_ = reflection->RepeatedFieldAccessor(field);
- default_instance_ =
- reflection->GetMessageFactory()->GetPrototype(field->message_type());
- }
-
- const void* data_;
- const AccessorType* accessor_;
- const Message* default_instance_;
-};
-
-// MutableRepeatedFieldRef definition for message types.
-template<typename T>
-class MutableRepeatedFieldRef<
- T, typename internal::enable_if<internal::is_base_of<Message, T>::value>::type> {
- typedef typename internal::RefTypeTraits<T>::AccessorType AccessorType;
-
- public:
- bool empty() const {
- return accessor_->IsEmpty(data_);
- }
- int size() const {
- return accessor_->Size(data_);
- }
- // See comments for RepeatedFieldRef<Message>::Get()
- const T& Get(int index, T* scratch_space) const {
- return *static_cast<const T*>(accessor_->Get(data_, index, scratch_space));
- }
- // Create a new message of the same type as the messages stored in this
- // repeated field. Caller takes ownership of the returned object.
- T* NewMessage() const {
- return static_cast<T*>(default_instance_->New());
- }
-
- void Set(int index, const T& value) const {
- accessor_->Set(data_, index, &value);
- }
- void Add(const T& value) const {
- accessor_->Add(data_, &value);
- }
- void RemoveLast() const {
- accessor_->RemoveLast(data_);
- }
- void SwapElements(int index1, int index2) const {
- accessor_->SwapElements(data_, index1, index2);
- }
- void Clear() const {
- accessor_->Clear(data_);
- }
-
- void Swap(const MutableRepeatedFieldRef& other) const {
- accessor_->Swap(data_, other.accessor_, other.data_);
- }
-
- template<typename Container>
- void MergeFrom(const Container& container) const {
- typedef typename Container::const_iterator Iterator;
- for (Iterator it = container.begin(); it != container.end(); ++it) {
- Add(*it);
- }
- }
- template<typename Container>
- void CopyFrom(const Container& container) const {
- Clear();
- MergeFrom(container);
- }
-
- private:
- friend class Reflection;
- MutableRepeatedFieldRef(
- Message* message,
- const FieldDescriptor* field) {
- const Reflection* reflection = message->GetReflection();
- data_ = reflection->RepeatedFieldData(
- message, field, internal::RefTypeTraits<T>::cpp_type,
- internal::RefTypeTraits<T>::GetMessageFieldDescriptor());
- accessor_ = reflection->RepeatedFieldAccessor(field);
- default_instance_ =
- reflection->GetMessageFactory()->GetPrototype(field->message_type());
- }
-
- void* data_;
- const AccessorType* accessor_;
- const Message* default_instance_;
-};
-
-namespace internal {
// Interfaces used to implement reflection RepeatedFieldRef API.
// Reflection::GetRepeatedAccessor() should return a pointer to an singleton
// object that implements the below interface.
@@ -369,7 +94,7 @@ class LIBPROTOBUF_EXPORT RepeatedFieldAccessor {
virtual void Swap(Field* data, const RepeatedFieldAccessor* other_mutator,
Field* other_data) const = 0;
- // Create an iterator that points at the beginning of the repeated field.
+ // Create an iterator that points at the begining of the repeated field.
virtual Iterator* BeginIterator(const Field* data) const = 0;
// Create an iterator that points at the end of the repeated field.
virtual Iterator* EndIterator(const Field* data) const = 0;
@@ -441,13 +166,13 @@ class RepeatedFieldRefIterator
public:
// Constructor for non-message fields.
RepeatedFieldRefIterator(const void* data,
- const RepeatedFieldAccessor* accessor, bool begin)
- : data_(data),
- accessor_(accessor),
- iterator_(begin ? accessor->BeginIterator(data)
- : accessor->EndIterator(data)),
- // The end iterator must not be dereferenced, no need for scratch space.
- scratch_space_(begin ? new AccessorValueType : NULL) {}
+ const RepeatedFieldAccessor* accessor,
+ bool begin)
+ : data_(data), accessor_(accessor),
+ iterator_(begin ? accessor->BeginIterator(data) :
+ accessor->EndIterator(data)),
+ scratch_space_(new AccessorValueType) {
+ }
// Constructor for message fields.
RepeatedFieldRefIterator(const void* data,
const RepeatedFieldAccessor* accessor,
@@ -566,7 +291,7 @@ struct RefTypeTraits<
template<typename T>
struct RefTypeTraits<
- T, typename internal::enable_if< ::google::protobuf::internal::is_same<string, T>::value>::type> {
+ T, typename internal::enable_if<internal::is_same<string, T>::value>::type> {
typedef RepeatedFieldRefIterator<T> iterator;
typedef RepeatedFieldAccessor AccessorType;
typedef string AccessorValueType;
@@ -609,5 +334,4 @@ struct RefTypeTraits<
} // namespace internal
} // namespace protobuf
} // namespace google
-
-#endif // GOOGLE_PROTOBUF_REFLECTION_H__
+#endif // GOOGLE_PROTOBUF_REPEATED_FIELD_REFLECTION_H__

Powered by Google App Engine
This is Rietveld 408576698