/thirdparty/breakpad/third_party/protobuf/protobuf/src/google/protobuf/dynamic_message.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 136 lines · 30 code · 17 blank · 89 comment · 0 complexity · 5676a8f6fd4d3cffbe7f2f38aa21bc0f MD5 · raw file

  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc. All rights reserved.
  3. // http://code.google.com/p/protobuf/
  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. // Author: kenton@google.com (Kenton Varda)
  31. // Based on original Protocol Buffers design by
  32. // Sanjay Ghemawat, Jeff Dean, and others.
  33. //
  34. // Defines an implementation of Message which can emulate types which are not
  35. // known at compile-time.
  36. #ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
  37. #define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__
  38. #include <google/protobuf/message.h>
  39. #include <google/protobuf/stubs/common.h>
  40. namespace google {
  41. namespace protobuf {
  42. // Defined in other files.
  43. class Descriptor; // descriptor.h
  44. class DescriptorPool; // descriptor.h
  45. // Constructs implementations of Message which can emulate types which are not
  46. // known at compile-time.
  47. //
  48. // Sometimes you want to be able to manipulate protocol types that you don't
  49. // know about at compile time. It would be nice to be able to construct
  50. // a Message object which implements the message type given by any arbitrary
  51. // Descriptor. DynamicMessage provides this.
  52. //
  53. // As it turns out, a DynamicMessage needs to construct extra
  54. // information about its type in order to operate. Most of this information
  55. // can be shared between all DynamicMessages of the same type. But, caching
  56. // this information in some sort of global map would be a bad idea, since
  57. // the cached information for a particular descriptor could outlive the
  58. // descriptor itself. To avoid this problem, DynamicMessageFactory
  59. // encapsulates this "cache". All DynamicMessages of the same type created
  60. // from the same factory will share the same support data. Any Descriptors
  61. // used with a particular factory must outlive the factory.
  62. class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory {
  63. public:
  64. // Construct a DynamicMessageFactory that will search for extensions in
  65. // the DescriptorPool in which the exendee is defined.
  66. DynamicMessageFactory();
  67. // Construct a DynamicMessageFactory that will search for extensions in
  68. // the given DescriptorPool.
  69. //
  70. // DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the
  71. // parser to look for extensions in an alternate pool. However, note that
  72. // this is almost never what you want to do. Almost all users should use
  73. // the zero-arg constructor.
  74. DynamicMessageFactory(const DescriptorPool* pool);
  75. ~DynamicMessageFactory();
  76. // Call this to tell the DynamicMessageFactory that if it is given a
  77. // Descriptor d for which:
  78. // d->file()->pool() == DescriptorPool::generated_pool(),
  79. // then it should delegate to MessageFactory::generated_factory() instead
  80. // of constructing a dynamic implementation of the message. In theory there
  81. // is no down side to doing this, so it may become the default in the future.
  82. void SetDelegateToGeneratedFactory(bool enable) {
  83. delegate_to_generated_factory_ = enable;
  84. }
  85. // implements MessageFactory ---------------------------------------
  86. // Given a Descriptor, constructs the default (prototype) Message of that
  87. // type. You can then call that message's New() method to construct a
  88. // mutable message of that type.
  89. //
  90. // Calling this method twice with the same Descriptor returns the same
  91. // object. The returned object remains property of the factory and will
  92. // be destroyed when the factory is destroyed. Also, any objects created
  93. // by calling the prototype's New() method share some data with the
  94. // prototype, so these must be destoyed before the DynamicMessageFactory
  95. // is destroyed.
  96. //
  97. // The given descriptor must outlive the returned message, and hence must
  98. // outlive the DynamicMessageFactory.
  99. //
  100. // The method is thread-safe.
  101. const Message* GetPrototype(const Descriptor* type);
  102. private:
  103. const DescriptorPool* pool_;
  104. bool delegate_to_generated_factory_;
  105. // This struct just contains a hash_map. We can't #include <google/protobuf/stubs/hash.h> from
  106. // this header due to hacks needed for hash_map portability in the open source
  107. // release. Namely, stubs/hash.h, which defines hash_map portably, is not a
  108. // public header (for good reason), but dynamic_message.h is, and public
  109. // headers may only #include other public headers.
  110. struct PrototypeMap;
  111. scoped_ptr<PrototypeMap> prototypes_;
  112. mutable Mutex prototypes_mutex_;
  113. friend class DynamicMessage;
  114. const Message* GetPrototypeNoLock(const Descriptor* type);
  115. GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory);
  116. };
  117. } // namespace protobuf
  118. } // namespace google
  119. #endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__