webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
extension_dict.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 // Author: anuraag@google.com (Anuraag Agrawal)
32 // Author: tibell@google.com (Johan Tibell)
33 
34 #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
35 #define GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
36 
37 #include <Python.h>
38 
39 #include <memory>
40 #ifndef _SHARED_PTR_H
42 #endif
43 
44 namespace google {
45 namespace protobuf {
46 
47 class Message;
48 class FieldDescriptor;
49 
50 #ifdef _SHARED_PTR_H
51 using std::shared_ptr;
52 #else
53 using internal::shared_ptr;
54 #endif
55 
56 namespace python {
57 
58 struct CMessage;
59 
60 typedef struct ExtensionDict {
62 
63  // This is the top-level C++ Message object that owns the whole
64  // proto tree. Every Python container class holds a
65  // reference to it in order to keep it alive as long as there's a
66  // Python object that references any part of the tree.
68 
69  // Weak reference to parent message. Used to make sure
70  // the parent is writable when an extension field is modified.
72 
73  // Pointer to the C++ Message that this ExtensionDict extends.
74  // Not owned by us.
76 
77  // A dict of child messages, indexed by Extension descriptors.
78  // Similar to CMessage::composite_fields.
79  PyObject* values;
81 
82 extern PyTypeObject ExtensionDict_Type;
83 
84 namespace extension_dict {
85 
86 // Builds an Extensions dict for a specific message.
88 
89 // Gets the number of extension values in this ExtensionDict as a python object.
90 //
91 // Returns a new reference.
92 PyObject* len(ExtensionDict* self);
93 
94 // Releases extensions referenced outside this dictionary to keep outside
95 // references alive.
96 //
97 // Returns 0 on success, -1 on failure.
99  PyObject* extension,
100  const FieldDescriptor* descriptor);
101 
102 // Gets an extension from the dict for the given extension descriptor.
103 //
104 // Returns a new reference.
105 PyObject* subscript(ExtensionDict* self, PyObject* key);
106 
107 // Assigns a value to an extension in the dict. Can only be used for singular
108 // simple types.
109 //
110 // Returns 0 on success, -1 on failure.
111 int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value);
112 
113 // Clears an extension from the dict. Will release the extension if there
114 // is still an external reference left to it.
115 //
116 // Returns None on success.
117 PyObject* ClearExtension(ExtensionDict* self,
118  PyObject* extension);
119 
120 // Gets an extension from the dict given the extension name as opposed to
121 // descriptor.
122 //
123 // Returns a new reference.
124 PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* name);
125 
126 // Gets an extension from the dict given the extension field number as
127 // opposed to descriptor.
128 //
129 // Returns a new reference.
130 PyObject* _FindExtensionByNumber(ExtensionDict* self, PyObject* number);
131 
132 } // namespace extension_dict
133 } // namespace python
134 } // namespace protobuf
135 
136 } // namespace google
137 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
PyObject * _FindExtensionByName(ExtensionDict *self, PyObject *name)
Definition: extension_dict.cc:227
Definition: message.h:179
int ReleaseExtension(ExtensionDict *self, PyObject *extension, const FieldDescriptor *descriptor)
Definition: extension_dict.cc:64
Definition: extension_dict.h:60
PyTypeObject ExtensionDict_Type
Definition: extension_dict.cc:296
const Descriptor * descriptor
Definition: descriptor.cc:271
ExtensionDict * NewExtensionDict(CMessage *parent)
Definition: extension_dict.cc:257
shared_ptr< Message > owner
Definition: extension_dict.h:67
PyObject * values
Definition: extension_dict.h:79
Message
Definition: peerconnection_unittest.cc:105
PyObject * subscript(ExtensionDict *self, PyObject *key)
Definition: extension_dict.cc:92
Definition: descriptor.h:439
ClearExtension
Definition: python_message.py:899
Definition: protobuf.h:85
OPENSSL_EXPORT const ASN1_OBJECT int const unsigned char int len
Definition: x509.h:1053
struct google::protobuf::python::ExtensionDict ExtensionDict
struct google::protobuf::python::CMessage CMessage
EGLAttrib * value
Definition: eglext.h:120
PyObject * _FindExtensionByNumber(ExtensionDict *self, PyObject *number)
Definition: extension_dict.cc:242
EGLImageKHR EGLint * name
Definition: eglext.h:851
const AtomicString & number()
Definition: InputTypeNames.cpp:100
Definition: __init__.py:1
Definition: message.h:67
PyObject_HEAD
Definition: extension_dict.h:61
Definition: shared_ptr.h:76
CMessage * parent
Definition: extension_dict.h:71
int ass_subscript(ExtensionDict *self, PyObject *key, PyObject *value)
Definition: extension_dict.cc:160
Definition: gflags_completions.h:115
Message * message
Definition: extension_dict.h:75
extension
Definition: descriptor.h:1666
CFArrayRef CFTypeRef key
Definition: AVFoundationCFSoftLinking.h:129