aboutsummaryrefslogtreecommitdiff
path: root/src/platform/gui/UiApplication.cpp
blob: de92e61a85d944f14952e0650a273be54cc500b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "cru/platform/gui/UiApplication.h"
#include "cru/base/Base.h"

#include <unordered_set>

namespace cru::platform::gui {

void DeleteLaterPool::Add(Object* object) { pool_.push_back(object); }

void DeleteLaterPool::Clean() {
  // Destructors of objects might add more objects to delete later. So the safe
  // implementation is to copy current pool to avoid modification during
  // iteration.
  while (!pool_.empty()) {
    std::vector<Object*> copy = std::move(pool_);
    std::unordered_set<Object*> deleted;
    for (auto object : copy) {
      if (!deleted.contains(object)) {
        deleted.insert(object);
        delete object;
      }
    }
  }
}

namespace {
IUiApplication* instance = nullptr;
}

IUiApplication* IUiApplication::GetInstance() { return instance; }

IUiApplication::IUiApplication() {
  if (instance) {
    throw Exception("A ui application has already been created.");
  }

  instance = this;
}

IUiApplication::~IUiApplication() { instance = nullptr; }

IMenu* IUiApplication::GetApplicationMenu() { return nullptr; }

std::optional<std::string> IUiApplication::ShowSaveDialog(
    SaveDialogOptions options) {
  NotImplemented();
}

std::optional<std::vector<std::string>> IUiApplication::ShowOpenDialog(
    OpenDialogOptions options) {
  NotImplemented();
}
}  // namespace cru::platform::gui