[gnome-games/wip/exalm/platform-preferences: 16/28] core: Add PlatformRegister
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/platform-preferences: 16/28] core: Add PlatformRegister
- Date: Tue, 25 Sep 2018 17:36:36 +0000 (UTC)
commit 8c71f27c713a0dc33c373391f671614c2e04c536
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Mon May 21 02:22:51 2018 +0500
core: Add PlatformRegister
This will be used in the following commits to represent the global
collection of Platform objects.
src/core/platform-register.vala | 37 +++++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
2 files changed, 38 insertions(+)
---
diff --git a/src/core/platform-register.vala b/src/core/platform-register.vala
new file mode 100644
index 00000000..db8ae63b
--- /dev/null
+++ b/src/core/platform-register.vala
@@ -0,0 +1,37 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.PlatformRegister : Object {
+ private static PlatformRegister instance;
+ private HashTable<string, Platform> platforms;
+
+ private PlatformRegister () {
+ platforms = new HashTable<string, Platform> (str_hash, str_equal);
+ }
+
+ public static PlatformRegister get_register () {
+ if (instance == null)
+ instance = new PlatformRegister ();
+
+ return instance;
+ }
+
+ public void add_platform (Platform platform) {
+ var platform_id = platform.get_id ();
+
+ assert (!platforms.contains (platform_id));
+
+ platforms[platform_id] = platform;
+ }
+
+ public Platform get_platform (string platform_id) {
+ return platforms[platform_id];
+ }
+
+ public List<Platform> get_all_platforms () {
+ var values = platforms.get_values ();
+ var result = values.copy ();
+ result.sort (Platform.compare);
+
+ return result;
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index 76075ecd..fef1c8bf 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -30,6 +30,7 @@ vala_sources = [
'core/media-set/media-set.vala',
'core/media-set/media-set-error.vala',
'core/platform.vala',
+ 'core/platform-register.vala',
'core/players.vala',
'core/plugin.vala',
'core/plugin-register.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]