Program Listing for File Sink.hpp

Return to documentation for file (include/uit/fixtures/Sink.hpp)

#pragma once
#ifndef UIT_FIXTURES_SINK_HPP_INCLUDE
#define UIT_FIXTURES_SINK_HPP_INCLUDE

#include <memory>
#include <stddef.h>
#include <utility>

#include "../ducts/Duct.hpp"
#include "../spouts/Inlet.hpp"

namespace uit {

template<typename ImplSpec>
class Sink {

  template<typename Inlet>
  using inlet_wrapper_t = typename ImplSpec::template inlet_wrapper_t<Inlet>;

public:

  using inlet_t = inlet_wrapper_t< uit::Inlet<ImplSpec> >;

private:

  inlet_t inlet;

public:

  Sink(Sink& other) = default;

  Sink(const Sink& other) = default;

  Sink(Sink&& other) = default;

  template <typename... Args>
  Sink(Args&&... args) : inlet(
    std::make_shared<internal::Duct<ImplSpec>>(
      std::forward<Args>(args)...
    )
  ) { ; }

  template <size_t N>
  decltype(auto) get() const { if constexpr (N == 0) return inlet; }

  inlet_t& GetInlet() { return inlet; }

};

} // namespace uit

namespace std {

  template<typename ImplSpec>
  struct tuple_size<uit::Sink<ImplSpec>>
    : std::integral_constant<size_t, 1>{};

  template<typename ImplSpec, size_t N>
  struct tuple_element<N, uit::Sink<ImplSpec>> {
    using type = decltype(
      std::declval<uit::Sink<ImplSpec>>().template get<N>()
    );
  };

} // namespace std

#endif // #ifndef UIT_FIXTURES_SINK_HPP_INCLUDE