ScopedFindFileHandle

来源:互联网 发布:知我网的东西是正品吗 编辑:程序博客网 时间:2024/06/01 09:24

class ScopedFindFileHandle {

 public:

  explicit ScopedFindFileHandle(HANDLE handle) : handle_(handle) {

    // Windows is inconsistent about invalid handles, so we always use NULL

    if (handle_ == INVALID_HANDLE_VALUE)

      handle_ = NULL;

  }

 

  ~ScopedFindFileHandle() {

    if (handle_)

      FindClose(handle_);

  }

 

  // Use this instead of comparing to INVALID_HANDLE_VALUE to pick up our NULL

  // usage for errors.

  bool IsValid() const { return handle_ != NULL; }

 

  operator HANDLE() { return handle_; }

 

 private:

  HANDLE handle_;

 

  DISALLOW_EVIL_CONSTRUCTORS(ScopedFindFileHandle);

};

原创粉丝点击