| 1 | #pragma once | ||
| 2 | #include <xs/Sv.h> | ||
| 3 | |||
| 4 | // remove OpenBSD pollution macro | ||
| 5 | #undef fileno | ||
| 6 | |||
| 7 | namespace xs { | ||
| 8 | |||
| 9 | using xs::my_perl; | ||
| 10 | |||
| 11 | struct Io : Sv { | ||
| 12 | static Io noinc (SV* val) { return Io(val, NONE); } | ||
| 13 | static Io noinc (IO* val) { return Io(val, NONE); } | ||
| 14 | |||
| 15 | Io (std::nullptr_t = nullptr) {} | ||
| 16 | Io (SV* sv, bool policy = INCREMENT) : Sv(sv, policy) { _validate(); } | ||
| 17 | Io (GV* sv, bool policy = INCREMENT) : Sv(sv, policy) { _validate(); } | ||
| 18 | 0 | Io (IO* sv, bool policy = INCREMENT) : Sv(sv, policy) {} | |
| 19 | |||
| 20 | Io (const Io& oth) : Sv(oth) {} | ||
| 21 | Io (Io&& oth) : Sv(std::move(oth)) {} | ||
| 22 | Io (const Sv& oth) : Sv(oth) { _validate(); } | ||
| 23 | Io (Sv&& oth) : Sv(std::move(oth)) { _validate(); } | ||
| 24 | |||
| 25 | Io (const Simple&) = delete; | ||
| 26 | Io (const Array&) = delete; | ||
| 27 | Io (const Hash&) = delete; | ||
| 28 | Io (const Sub&) = delete; | ||
| 29 | |||
| 30 | Io& operator= (SV* val) { Sv::operator=(val); _validate(); return *this; } | ||
| 31 | Io& operator= (GV* val) { Sv::operator=(val); _validate(); return *this; } | ||
| 32 | Io& operator= (IO* val) { Sv::operator=(val); return *this; } | ||
| 33 | Io& operator= (const Io& oth) { Sv::operator=(oth); return *this; } | ||
| 34 | Io& operator= (Io&& oth) { Sv::operator=(std::move(oth)); return *this; } | ||
| 35 | Io& operator= (const Sv& oth) { return operator=(oth.get()); } | ||
| 36 | Io& operator= (Sv&& oth) { Sv::operator=(std::move(oth)); _validate(); return *this; } | ||
| 37 | Io& operator= (const Simple&) = delete; | ||
| 38 | Io& operator= (const Array&) = delete; | ||
| 39 | Io& operator= (const Hash&) = delete; | ||
| 40 | Io& operator= (const Sub&) = delete; | ||
| 41 | |||
| 42 | void set (SV* val) { Sv::operator=(val); } | ||
| 43 | |||
| 44 | operator AV* () const = delete; | ||
| 45 | operator HV* () const = delete; | ||
| 46 | operator CV* () const = delete; | ||
| 47 | operator GV* () const = delete; | ||
| 48 | operator IO* () const { return (IO*)sv; } | ||
| 49 | |||
| 50 | IO* operator-> () const { return (IO*)sv; } | ||
| 51 | |||
| 52 | 0 | template <typename T = SV> panda::enable_if_one_of_t<T,SV,IO>* get () const { return (T*)sv; } | |
| 53 | |||
| 54 | int fileno () const { return PerlIO_fileno(ifp()); } | ||
| 55 | |||
| 56 | PerlIO* ifp () const { return IoIFP(sv); } | ||
| 57 | PerlIO* ofp () const { return IoOFP(sv); } | ||
| 58 | |||
| 59 | char iotype () const { return IoTYPE(sv); } | ||
| 60 | |||
| 61 | private: | ||
| 62 | void _validate (); | ||
| 63 | }; | ||
| 64 | |||
| 65 | } |