⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wyseg.h

📁 一个不错
💻 H
字号:
/* Copyright is licensed by GNU LGPL.                 by I.J.Wang 2006 .WySeg<void> specilization not implemented (may be different) .WySeg: no member dereferences the pointed range of elements*/#ifndef WYSEG_H__#define WYSEG_H__#define WYSEG_VERSION 31#include "wyret.h"template<typename T>class WySeg {  public:    typedef size_t size_type;    typedef T* pointer_type;    typedef T value_type;  private:    // [Syn] Construct object to point to p, size is the minimum of s1 and s2    //    inline WySeg(pointer_type p,size_type s1, size_type s2)         : _p_bgn(p), _p_end(p+ ((s1<s2)? s1:s2))         {};    pointer_type _p_bgn;  // begin of the sub-array    pointer_type _p_end;  // end of the sub-array (past-the-end value)    // Hidden (vague)    WySeg();  public:    WY_THROW_REPLY;    WySeg(const WySeg& s) WY__TSPC()         : _p_bgn(s._p_bgn), _p_end(s._p_end) {};    WySeg(pointer_type p, size_type s) WY__TSPC(Reply)         : _p_bgn(p), _p_end(p+s)         {           if(p==NULL) {             WY_THROW( Reply(Wym_EFAULT) );            }         };    WySeg(pointer_type head, pointer_type tail) WY__TSPC(Reply)         : _p_bgn(head), _p_end(tail)         {           if((head==NULL)||(tail==NULL)) {             WY_THROW( Reply(Wym_EFAULT) );           }           if(ptrdiff_t(tail-head)<0) {             WY_THROW( Reply(Wym_ERANGE) );           }         };    WySeg(WySeg& s, Wy::ByMove_t) WY__TSPC()         : _p_bgn(s._p_bgn), _p_end(s._p_end) {           #ifndef NDEBUG            s._p_bgn=s._p_end=NULL;            #endif         };    pointer_type begin(void) const WY__TSPC()         { return(_p_bgn); };    pointer_type end(void) const WY__TSPC()         { return _p_end; };    size_type size(void) const WY__TSPC()         { return(_p_end-_p_bgn); };    value_type& operator[](size_type idx) const WY__TSPC(Reply)         {           if(idx>=size_type(_p_end-_p_bgn)) {             WY_THROW( typename WySeg::Reply(Wym_EINVAL) );           }           return _p_bgn[idx];          };    void reset(const WySeg& s) WY__TSPC()         { _p_bgn=s._p_bgn; _p_end=s._p_end; };    WyRet reset(pointer_type p, size_type s) WY__TSPC()         {           if(p==NULL) {             WY_RETURN(Wym_EFAULT);           }           _p_bgn=p;           _p_end=p+s;            return(Ok);         };    WyRet reset(pointer_type head, pointer_type tail) WY__TSPC()         {           if((head==NULL)||(tail==NULL)) {             WY_RETURN( Wym_EFAULT );           }           if(tail<head) {             WY_RETURN( Wym_ERANGE );           }           _p_bgn=head;           _p_end=tail;           return(Ok);         };    const WySeg& operator=(const WySeg& s) WY__TSPC()         { _p_bgn=s._p_bgn; _p_end=s._p_end; return(*this); };    void swap(WySeg& ano) WY__TSPC()         {           Wy__Base::vswap(_p_bgn,ano._p_bgn);           Wy__Base::vswap(_p_end,ano._p_end);         };    WySeg subseg(size_type idx) const WY__TSPC(Reply)         {           if(idx>static_cast<size_type>(_p_end-_p_bgn)) {             WY_THROW( Reply(Wym_EINVAL) );           }           return WySeg(_p_bgn+idx,_p_end);         };    WySeg subseg(size_type idx, size_type s) const WY__TSPC(Reply)         {           const size_type seg_len(_p_end-_p_bgn);           if(idx>seg_len) {             WY_THROW( Reply(Wym_EINVAL) );           }           return WySeg(_p_bgn+idx,seg_len-idx,s);         };    bool is_overlap(const WySeg& s) const WY__TSPC()         {           if((_p_bgn==_p_end)||(s._p_bgn==s._p_end)) { // either is size 0             return(false);           }           if(_p_bgn<s._p_bgn) {             return(_p_end>s._p_bgn);           } else if(_p_bgn>s._p_bgn) {             return(_p_bgn<s._p_end);           } else {             return(true);           }         };    // note: size==0 doest not determine equivalence    //    bool operator==(const WySeg& rhs) const WY__TSPC()         { return ((_p_bgn==rhs._p_bgn)&&(_p_end==rhs._p_end)); };    bool operator!=(const WySeg& rhs) const WY__TSPC()         { return ((_p_bgn!=rhs._p_bgn)||(_p_end!=rhs._p_end)); };};#endif   // End WYSEG_H__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -