Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

  1. //===- llvm/ADT/NullablePtr.h - A pointer that allows null ------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines and implements the NullablePtr class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ADT_NULLABLEPTR_H
  14. #define LLVM_ADT_NULLABLEPTR_H
  15. #include <cassert>
  16. #include <cstddef>
  17. namespace llvm {
  18. /// NullablePtr pointer wrapper - NullablePtr is used for APIs where a
  19. /// potentially-null pointer gets passed around that must be explicitly handled
  20. /// in lots of places. By putting a wrapper around the null pointer, it makes
  21. /// it more likely that the null pointer case will be handled correctly.
  22. template<class T>
  23. class NullablePtr {
  24. T *Ptr;
  25. public:
  26. NullablePtr(T *P = 0) : Ptr(P) {}
  27. bool isNull() const { return Ptr == 0; }
  28. bool isNonNull() const { return Ptr != 0; }
  29. /// get - Return the pointer if it is non-null.
  30. const T *get() const {
  31. assert(Ptr && "Pointer wasn't checked for null!");
  32. return Ptr;
  33. }
  34. /// get - Return the pointer if it is non-null.
  35. T *get() {
  36. assert(Ptr && "Pointer wasn't checked for null!");
  37. return Ptr;
  38. }
  39. T *getPtrOrNull() { return Ptr; }
  40. const T *getPtrOrNull() const { return Ptr; }
  41. };
  42. } // end namespace llvm
  43. #endif