webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
map_container.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
32 #define GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
33 
34 #include <Python.h>
35 
36 #include <memory>
37 #ifndef _SHARED_PTR_H
39 #endif
40 
43 
44 namespace google {
45 namespace protobuf {
46 
47 class Message;
48 
49 #ifdef _SHARED_PTR_H
50 using std::shared_ptr;
51 #else
52 using internal::shared_ptr;
53 #endif
54 
55 namespace python {
56 
57 struct CMessage;
58 struct CMessageClass;
59 
60 // This struct is used directly for ScalarMap, and is the base class of
61 // MessageMapContainer, which is used for MessageMap.
62 struct MapContainer {
64 
65  // This is the top-level C++ Message object that owns the whole
66  // proto tree. Every Python MapContainer holds a
67  // reference to it in order to keep it alive as long as there's a
68  // Python object that references any part of the tree.
70 
71  // Pointer to the C++ Message that contains this container. The
72  // MapContainer does not own this pointer.
73  const Message* message;
74 
75  // Use to get a mutable message when necessary.
77 
78  // Weak reference to a parent CMessage object (i.e. may be NULL.)
79  //
80  // Used to make sure all ancestors are also mutable when first
81  // modifying the container.
83 
84  // Pointer to the parent's descriptor that describes this
85  // field. Used together with the parent's message when making a
86  // default message instance mutable.
87  // The pointer is owned by the global DescriptorPool.
91 
92  // We bump this whenever we perform a mutation, to invalidate existing
93  // iterators.
95 
96  // Releases the messages in the container to a new message.
97  //
98  // Returns 0 on success, -1 on failure.
99  int Release();
100 
101  // Set the owner field of self and any children of self.
102  void SetOwner(const shared_ptr<Message>& new_owner) {
103  owner = new_owner;
104  }
105 };
106 
108  // The type used to create new child messages.
110 
111  // A dict mapping Message* -> CMessage.
112  PyObject* message_dict;
113 };
114 
115 #if PY_MAJOR_VERSION >= 3
116  extern PyObject *MessageMapContainer_Type;
117  extern PyType_Spec MessageMapContainer_Type_spec;
118  extern PyObject *ScalarMapContainer_Type;
119  extern PyType_Spec ScalarMapContainer_Type_spec;
120 #else
121  extern PyTypeObject MessageMapContainer_Type;
122  extern PyTypeObject ScalarMapContainer_Type;
123 #endif
124 
125 extern PyTypeObject MapIterator_Type; // Both map types use the same iterator.
126 
127 // Builds a MapContainer object, from a parent message and a
128 // field descriptor.
129 extern PyObject* NewScalarMapContainer(
131 
132 // Builds a MessageMap object, from a parent message and a
133 // field descriptor.
134 extern PyObject* NewMessageMapContainer(
136  CMessageClass* message_class);
137 
138 } // namespace python
139 } // namespace protobuf
140 
141 } // namespace google
142 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_MAP_CONTAINER_H__
Definition: message.h:179
PyObject * NewScalarMapContainer(CMessage *parent, const google::protobuf::FieldDescriptor *parent_field_descriptor)
Definition: map_container.cc:397
CMessage * parent
Definition: map_container.h:82
const FieldDescriptor * key_field_descriptor
Definition: map_container.h:89
void SetOwner(const shared_ptr< Message > &new_owner)
Definition: map_container.h:102
uint64 version
Definition: map_container.h:94
Message
Definition: peerconnection_unittest.cc:105
const Message * message
Definition: map_container.h:73
PyTypeObject MessageMapContainer_Type
Definition: map_container.cc:819
Message * GetMutableMessage()
Definition: map_container.cc:109
int Release()
Definition: map_container.cc:390
Definition: descriptor.h:439
PyObject * NewMessageMapContainer(CMessage *parent, const google::protobuf::FieldDescriptor *parent_field_descriptor, CMessageClass *message_class)
Definition: map_container.cc:639
Definition: map_container.h:107
PyTypeObject ScalarMapContainer_Type
Definition: map_container.cc:565
struct google::protobuf::python::CMessage CMessage
Definition: map_container.h:62
Definition: __init__.py:1
PyTypeObject MapIterator_Type
Definition: map_container.cc:929
uint64_t uint64
Definition: port.h:136
Definition: message.h:67
shared_ptr< Message > owner
Definition: map_container.h:69
PyObject * message_dict
Definition: map_container.h:112
const FieldDescriptor * value_field_descriptor
Definition: map_container.h:90
Definition: shared_ptr.h:76
Definition: gflags_completions.h:115
PyObject_HEAD
Definition: map_container.h:63
CMessageClass * message_class
Definition: map_container.h:109
const FieldDescriptor * parent_field_descriptor
Definition: map_container.h:88