#ifndef MEDIAPIPE_FRAMEWORK_API2_PORT_H_
#define MEDIAPIPE_FRAMEWORK_API2_PORT_H_
#include <type_traits>
#include <utility>
#include "absl/log/absl_check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "mediapipe/framework/api2/const_str.h"
#include "mediapipe/framework/api2/packet.h"
#include "mediapipe/framework/calculator_context.h"
#include "mediapipe/framework/calculator_contract.h"
#include "mediapipe/framework/output_side_packet.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/tool/type_util.h"
namespace mediapipe {
namespace api2 {
class PortBase { … };
class InputBase : public PortBase { … };
class OutputBase : public PortBase { … };
class SideInputBase : public PortBase { … };
class SideOutputBase : public PortBase { … };
struct NoneType { … };
template <auto& kP>
struct SameType { … };
class PacketTypeAccess;
class PacketTypeAccessFallback;
template <typename T>
class InputShardAccess;
template <typename T>
class OutputShardAccess;
template <typename T>
class InputSidePacketAccess;
template <typename T>
class OutputSidePacketAccess;
template <typename T>
class InputShardOrSideAccess;
namespace internal {
template <typename...>
class Contract;
template <class CC>
auto GetCollection(CC* cc, const InputBase& port) -> decltype(cc->Inputs()) { … }
template <class CC>
auto GetCollection(CC* cc, const SideInputBase& port)
-> decltype(cc->InputSidePackets()) { … }
template <class CC>
auto GetCollection(CC* cc, const OutputBase& port) -> decltype(cc->Outputs()) { … }
template <class CC>
auto GetCollection(CC* cc, const SideOutputBase& port)
-> decltype(cc->OutputSidePackets()) { … }
template <class Collection>
auto GetOrNull(Collection& collection, const absl::string_view& tag, int index)
-> decltype(&collection.Get(std::declval<CollectionItemId>())) { … }
template <class T>
struct IsOneOf : std::false_type { … };
IsOneOf<OneOf<T...>>;
template <class T>
struct IsSameType : std::false_type { … };
template <class P, P& kP>
struct IsSameType<SameType<kP>> : std::true_type {};
template <typename T,
typename std::enable_if<!std::is_same<T, AnyType>{ … }
template <typename T, typename std::enable_if<IsSameType<T>{ … }
template <typename T,
typename std::enable_if<std::is_same<T, AnyType>{ … }
template <>
inline void SetType<NoneType>(CalculatorContract* cc, PacketType& pt) { … }
template <typename... T>
inline void SetTypeOneOf(OneOf<T...>, CalculatorContract* cc, PacketType& pt) { … }
template <typename T, typename std::enable_if<IsOneOf<T>{ … }
template <typename ValueT>
InputShardAccess<ValueT> SinglePortAccess(mediapipe::CalculatorContext* cc,
InputStreamShard* stream) { … }
template <typename ValueT>
OutputShardAccess<ValueT> SinglePortAccess(mediapipe::CalculatorContext* cc,
OutputStreamShard* stream) { … }
template <typename ValueT>
InputSidePacketAccess<ValueT> SinglePortAccess(
mediapipe::CalculatorContext* cc, const mediapipe::Packet* packet) { … }
template <typename ValueT>
OutputSidePacketAccess<ValueT> SinglePortAccess(
mediapipe::CalculatorContext* cc, OutputSidePacket* osp) { … }
template <typename ValueT>
InputShardOrSideAccess<ValueT> SinglePortAccess(
mediapipe::CalculatorContext* cc, InputStreamShard* stream,
const mediapipe::Packet* packet) { … }
template <typename ValueT>
PacketTypeAccess SinglePortAccess(mediapipe::CalculatorContract* cc,
PacketType* pt);
template <typename ValueT>
PacketTypeAccessFallback SinglePortAccess(mediapipe::CalculatorContract* cc,
PacketType* pt, bool is_stream);
template <typename ValueT, typename PortT, class CC>
auto AccessPort(std::false_type, const PortT& port, CC* cc) { … }
template <typename ValueT, typename X, class CC>
class MultiplePortAccess { … };
template <typename ValueT, typename PortT, class CC>
auto AccessPort(std::true_type, const PortT& port, CC* cc) { … }
template <class Base>
struct SideBase;
template <>
struct SideBase<InputBase> { … };
template <typename T, typename = void>
struct ActualPayloadType { … };
template <typename T>
struct ActualPayloadType<T, std::enable_if_t<IsSameType<T>{}, void>> {
using type = typename ActualPayloadType<
typename std::decay_t<decltype(T::kPort)>::value_t>::type;
};
}
template <typename T>
using ActualPayloadT = typename internal::ActualPayloadType<T>::type;
static_assert(std::is_same_v<ActualPayloadT<int>, int>, "");
static_assert(std::is_same_v<ActualPayloadT<AnyType>, internal::Generic>, "");
template <typename Base, typename ValueT, bool IsOptional = false,
bool IsMultiple = false>
class SideFallbackT;
template <typename Base, typename ValueT, bool IsOptionalV = false,
bool IsMultipleV = false>
class PortCommon : public Base { … };
template <typename T = internal::Generic>
using Input = PortCommon<InputBase, T>;
template <typename T = internal::Generic>
using Output = PortCommon<OutputBase, T>;
template <typename T = internal::Generic>
using SideInput = PortCommon<SideInputBase, T>;
template <typename T = internal::Generic>
using SideOutput = PortCommon<SideOutputBase, T>;
template <typename Base, typename ValueT, bool IsOptionalV, bool IsMultipleV>
class SideFallbackT : public Base { … };
class OutputShardAccessBase { … };
template <typename T>
class OutputShardAccess : public OutputShardAccessBase { … };
template <>
class OutputShardAccess<internal::Generic> : public OutputShardAccessBase { … };
template <typename T>
class OutputSidePacketAccess { … };
template <typename T>
class InputShardAccess : public Packet<T> { … };
template <typename T>
class InputSidePacketAccess : public Packet<T> { … };
template <typename T>
class InputShardOrSideAccess : public Packet<T> { … };
class PacketTypeAccess { … };
class PacketTypeAccessFallback : public PacketTypeAccess { … };
namespace internal {
template <typename ValueT>
PacketTypeAccess SinglePortAccess(mediapipe::CalculatorContract* cc,
PacketType* pt) { … }
template <typename ValueT>
PacketTypeAccessFallback SinglePortAccess(mediapipe::CalculatorContract* cc,
PacketType* pt, bool is_stream) { … }
}
}
}
#endif