A 2D tile-based sandbox game.
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.

util.h 984B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <memory>
  3. /*
  4. * This file mostly just contains copy-pasted stuff from libswan.
  5. * I don't love the code duplication, but it feels overkill to have a
  6. * library which both libcygnet and libswan depends on just for this stuff.
  7. */
  8. namespace Cygnet {
  9. // Inherit from this class to make a class non-copyable
  10. class NonCopyable {
  11. public:
  12. NonCopyable(const NonCopyable &) = delete;
  13. NonCopyable(NonCopyable &&) noexcept = default;
  14. NonCopyable &operator=(const NonCopyable &) = delete;
  15. NonCopyable &operator=(NonCopyable &&) = default;
  16. protected:
  17. NonCopyable() = default;
  18. ~NonCopyable() = default;
  19. };
  20. // Take a deleter function, turn it into a class with an operator() for unique_ptr
  21. template<typename T, void (*Func)(T *)>
  22. class CPtrDeleter {
  23. public:
  24. void operator()(T *ptr) { Func(ptr); }
  25. };
  26. // This is just a bit nicer to use than using unique_ptr directly
  27. template<typename T, void (*Func)(T *)>
  28. using CPtr = std::unique_ptr<T, CPtrDeleter<T, Func>>;
  29. }