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

Side by Side Diff: third_party/protobuf/python/google/protobuf/pyext/extension_dict.h

Issue 1291903002: Pull new version of protobuf sources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months 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 unified diff | Download patch
OLDNEW
(Empty)
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
41 #include <google/protobuf/stubs/shared_ptr.h>
42 #endif
43
44 namespace google {
45 namespace protobuf {
46
47 class Message;
48 class FieldDescriptor;
49
50 using internal::shared_ptr;
51
52 namespace python {
53
54 struct CMessage;
55
56 typedef struct ExtensionDict {
57 PyObject_HEAD;
58
59 // This is the top-level C++ Message object that owns the whole
60 // proto tree. Every Python container class holds a
61 // reference to it in order to keep it alive as long as there's a
62 // Python object that references any part of the tree.
63 shared_ptr<Message> owner;
64
65 // Weak reference to parent message. Used to make sure
66 // the parent is writable when an extension field is modified.
67 CMessage* parent;
68
69 // Pointer to the C++ Message that this ExtensionDict extends.
70 // Not owned by us.
71 Message* message;
72
73 // A dict of child messages, indexed by Extension descriptors.
74 // Similar to CMessage::composite_fields.
75 PyObject* values;
76 } ExtensionDict;
77
78 extern PyTypeObject ExtensionDict_Type;
79
80 namespace extension_dict {
81
82 // Builds an Extensions dict for a specific message.
83 ExtensionDict* NewExtensionDict(CMessage *parent);
84
85 // Gets the number of extension values in this ExtensionDict as a python object.
86 //
87 // Returns a new reference.
88 PyObject* len(ExtensionDict* self);
89
90 // Releases extensions referenced outside this dictionary to keep outside
91 // references alive.
92 //
93 // Returns 0 on success, -1 on failure.
94 int ReleaseExtension(ExtensionDict* self,
95 PyObject* extension,
96 const FieldDescriptor* descriptor);
97
98 // Gets an extension from the dict for the given extension descriptor.
99 //
100 // Returns a new reference.
101 PyObject* subscript(ExtensionDict* self, PyObject* key);
102
103 // Assigns a value to an extension in the dict. Can only be used for singular
104 // simple types.
105 //
106 // Returns 0 on success, -1 on failure.
107 int ass_subscript(ExtensionDict* self, PyObject* key, PyObject* value);
108
109 // Clears an extension from the dict. Will release the extension if there
110 // is still an external reference left to it.
111 //
112 // Returns None on success.
113 PyObject* ClearExtension(ExtensionDict* self,
114 PyObject* extension);
115
116 // Checks if the dict has an extension.
117 //
118 // Returns a new python boolean reference.
119 PyObject* HasExtension(ExtensionDict* self, PyObject* extension);
120
121 // Gets an extension from the dict given the extension name as opposed to
122 // descriptor.
123 //
124 // Returns a new reference.
125 PyObject* _FindExtensionByName(ExtensionDict* self, PyObject* name);
126
127 } // namespace extension_dict
128 } // namespace python
129 } // namespace protobuf
130
131 } // namespace google
132 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_EXTENSION_DICT_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698