message_factory.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_MESSAGE_FACTORY_H__
32 #define GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
33 
34 #include <Python.h>
35 
36 #include <unordered_map>
39 
40 namespace google {
41 namespace protobuf {
42 class MessageFactory;
43 
44 namespace python {
45 
46 // The (meta) type of all Messages classes.
47 struct CMessageClass;
48 
50  PyObject_HEAD
51 
52  // DynamicMessageFactory used to create C++ instances of messages.
53  // This object cache the descriptors that were used, so the DescriptorPool
54  // needs to get rid of it before it can delete itself.
55  //
56  // Note: A C++ MessageFactory is different from the PyMessageFactory.
57  // The C++ one creates messages, when the Python one creates classes.
59 
60  // Owned reference to a Python DescriptorPool.
61  // This reference must stay until the message_factory is destructed.
63 
64  // Make our own mapping to retrieve Python classes from C++ descriptors.
65  //
66  // Descriptor pointers stored here are owned by the DescriptorPool above.
67  // Python references to classes are owned by this PyDescriptorPool.
68  typedef std::unordered_map<const Descriptor*, CMessageClass*>
71 };
72 
73 extern PyTypeObject PyMessageFactory_Type;
74 
75 namespace message_factory {
76 
77 // Creates a new MessageFactory instance.
79 
80 // Registers a new Python class for the given message descriptor.
81 // On error, returns -1 with a Python exception set.
83  const Descriptor* message_descriptor,
85 // Retrieves the Python class registered with the given message descriptor, or
86 // fail with a TypeError. Returns a *borrowed* reference.
88  const Descriptor* message_descriptor);
89 // Retrieves the Python class registered with the given message descriptor.
90 // The class is created if not done yet. Returns a *new* reference.
92  const Descriptor* message_descriptor);
93 } // namespace message_factory
94 
95 // Initialize objects used by this module.
96 // On error, returns false with a Python exception set.
97 bool InitMessageFactory();
98 
99 } // namespace python
100 } // namespace protobuf
101 } // namespace google
102 
103 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_MESSAGE_FACTORY_H__
google::protobuf::python::PyMessageFactory::pool
PyDescriptorPool * pool
Definition: message_factory.h:62
google::protobuf::python::PyMessageFactory
Definition: message_factory.h:49
google::protobuf::python::PyMessageFactory::message_factory
PyObject_HEAD MessageFactory * message_factory
Definition: message_factory.h:58
google::protobuf::python::PyMessageFactory::ClassesByMessageMap
std::unordered_map< const Descriptor *, CMessageClass * > ClassesByMessageMap
Definition: message_factory.h:69
google::protobuf::python::PyDescriptorPool
Definition: descriptor_pool.h:56
google::protobuf::python::CMessageClass
Definition: python/google/protobuf/pyext/message.h:148
google::protobuf::MessageFactory
Definition: src/google/protobuf/message.h:1069
google::protobuf::python::InitMessageFactory
bool InitMessageFactory()
Definition: message_factory.cc:293
message_class
def message_class(spec)
google::protobuf::python::PyMessageFactory::classes_by_descriptor
ClassesByMessageMap * classes_by_descriptor
Definition: message_factory.h:70
google::protobuf::python::message_factory::GetOrCreateMessageClass
CMessageClass * GetOrCreateMessageClass(PyMessageFactory *self, const Descriptor *descriptor)
Definition: message_factory.cc:155
google::protobuf::python::message_factory::RegisterMessageClass
int RegisterMessageClass(PyMessageFactory *self, const Descriptor *message_descriptor, CMessageClass *message_class)
Definition: message_factory.cc:140
google::protobuf::python::PyMessageFactory_Type
PyTypeObject PyMessageFactory_Type
Definition: message_factory.cc:251
descriptor_pool.h
pool
InternalDescriptorPool * pool
Definition: php/ext/google/protobuf/protobuf.h:798
type
GLenum type
Definition: glcorearb.h:2695
google::protobuf::python::message_factory::NewMessageFactory
PyMessageFactory * NewMessageFactory(PyTypeObject *type, PyDescriptorPool *pool)
Definition: message_factory.cc:59
google::protobuf::Descriptor
Definition: src/google/protobuf/descriptor.h:231
descriptor.h
google::protobuf::python::message_factory::GetMessageClass
CMessageClass * GetMessageClass(PyMessageFactory *self, const Descriptor *message_descriptor)
Definition: message_factory.cc:223
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:56