#ifndef MEDIAPIPE_FRAMEWORK_API2_NODE_H_
#define MEDIAPIPE_FRAMEWORK_API2_NODE_H_
#include <memory>
#include <type_traits>
#include "absl/status/status.h"
#include "mediapipe/framework/api2/contract.h"
#include "mediapipe/framework/calculator_base.h"
#include "mediapipe/framework/calculator_context.h"
#include "mediapipe/framework/calculator_contract.h"
#include "mediapipe/framework/deps/registration.h"
#include "mediapipe/framework/subgraph.h"
namespace mediapipe {
namespace api2 {
class NodeIntf { … };
class Node : public CalculatorBase { … };
}
namespace internal {
template <class T>
class CalculatorBaseFactoryFor<
T,
typename std::enable_if<std::is_base_of<mediapipe::api2::Node, T>{}>::type>
: public CalculatorBaseFactory {
public:
absl::Status GetContract(CalculatorContract* cc) final {
auto status = T::Contract::GetContract(cc);
if (status.ok()) {
status = UpdateContract<T>(cc);
}
return status;
}
std::unique_ptr<CalculatorBase> CreateCalculator(
CalculatorContext* calculator_context) final {
return absl::make_unique<T>();
}
private:
template <typename U>
auto UpdateContract(CalculatorContract* cc)
-> decltype(U::UpdateContract(cc)) {
return U::UpdateContract(cc);
}
template <typename U>
absl::Status UpdateContract(...) {
return {};
}
};
}
namespace api2 {
namespace internal {
MEDIAPIPE_STATIC_REGISTRATOR_TEMPLATE(…)
MEDIAPIPE_STATIC_REGISTRATOR_TEMPLATE(…)
}
template <class Impl = void>
class RegisteredNode;
template <class Impl>
class RegisteredNode : public Node, private internal::NodeRegistrator<Impl> { … };
template <>
class RegisteredNode<void> : public Node { … };
template <class Impl>
struct FunctionNode : public RegisteredNode<Impl> { … };
template <class Intf, class Impl = void>
class NodeImpl : public RegisteredNode<Impl>, public Intf { … };
#define MEDIAPIPE_NODE_CONTRACT(...) …
#define MEDIAPIPE_NODE_INTERFACE(name, ...) …
template <class Intf, class Impl>
class SubgraphImpl : public Subgraph,
public Intf,
private internal::SubgraphRegistrator<Impl> { … };
#define MEDIAPIPE_NODE_IMPLEMENTATION(Impl) …
#define MEDIAPIPE_REGISTER_NODE(name) …
#define MEDIAPIPE_SUBGRAPH_IMPLEMENTATION(Impl) …
}
}
#endif