1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ 9 #define GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ 10 11 #define PY_SSIZE_T_CLEAN 12 #include <Python.h> 13 14 #include <cstdint> 15 16 #include "google/protobuf/descriptor.h" 17 #include "google/protobuf/message.h" 18 #include "google/protobuf/pyext/message.h" 19 20 namespace google { 21 namespace protobuf { 22 23 class Message; 24 25 namespace python { 26 27 struct CMessageClass; 28 29 // This struct is used directly for ScalarMap, and is the base class of 30 // MessageMapContainer, which is used for MessageMap. 31 struct MapContainer : public ContainerBase { 32 // Use to get a mutable message when necessary. 33 Message* GetMutableMessage(); 34 35 // We bump this whenever we perform a mutation, to invalidate existing 36 // iterators. 37 uint64_t version; 38 }; 39 40 struct MessageMapContainer : public MapContainer { 41 // The type used to create new child messages. 42 CMessageClass* message_class; 43 }; 44 45 bool InitMapContainers(); 46 47 extern PyTypeObject* MessageMapContainer_Type; 48 extern PyTypeObject* ScalarMapContainer_Type; 49 extern PyTypeObject MapIterator_Type; // Both map types use the same iterator. 50 51 // Builds a MapContainer object, from a parent message and a 52 // field descriptor. 53 extern MapContainer* NewScalarMapContainer( 54 CMessage* parent, const FieldDescriptor* parent_field_descriptor); 55 56 // Builds a MessageMap object, from a parent message and a 57 // field descriptor. 58 extern MessageMapContainer* NewMessageMapContainer( 59 CMessage* parent, const FieldDescriptor* parent_field_descriptor, 60 CMessageClass* message_class); 61 62 } // namespace python 63 } // namespace protobuf 64 } // namespace google 65 66 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__ 67