25 #include "type_helper.h"
29 template <google::protobuf::FieldDescriptor::Type t>
30 void insertType(dccl::internal::TypeHelper::TypeMap* type_map)
32 type_map->insert(std::make_pair(t, std::shared_ptr<dccl::internal::FromProtoTypeBase>(
36 template <google::protobuf::FieldDescriptor::CppType t>
37 void insert(dccl::internal::TypeHelper::CppTypeMap* cpptype_map)
39 cpptype_map->insert(std::make_pair(t, std::shared_ptr<dccl::internal::FromProtoCppTypeBase>(
46 void dccl::internal::TypeHelper::initialize()
48 using namespace google::protobuf;
50 using std::shared_ptr;
53 make_pair(
static_cast<FieldDescriptor::Type
>(0), std::make_shared<FromProtoTypeBase>()));
54 insertType<FieldDescriptor::TYPE_DOUBLE>(&type_map_);
55 insertType<FieldDescriptor::TYPE_FLOAT>(&type_map_);
56 insertType<FieldDescriptor::TYPE_UINT64>(&type_map_);
57 insertType<FieldDescriptor::TYPE_UINT32>(&type_map_);
58 insertType<FieldDescriptor::TYPE_FIXED64>(&type_map_);
59 insertType<FieldDescriptor::TYPE_FIXED32>(&type_map_);
60 insertType<FieldDescriptor::TYPE_INT64>(&type_map_);
61 insertType<FieldDescriptor::TYPE_INT32>(&type_map_);
62 insertType<FieldDescriptor::TYPE_SFIXED32>(&type_map_);
63 insertType<FieldDescriptor::TYPE_SFIXED64>(&type_map_);
64 insertType<FieldDescriptor::TYPE_SINT32>(&type_map_);
65 insertType<FieldDescriptor::TYPE_SINT64>(&type_map_);
66 insertType<FieldDescriptor::TYPE_BOOL>(&type_map_);
67 insertType<FieldDescriptor::TYPE_STRING>(&type_map_);
68 insertType<FieldDescriptor::TYPE_BYTES>(&type_map_);
69 insertType<FieldDescriptor::TYPE_MESSAGE>(&type_map_);
70 insertType<FieldDescriptor::TYPE_GROUP>(&type_map_);
71 insertType<FieldDescriptor::TYPE_ENUM>(&type_map_);
73 cpptype_map_.insert(make_pair(
static_cast<FieldDescriptor::CppType
>(0),
74 std::make_shared<FromProtoCppTypeBase>()));
76 insert<FieldDescriptor::CPPTYPE_DOUBLE>(&cpptype_map_);
77 insert<FieldDescriptor::CPPTYPE_FLOAT>(&cpptype_map_);
78 insert<FieldDescriptor::CPPTYPE_UINT64>(&cpptype_map_);
79 insert<FieldDescriptor::CPPTYPE_UINT32>(&cpptype_map_);
80 insert<FieldDescriptor::CPPTYPE_INT64>(&cpptype_map_);
81 insert<FieldDescriptor::CPPTYPE_INT32>(&cpptype_map_);
82 insert<FieldDescriptor::CPPTYPE_BOOL>(&cpptype_map_);
83 insert<FieldDescriptor::CPPTYPE_STRING>(&cpptype_map_);
84 insert<FieldDescriptor::CPPTYPE_MESSAGE>(&cpptype_map_);
85 insert<FieldDescriptor::CPPTYPE_ENUM>(&cpptype_map_);
88 std::shared_ptr<dccl::internal::FromProtoCppTypeBase>
89 dccl::internal::TypeHelper::find(google::protobuf::FieldDescriptor::CppType cpptype,
90 const std::string& type_name )
const
92 if (!type_name.empty())
94 auto it = custom_message_map_.find(type_name);
95 if (it != custom_message_map_.end())
99 auto it = cpptype_map_.find(cpptype);
100 if (it != cpptype_map_.end())
103 return std::shared_ptr<FromProtoCppTypeBase>();
106 std::shared_ptr<dccl::internal::FromProtoTypeBase>
107 dccl::internal::TypeHelper::find(google::protobuf::FieldDescriptor::Type type)
const
109 auto it = type_map_.find(type);
110 if (it != type_map_.end())
113 return std::shared_ptr<FromProtoTypeBase>();