|
|
@ -21,9 +21,11 @@ |
|
|
|
#include <cstdint> |
|
|
|
#include <cstdint> |
|
|
|
#include <cstring> |
|
|
|
#include <cstring> |
|
|
|
#include <iosfwd> |
|
|
|
#include <iosfwd> |
|
|
|
|
|
|
|
#include <memory> |
|
|
|
#include <new> |
|
|
|
#include <new> |
|
|
|
#include <string> |
|
|
|
#include <string> |
|
|
|
#include <type_traits> |
|
|
|
#include <type_traits> |
|
|
|
|
|
|
|
#include <utility> |
|
|
|
|
|
|
|
|
|
|
|
#include "absl/base/attributes.h" |
|
|
|
#include "absl/base/attributes.h" |
|
|
|
#include "absl/base/casts.h" |
|
|
|
#include "absl/base/casts.h" |
|
|
@ -1438,6 +1440,28 @@ T& DownCastToGenerated(MessageLite& from) { |
|
|
|
return DownCastMessage<T>(from); |
|
|
|
return DownCastMessage<T>(from); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Overloads for `std::shared_ptr` to substitute `std::dynamic_pointer_cast`
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
std::shared_ptr<T> DynamicCastMessage(std::shared_ptr<MessageLite> ptr) { |
|
|
|
|
|
|
|
if (auto* res = DynamicCastMessage<T>(ptr.get())) { |
|
|
|
|
|
|
|
// Use aliasing constructor to keep the same control block.
|
|
|
|
|
|
|
|
return std::shared_ptr<T>(std::move(ptr), res); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T> |
|
|
|
|
|
|
|
std::shared_ptr<const T> DynamicCastMessage( |
|
|
|
|
|
|
|
std::shared_ptr<const MessageLite> ptr) { |
|
|
|
|
|
|
|
if (auto* res = DynamicCastMessage<T>(ptr.get())) { |
|
|
|
|
|
|
|
// Use aliasing constructor to keep the same control block.
|
|
|
|
|
|
|
|
return std::shared_ptr<const T>(std::move(ptr), res); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace protobuf
|
|
|
|
} // namespace protobuf
|
|
|
|
} // namespace google
|
|
|
|
} // namespace google
|
|
|
|
|
|
|
|
|
|
|
|