Кресты / Говнокод #29240 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
namespace arangodb {
class DatabaseFeature;

struct IDatabaseGuard {
  virtual ~IDatabaseGuard() = default;
  [[nodiscard]] virtual TRI_vocbase_t& database() const noexcept = 0;
};

struct VocbaseReleaser {
  void operator()(TRI_vocbase_t* vocbase) const noexcept;
};

using VocbasePtr = std::unique_ptr<TRI_vocbase_t, VocbaseReleaser>;

/// @brief Scope guard for a database, ensures that it is not
///        dropped while still using it.
class DatabaseGuard final : public IDatabaseGuard {
 public:
  /// @brief create guard on existing db
  explicit DatabaseGuard(TRI_vocbase_t& vocbase);

  /// @brief create guard from existing VocbasePtr
  explicit DatabaseGuard(VocbasePtr vocbase);

  /// @brief create the guard, using a database id
  DatabaseGuard(DatabaseFeature& feature, TRI_voc_tick_t id);

  /// @brief create the guard, using a database name
  DatabaseGuard(DatabaseFeature& feature, std::string_view name);

  /// @brief return the database pointer
  TRI_vocbase_t& database() const noexcept final { return *_vocbase; }
  TRI_vocbase_t const* operator->() const noexcept { return _vocbase.get(); }
  TRI_vocbase_t* operator->() noexcept { return _vocbase.get(); }

 private:
  VocbasePtr _vocbase;
};

}  // namespace arangodb

Виртуальное гавно!

Запостил: gnusmas gnusmas, (Updated )

Комментарии (2) RSS

  • зачем тут вообще виртуализаия? чтобы что? потому что в книжка 90-х годов писали что ООП это првильно?


    > /// @brief return the database pointer
    какой полезный комментарий


    и вообще это всё обертка вокруг VocbasePtr, реально можно заменить на свободную функципю, которая его возвращает?
    Ответить
  • ИНЬЮ?

    Соедините меня с инженером ВЫСШЕЙ категории!

    Govnokod.xyz РАБОТАЛ, и я КАЙФОВАЛ! А вы мой кайф разрываете!!!
    Ответить

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8