#pragma once #include #include #include "Utility.Expected.tlh" #include "String.WString.hpp" #include "String.DString.hpp" #include "TmplBlockBuffer.tlh" #include "TmplBlockBuffer.tli" //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- namespace ECOM::Utility { //----------------------------------------------------------------------------- // eiDWString //----------------------------------------------------------------------------- class eiDWString : public ECOM::Utility::Either // 要么是 DString, 要么是 WString { using base = ECOM::Utility::Either ; public: eiDWString () : base { eSTR::DString () } { } // 默认是 DString eiDWString (eiDWString const & from) : base { from } {} eiDWString (eiDWString && from) : base { std::move (from) } {} eiDWString (const eSTR::DString & from) : base { from } { } eiDWString (const eSTR::WString & from) : base { from } { } eiDWString (eSTR::DString && from) : base { from } { } eiDWString (eSTR::WString && from) : base { from } { } ~eiDWString () = default; public: template T As () const { static_assert (dependent_false ); } template <> eSTR::DString As () const // 必须返回 DString { if (this->is <0> ()) return this->get <0> (); if (this->is <1> ()) return this->get <1> ().ToDString (); return eSTR::DString (); } template <> eSTR::WString As () const // 必须返回 WString { if (this->is <0> ()) return eSTR::WString (this->get <0> ()); if (this->is <1> ()) return this->get <1> (); return eSTR::WString (); } void To (eSTR::DString & _val) { _val = As (); } void To (eSTR::WString & _val) { _val = As (); } operator eSTR::DString () { return As (); } operator eSTR::WString () { return As (); } constexpr eiDWString & operator = (const eiDWString & from) { base::operator = (from); return (*this); } constexpr eiDWString & operator = (eiDWString && from) { base::operator = (std::move (from)); return (*this); } constexpr eiDWString & operator = (base && from) { base::operator = (std::move (from)); return (*this); } constexpr eiDWString & operator = (const eSTR::DString & _left) { base::operator = (_left); return (*this); } constexpr eiDWString & operator = (eSTR::DString && _left) { base::operator = (std::move (_left)); return (*this); } constexpr eiDWString & operator = (const eSTR::WString & _right) { base::operator = (_right); return (*this); } constexpr eiDWString & operator = (eSTR::WString && _right) { base::operator = (std::move (_right)); return (*this); } }; //----------------------------------------------------------------------------- // iAck //----------------------------------------------------------------------------- class iAck { public: iAck () = default; iAck (iAck const & from) : IDofCodec {from.IDofCodec }, AckMessage { from.AckMessage } {} iAck (iAck && from) : IDofCodec{ from.IDofCodec }, AckMessage { std::move (from.AckMessage) } {} virtual ~iAck () = default; public: DWORD IDofCodec = 0; eiDWString AckMessage; public: template T AckAs () const { return AckMessage.As (); } void To (eSTR::DString & _val) { _val = AckAs (); } void To (eSTR::WString & _val) { _val = AckAs (); } operator eSTR::DString () { return AckAs (); } operator eSTR::WString () { return AckAs (); } constexpr iAck & operator = (const iAck & from) { IDofCodec = from.IDofCodec; AckMessage = from.AckMessage; return (*this); } constexpr iAck & operator = (iAck && from) { IDofCodec = from.IDofCodec; AckMessage = std::move (from.AckMessage); return (*this); } }; class iBLOBAck : public iAck { using base = iAck; public: using base::base; OBlockBuffer AckBLOB; }; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //using eiResult = ECOM::Utility::Either ; //using eiAck = ECOM::Utility::Either ; //using eiBLOBAck = ECOM::Utility::Either ; using eiAck = ECOM::Utility::Expected ; using eiBLOBAck = ECOM::Utility::Expected ; #if 0 //< 不能放在这里, 由各个 Domain 自行定义, 因为每个 Domain 都需要添加自己的 Error::Domain inline auto eiUnknownError () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::enUnknown); } inline auto eiBadArgument () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::invalid_argument); } inline auto eiTimeOut () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::timed_out); } inline auto eiNoFile () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::no_such_file_or_directory); } inline auto eiNoDevice () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::no_such_device); } inline auto eiBusy () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::device_or_resource_busy); } inline auto eiException () { return ECOM::Utility::Error::Generic::Make (ECOM::Utility::Error::Generic::enError::exception); } //> #endif //>