📄 wyr_reply.h
字号:
/* Copyright is licensed under GNU LGPL. by I.J.Wang 2006*/#ifndef WYR_REPLY_H__#define WYR_REPLY_H__#define WYR_REPLY_VERSION 31typedef int Wy__ErrNoType;namespace Wy {const Wy__ErrNoType _max_errno=127; // errno is taken in range [0-_max_errno]const Wy__ErrNoType _default_errno=-1;const char* const _default_repstr="General error";};class WyReply;// These are predefined reply objects//// Constants mapped to C-library errno's by prefixing errno names with "Wym_".//extern const WyReply Ok; // Successextern const WyReply Wym_EPERM; // Operation not permitted extern const WyReply Wym_ENOENT; // No such file or directory extern const WyReply Wym_ESRCH; // No such process extern const WyReply Wym_EINTR; // Interrupted system call extern const WyReply Wym_EIO; // Input/output error extern const WyReply Wym_ENXIO; // No such device or address extern const WyReply Wym_E2BIG; // Arg list too long extern const WyReply Wym_ENOEXEC; // Exec format error extern const WyReply Wym_EBADF; // Bad file number extern const WyReply Wym_ECHILD; // No child processes extern const WyReply Wym_EAGAIN; // Try again extern const WyReply Wym_ENOMEM; // Out of memory extern const WyReply Wym_EACCES; // Permission denied extern const WyReply Wym_EFAULT; // Bad address extern const WyReply Wym_ENOTBLK; // Block device required extern const WyReply Wym_EBUSY; // Device or resource busy extern const WyReply Wym_EEXIST; // File exists extern const WyReply Wym_EXDEV; // Cross-device link extern const WyReply Wym_ENODEV; // No such device extern const WyReply Wym_ENOTDIR; // Not a directory extern const WyReply Wym_EISDIR; // Is a directory extern const WyReply Wym_EINVAL; // Invalid argument extern const WyReply Wym_ENFILE; // File table overflow extern const WyReply Wym_EMFILE; // Too many open files extern const WyReply Wym_ENOTTY; // Not a typewriter extern const WyReply Wym_ETXTBSY; // Text file busy extern const WyReply Wym_EFBIG; // File too large extern const WyReply Wym_ENOSPC; // No space left on device extern const WyReply Wym_ESPIPE; // Illegal seek extern const WyReply Wym_EROFS; // Read-only file system extern const WyReply Wym_EMLINK; // Too many links extern const WyReply Wym_EPIPE; // Broken pipe extern const WyReply Wym_EDOM; // Math argument out of domain of func extern const WyReply Wym_ERANGE; // Math result not representable extern const WyReply Wym_EDEADLK; // Resource deadlock would occur extern const WyReply Wym_ENAMETOOLONG;// File name too long extern const WyReply Wym_ENOLCK; // No record locks available extern const WyReply Wym_ENOSYS; // Function not implemented extern const WyReply Wym_ENOTEMPTY; // Directory not empty extern const WyReply Wym_ELOOP; // Too many symbolic links encounteredextern const WyReply Wym_EWOULDBLOCK; // Operation would block extern const WyReply Wym_E41; // Unknown error 41extern const WyReply Wym_ENOMSG; // No message of desired type extern const WyReply Wym_EIDRM; // Identifier removed extern const WyReply Wym_ECHRNG; // Channel number out of range extern const WyReply Wym_EL2NSYNC; // Level 2 not synchronized extern const WyReply Wym_EL3HLT; // Level 3 halted extern const WyReply Wym_EL3RST; // Level 3 reset extern const WyReply Wym_ELNRNG; // Link number out of range extern const WyReply Wym_EUNATCH; // Protocol driver not attached extern const WyReply Wym_ENOCSI; // No CSI structure available extern const WyReply Wym_EL2HLT; // Level 2 halted extern const WyReply Wym_EBADE; // Invalid exchange extern const WyReply Wym_EBADR; // Invalid request descriptor extern const WyReply Wym_EXFULL; // Exchange full extern const WyReply Wym_ENOANO; // No anode extern const WyReply Wym_EBADRQC; // Invalid request code extern const WyReply Wym_EBADSLT; // Invalid slot extern const WyReply Wym_EDEADLOCK; // EDEADLKextern const WyReply Wym_E58; // Unknown error 58extern const WyReply Wym_EBFONT; // Bad font file format extern const WyReply Wym_ENOSTR; // Device not a stream extern const WyReply Wym_ENODATA; // No data available extern const WyReply Wym_ETIME; // Timer expired extern const WyReply Wym_ENOSR; // Out of streams resources extern const WyReply Wym_ENONET; // Machine is not on the network extern const WyReply Wym_ENOPKG; // Package not installed extern const WyReply Wym_EREMOTE; // Object is remote extern const WyReply Wym_ENOLINK; // Link has been severed extern const WyReply Wym_EADV; // Advertise error extern const WyReply Wym_ESRMNT; // Srmount error extern const WyReply Wym_ECOMM; // Communication error on send extern const WyReply Wym_EPROTO; // Protocol error extern const WyReply Wym_EMULTIHOP; // Multihop attempted extern const WyReply Wym_EDOTDOT; // RFS specific error extern const WyReply Wym_EBADMSG; // Not a data message extern const WyReply Wym_EOVERFLOW; // Value too large for defined data type extern const WyReply Wym_ENOTUNIQ; // Name not unique on network extern const WyReply Wym_EBADFD; // File descriptor in bad state extern const WyReply Wym_EREMCHG; // Remote address changed extern const WyReply Wym_ELIBACC; // Can not access a needed shared library extern const WyReply Wym_ELIBBAD; // Accessing a corrupted shared library extern const WyReply Wym_ELIBSCN; // .lib section in a.out corrupted extern const WyReply Wym_ELIBMAX; // Attempting to link in too many shared libraries extern const WyReply Wym_ELIBEXEC; // Cannot exec a shared library directly extern const WyReply Wym_EILSEQ; // Illegal byte sequence extern const WyReply Wym_ERESTART; // Interrupted system call should be restarted extern const WyReply Wym_ESTRPIPE; // Streams pipe error extern const WyReply Wym_EUSERS; // Too many users extern const WyReply Wym_ENOTSOCK; // Socket operation on non-socket extern const WyReply Wym_EDESTADDRREQ;// Destination address required extern const WyReply Wym_EMSGSIZE; // Message too long extern const WyReply Wym_EPROTOTYPE; // Protocol wrong type for socket extern const WyReply Wym_ENOPROTOOPT; // Protocol not available extern const WyReply Wym_EPROTONOSUPPORT;// Protocol not supported extern const WyReply Wym_ESOCKTNOSUPPORT;// Socket type not supported extern const WyReply Wym_EOPNOTSUPP; // Operation not supported on transport endpoint extern const WyReply Wym_EPFNOSUPPORT;// Protocol family not supported extern const WyReply Wym_EAFNOSUPPORT;// Address family not supported by protocol extern const WyReply Wym_EADDRINUSE; // Address already in use extern const WyReply Wym_EADDRNOTAVAIL;// Cannot assign requested address extern const WyReply Wym_ENETDOWN; // Network is down extern const WyReply Wym_ENETUNREACH; // Network is unreachable extern const WyReply Wym_ENETRESET; // Network dropped connection because of reset extern const WyReply Wym_ECONNABORTED;// Software caused connection abort extern const WyReply Wym_ECONNRESET; // Connection reset by peer extern const WyReply Wym_ENOBUFS; // No buffer space available extern const WyReply Wym_EISCONN; // Transport endpoint is already connected extern const WyReply Wym_ENOTCONN; // Transport endpoint is not connected extern const WyReply Wym_ESHUTDOWN; // Cannot send after transport endpoint shutdown extern const WyReply Wym_ETOOMANYREFS;// Too many references: cannot splice extern const WyReply Wym_ETIMEDOUT; // Connection timed out extern const WyReply Wym_ECONNREFUSED;// Connection refused extern const WyReply Wym_EHOSTDOWN; // Host is down extern const WyReply Wym_EHOSTUNREACH;// No route to host extern const WyReply Wym_EALREADY; // Operation already in progress extern const WyReply Wym_EINPROGRESS; // Operation now in progress extern const WyReply Wym_ESTALE; // Stale NFS file handle extern const WyReply Wym_EUCLEAN; // Structure needs cleaning extern const WyReply Wym_ENOTNAM; // Not a XENIX named type file extern const WyReply Wym_ENAVAIL; // No XENIX semaphores available extern const WyReply Wym_EISNAM; // Is a named type file extern const WyReply Wym_EREMOTEIO; // Remote I/O error extern const WyReply Wym_EDQUOT; // Quota exceeded extern const WyReply Wym_ENOMEDIUM; // No medium found extern const WyReply Wym_EMEDIUMTYPE; // Wrong medium type extern const WyReply Wym_E125; // Operation canceledextern const WyReply Wym_E126; // Unknown error 126extern const WyReply Wym_E127; // Unknown error 127//--------------------//// libwy added reply ////--------------------//extern const WyReply Wym_ETHRDCAN; // Thread canceledextern const WyReply Wym_EDIVZERO; // Divisor is zeroextern const WyReply Wym_EMATHNEG; // Math negatation failureextern const WyReply Wym_EBADTYPE; // Bad argument type/* [Thread-Cancellation-Safe] Note: All member functions do not throw*/class Wy_RepInfo { typedef Wy__ErrNoType RepCodeType; static const RepCodeType _default_rcode; RepCodeType _rcode; // reply code const char* _rstr; // zero terminated string // [Hidden] // Wy_RepInfo(const Wy_RepInfo&) WY__NOTHROW__; // object should be unique const Wy_RepInfo& operator =(const Wy_RepInfo&); bool operator ==(const Wy_RepInfo&); void* operator new(size_t); protected: // Note: Wy_RepInfo constructors are protected because this class // cannot implement set_reply. And 'explicit' can be saved. // Wy_RepInfo(const char*) WY__NOTHROW__; Wy_RepInfo(RepCodeType, const char*) WY__NOTHROW__; public: virtual ~Wy_RepInfo() WY__NOTHROW__ {}; // Note: Semantics of reply code is defined by deriving class // RepCodeType c_repcode(void) const WY__NOTHROW__; const char* c_repstr(void) const WY__NOTHROW__; virtual size_t get_reply(char* buf, size_t blen) const WY__NOTHROW__=0; virtual void set_reply(const char* str, size_t slen) WY__NOTHROW__=0;};/* [Thread-Cancellation-Safe] Note: All member functions do not throw [Implement] WyReply contains exactly one member Wy_RepInfo*, utilizing the fact that the address of static allocated object is unique in a process. The address is used as an id. Does the ptr need normalization?*/class WyReply { private: static Wy_RepInfo* const _default_ri_ptr; // default value of _ri_ptr // [Syn] Get the argument en corresponding Wy_RepInfo pointer // // [Ret] Wy_RepInfo pointer that the argument en corresponds. // The returned is a base pointer and is always dereferencable. // static Wy_RepInfo* _en2ptr(Wy__ErrNoType en) WY__NOTHROW__; Wy_RepInfo* _ri_ptr; // Hidden Wy_RepInfo& operator*() const WY__NOTHROW__; // usecase looks strange for now public: // Note: default object is not a Ok object. // WyReply() WY__NOTHROW__ : _ri_ptr(_default_ri_ptr) {}; WyReply(const WyReply &src) WY__NOTHROW__ : _ri_ptr(src._ri_ptr) {}; explicit WyReply(Wy__ErrNoType en) WY__NOTHROW__ : _ri_ptr(_en2ptr(en)) { if(_ri_ptr==NULL) { WY_TERMINATE(""); } }; explicit WyReply(Wy_RepInfo& ei) WY__NOTHROW__ : _ri_ptr(&ei) { if(_ri_ptr==NULL) { WY_TERMINATE(""); } }; WyReply(WyReply &src, Wy::ByMove_t) WY__NOTHROW__ : _ri_ptr(src._ri_ptr) {}; inline bool is_default(void) const WY__NOTHROW__ { return _ri_ptr==_default_ri_ptr; }; // Note: member is const, the returned pointer is not. // inline Wy_RepInfo* operator->() const WY__NOTHROW__ { return _ri_ptr; }; inline void reset(void) WY__NOTHROW__ { _ri_ptr=_default_ri_ptr; }; inline void reset(const WyReply& ec) WY__NOTHROW__ { _ri_ptr=ec._ri_ptr; }; Wy__ErrNoType reset(Wy__ErrNoType en) WY__NOTHROW__; // Note: This version of reset might cause bad use //void reset(const Wy_RepInfo& ei) WY__NOTHROW__ inline const WyReply& operator =(const WyReply& rhs) WY__NOTHROW__ { _ri_ptr=rhs._ri_ptr; return *this; }; inline const WyReply& operator =(Wy__ErrNoType en) WY__NOTHROW__ { _ri_ptr=_en2ptr(en); return *this; }; inline bool operator==(const WyReply& rhs) const WY__NOTHROW__ { return _ri_ptr==rhs._ri_ptr; }; inline bool operator!=(const WyReply& rhs) const WY__NOTHROW__ { return _ri_ptr!=rhs._ri_ptr; }; // [Evaluation] .is operator bool suitable? // .can Ok be safed? // Note: this member is so far not as useful, // //inline bool is_ok(void) const WY__NOTHROW__ // { return _ri_ptr!=Ok._ri_ptr; };};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -