diff --git a/src/uvw/tty.hpp b/src/uvw/tty.hpp index 2a7ecc24..66d4ed3f 100644 --- a/src/uvw/tty.hpp +++ b/src/uvw/tty.hpp @@ -13,34 +13,16 @@ namespace uvw { -namespace details { - - -template -struct FileDescriptor; - -template<> struct FileDescriptor<0> { }; -template<> struct FileDescriptor<1> { }; -template<> struct FileDescriptor<2> { }; - -} - - class TTY final: public Stream { - template explicit TTY(std::shared_ptr ref, - details::FileDescriptor, + FileDescriptor desc, bool readable) : Stream{HandleType{}, std::move(ref)}, - fd{FD}, + fd{static_cast(desc)}, rw{readable ? 1 : 0} { } public: - static constexpr auto STDIN = details::FileDescriptor<0>{}; - static constexpr auto STDOUT = details::FileDescriptor<1>{}; - static constexpr auto STDERR = details::FileDescriptor<2>{}; - enum class Mode: unsigned short int { NORMAL, RAW, IO }; template @@ -89,7 +71,7 @@ public: } private: - uv_file fd; + FileDescriptor::Type fd; int rw; }; diff --git a/src/uvw/util.hpp b/src/uvw/util.hpp index 7dee92d1..a3b6b843 100644 --- a/src/uvw/util.hpp +++ b/src/uvw/util.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include #include @@ -67,6 +68,23 @@ private: }; +struct FileDescriptor { + using Type = uv_file; + + constexpr FileDescriptor(Type desc): fd{desc} { } + + constexpr operator Type() const noexcept { return fd; } + +private: + const Type fd; +}; + + +static constexpr auto STDIN = FileDescriptor{0}; +static constexpr auto STDOUT = FileDescriptor{1}; +static constexpr auto STDERR = FileDescriptor{2}; + + /** * See Boost/Mutant idiom: * https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Boost_mutant