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

📄 wy_dirfile.cpp

📁 一个不错
💻 CPP
字号:
/* Copyright is licensed under GNU LGPL.                 by I.J.Wang 2003*/#define WYLIB_SOURCE#include "wy_dirfile.h"#include "wy__dirhandle.h"#include "wy_atdestroy.h"#include <new>#include <typeinfo>const char Wy_DirFile::class_name[]="Wy_DirFile";Wy_DirFile::Wy_DirFile() : _hptr(0){};Wy_DirFile::Wy_DirFile(const Wy_DirFile &dirf)try : _hptr(NULL) { _hptr=0; if(dirf.is_default()) {   return; } _hptr= new(std::nothrow) Wy__DirHandle(*dirf._hptr); if(_hptr==0) {   WY_THROW( Reply(Wym_ENOMEM) ); }}catch(const Reply&) {  throw;}catch(const Wy__DirHandle::Reply& e) {  WY_THROW( Reply(e) );}catch(const WyRet& e) { WY_NDEBUG_MSG(e); WY_THROW( WyRet(e) );};Wy_DirFile::Wy_DirFile(const char* pathname)try : _hptr(0) { Wy__DirHandle* ptr= new(std::nothrow) Wy__DirHandle(); if(ptr==0) {   WY_THROW( Reply(Wym_ENOMEM) ); } Wy_AtDestroy<void,Wy__DirHandle*> rrid(Wy::_delete_one,ptr); WyRet r( ptr->open(pathname) ); if(r!=Ok) {   WY_THROW( Reply(r) ); } _hptr=ptr; rrid.release();}catch(const Reply&) {  throw;}catch(const Wy__DirHandle::Reply& e) {  WY_THROW( Reply(e) );}catch(const WyRet& e) { WY_NDEBUG_MSG(e); WY_THROW( WyRet(e) );};Wy_DirFile::Wy_DirFile(const WyStr& pathname)try : _hptr(0) { Wy__DirHandle* ptr= new(std::nothrow) Wy__DirHandle(); if(ptr==0) {   WY_THROW( Reply(Wym_ENOMEM) ); } Wy_AtDestroy<void,Wy__DirHandle*> rrid(Wy::_delete_one,ptr); WyRet r( ptr->open(pathname) ); if(r!=Ok) {   WY_THROW( Reply(r) ); } rrid.release(); _hptr=ptr;}catch(const Reply&) {  throw;}catch(const Wy__DirHandle::Reply& e) {  WY_THROW( Reply(e) );}catch(const WyRet& e) { WY_NDEBUG_MSG(e); WY_THROW( WyRet(e) );};Wy_DirFile::Wy_DirFile(Wy_DirFile &src, Wy::ByMove_t) WY__TSPC() : _hptr(src._hptr){ src._hptr=NULL;};Wy_DirFile::~Wy_DirFile(){ Wy__Base::NoCancel noc; delete _hptr; _hptr=NULL;};bool Wy_DirFile::is_default(void) const WY__TSPC(){ return _hptr==NULL; };WyFileHandle Wy_DirFile::fh(void) const WY__TSPC(){ if(_hptr==0) {   return WyFileHandle(); } return _hptr->fh();};WyRet Wy_DirFile::stat(WyFileStat& filestat) const{ if(_hptr==0) {   WY_RETURN(Wym_EBADF); } WY_RETURN( _hptr->fstat(filestat) );};WyRet Wy_DirFile::reset(void){ if(_hptr==0) {   return(Ok); } Wy__DirHandle* ptr(_hptr); _hptr=NULL; try {   delete ptr; } catch(const Wy__DirHandle::Reply& e) {   WY_RETURN(e); } catch(const WyRet& e) { WY_NDEBUG_MSG(e);   WY_THROW( WyRet(e) ); } return(Ok);};WyRet Wy_DirFile::reset(const Wy_DirFile& dirf)try { if(dirf.is_default()) {   this->reset();   return(Ok); } if(_hptr==dirf._hptr) {   return(Ok); } Wy__DirHandle* ptr= new(std::nothrow) Wy__DirHandle(); if(ptr==0) {   WY_RETURN(Wym_ENOMEM); } Wy_AtDestroy<void,Wy__DirHandle*> rrid(Wy::_delete_one,ptr); const WyRet r( ptr->reset(*dirf._hptr) ); if(r!=Ok) {   WY_RETURN(r); } if(_hptr==0) {   _hptr=ptr;   rrid.release(); } else {   _hptr->swap(*ptr); } return(Ok);}catch(const Wy__DirHandle::Reply& e) {  WY_RETURN(e);}catch(const WyRet& e) { WY_NDEBUG_MSG(e);  WY_THROW( WyRet(e) );};WyRet Wy_DirFile::reset(const char* pathname)try { Wy__DirHandle* ptr= new(std::nothrow) Wy__DirHandle(); if(ptr==0) {   WY_RETURN(Wym_ENOMEM); } Wy_AtDestroy<void,Wy__DirHandle*> rrid(Wy::_delete_one,ptr); const WyRet r( ptr->open(pathname) ); if(r!=Ok) {   WY_RETURN(r); } if(_hptr==0) {   _hptr=ptr;   rrid.release(); } else {   _hptr->swap(*ptr); } return(Ok);}catch(const Wy__DirHandle::Reply& e) {  WY_RETURN(e);}catch(const WyRet& e) { WY_NDEBUG_MSG(e);  WY_THROW( WyRet(e) );};WyRet Wy_DirFile::reset(const WyStr& pathname)try { Wy__DirHandle* ptr= new(std::nothrow) Wy__DirHandle(); if(ptr==0) {   WY_RETURN(Wym_ENOMEM); } Wy_AtDestroy<void,Wy__DirHandle*> rrid(Wy::_delete_one,ptr); const WyRet r( ptr->open(pathname) ); if(r!=Ok) {   WY_RETURN(r); } if(_hptr==0) {   _hptr=ptr;   rrid.release(); } else {   _hptr->swap(*ptr); } return(Ok);}catch(const Wy__DirHandle::Reply& e) {  WY_RETURN(e);}catch(const WyRet& e) { WY_NDEBUG_MSG(e);  WY_THROW( WyRet(e) );};WyRet Wy_DirFile::_swap(Wy_DirFile& dirf) WY__TSPC(){ if(typeid(*this)!=typeid(dirf)) {   WY_RETURN(Wym_EBADTYPE); } Wy__Base::vswap(_hptr,dirf._hptr); return(Ok);};Wy_DirFile* Wy_DirFile::_alloc(WyRet& r) consttry { if(WY__EQU_TYPEID(*this,Wy_DirFile)==false) {   r=Wym_ENOSYS; WY_HERE(r);        // _alloc not overridden   return(NULL); } Wy_DirFile* p=new(std::nothrow) Wy_DirFile(); if(p==NULL) {   r=Wym_ENOMEM; WY_HERE(r); } else {   r=Ok; } return(p);}catch(const Reply& e) { r=e; WY_HERE(r); return(0);}catch(const WyRet& e) { WY_NDEBUG_MSG(e); WY_THROW( WyRet(e) );};WyRet Wy_DirFile::read(WyDirEnt& dent){ if(_hptr==0) {   WY_RETURN(Wym_EBADF); } const WyRet r( _hptr->read(dent) ); if(r!=Ok) {   WY_RETURN(r); } return(Ok);};WyRet Wy_DirFile::rewind(void){ if(_hptr==0) {   WY_RETURN(Wym_EBADF); } const WyRet r( _hptr->rewind() ); if(r!=Ok) {   WY_RETURN(r); } return(Ok);};size_t Wy_DirFile::wy_ref_count(void) const{  if(_hptr==0) {    return(0);  }  const size_t v=_hptr->ref_count();  if(v<=0) {    WY_THROW( WyRet() );  }  return(v);};WyRet Wy_DirFile::create(const char* pathname,mode_t mode){ if(::mkdir(pathname,mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet Wy_DirFile::create(const WyStr& pathname,mode_t mode){ if(::mkdir(pathname.c_str(),mode)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet Wy_DirFile::unlink(const char* pathname){ if(::rmdir(pathname)!=0) {   WY_RETURN(errno); }; return(Ok);};WyRet Wy_DirFile::unlink(const WyStr& pathname){ if(::rmdir(pathname.c_str())!=0) {   WY_RETURN(errno); }; return(Ok);};

⌨️ 快捷键说明

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