Sha256: 5f139b8a49fb490c5711d581558e626bf0470392947e1b412695cc5f3e6cbb0d

Contents?: true

Size: 969 Bytes

Versions: 9

Compression:

Stored size: 969 Bytes

Contents

#ifndef MARISA_SCOPED_PTR_H_
#define MARISA_SCOPED_PTR_H_

#include "base.h"

namespace marisa {

template <typename T>
class scoped_ptr {
 public:
  scoped_ptr() : ptr_(NULL) {}
  explicit scoped_ptr(T *ptr) : ptr_(ptr) {}

  ~scoped_ptr() {
    delete ptr_;
  }

  void reset(T *ptr = NULL) {
    MARISA_THROW_IF((ptr != NULL) && (ptr == ptr_), MARISA_RESET_ERROR);
    scoped_ptr(ptr).swap(*this);
  }

  T &operator*() const {
    MARISA_DEBUG_IF(ptr_ == NULL, MARISA_STATE_ERROR);
    return *ptr_;
  }
  T *operator->() const {
    MARISA_DEBUG_IF(ptr_ == NULL, MARISA_STATE_ERROR);
    return ptr_;
  }
  T *get() const {
    return ptr_;
  }

  void clear() {
    scoped_ptr().swap(*this);
  }
  void swap(scoped_ptr &rhs) {
    marisa::swap(ptr_, rhs.ptr_);
  }

 private:
  T *ptr_;

  // Disallows copy and assignment.
  scoped_ptr(const scoped_ptr &);
  scoped_ptr &operator=(const scoped_ptr &);
};

}  // namespace marisa

#endif  // MARISA_SCOPED_PTR_H_

Version data entries

9 entries across 6 versions & 1 rubygems

Version Path
melisa-0.2.5 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h
melisa-0.2.4 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h
melisa-0.2.3 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h
melisa-0.2.2 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h
melisa-0.2.2 ext/marisa-0.2.4/pkg/include/marisa/scoped-ptr.h
melisa-0.2.1 ext/marisa-0.2.4/pkg/include/marisa/scoped-ptr.h
melisa-0.2.1 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h
melisa-0.2.0 ext/marisa-0.2.4/pkg/include/marisa/scoped-ptr.h
melisa-0.2.0 ext/marisa-0.2.4/lib/marisa/scoped-ptr.h