chromium/third_party/mediapipe/src/mediapipe/framework/type_map.h

// Copyright 2019 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This header defines static maps to store the mappings from type hash id and
// name string to MediaPipeTypeData.  It also provides code to inspect types of
// packets and access registered serialize and deserialize functions.
// Calculators can use this to infer types of packets and adjust accordingly.
//
// Register a type:
//    // If the generic serializer can serialize your type use:
//    MEDIAPIPE_REGISTER_GENERIC_TYPE(::namespace::Type);
//
//    // If your type includes commas, you need to use a macro:
//    #define MY_PAIR_TYPE ::std::pair<int, float>
//    MEDIAPIPE_REGISTER_GENERIC_TYPE_WITH_NAME(MY_PAIR_TYPE,
//                                            "::std::pair<int,float>");
//    #undef MY_PAIR_TYPE
//
//    // If you need more control over the serialization functions you can
//    // specify them directly.
//    MEDIAPIPE_REGISTER_TYPE(
//        ::namespace::Type, "::namespace::Type",
//        ::mediapipe::SerializeUsingGenericFn<::namespace::Type>,
//        ::mediapipe::DeserializeUsingGenericFn<::namespace::Type>);
//
//    // If your type is serialized by converting it to an easily serializable
//    // type (such as a proto) use a proxy.
//    // See mediapipe/framework/formats/location.cc for more
//    details. MEDIAPIPE_REGISTER_TYPE_WITH_PROXY(
//        mediapipe::Location, "mediapipe::Location",
//        ::mediapipe::SerializeUsingGenericFn<Location WITH_MEDIAPIPE_PROXY
//        LocationData>,
//        ::mediapipe::DeserializeUsingGenericFn<Location WITH_MEDIAPIPE_PROXY
//        LocationData>, LocationToLocationData, LocationFromLocationData);
//
// Inspect type:
//     const std::string* result = MediaPipeTypeString<CustomStruct>();
//     if (result && *result == "CustomStruct") ...
//
// Compare type hash id's:
//     const size_t* complex_type_id = MediaPipeTypeId("ComplexStruct");
//     if (complex_type_id && *complex_type_id ==
//     tool::GetTypeHash<std::string>())
//       ...
//

#ifndef MEDIAPIPE_FRAMEWORK_TYPE_MAP_H_
#define MEDIAPIPE_FRAMEWORK_TYPE_MAP_H_

#include <functional>
#include <map>
#include <memory>
#include <vector>

#include "absl/base/macros.h"
#include "absl/log/absl_check.h"
#include "absl/log/absl_log.h"
#include "absl/synchronization/mutex.h"
#include "mediapipe/framework/demangle.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/tool/status_util.h"
#include "mediapipe/framework/tool/type_util.h"

mediapipe  // namespace mediapipe

#endif  // MEDIAPIPE_FRAMEWORK_TYPE_MAP_H_