summaryrefslogtreecommitdiffstats
path: root/xbmc/interfaces/legacy/Alternative.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/interfaces/legacy/Alternative.h
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/interfaces/legacy/Alternative.h')
-rw-r--r--xbmc/interfaces/legacy/Alternative.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/xbmc/interfaces/legacy/Alternative.h b/xbmc/interfaces/legacy/Alternative.h
new file mode 100644
index 0000000..a715688
--- /dev/null
+++ b/xbmc/interfaces/legacy/Alternative.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2005-2018 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include "Exception.h"
+
+namespace XBMCAddon
+{
+ enum WhichAlternative { none, first, second };
+
+ template<typename T1, typename T2> class Alternative
+ {
+ public:
+ private:
+ WhichAlternative pos = none;
+ T1 d1;
+ T2 d2;
+
+ public:
+ Alternative() = default;
+
+ inline WhichAlternative which() const { return pos; }
+
+ inline T1& former()
+ {
+ if (pos == second)// first and none is ok
+ throw WrongTypeException("Access of XBMCAddon::Alternative as incorrect type");
+ if (pos == none)
+ d1 = T1();
+ pos = first;
+ return d1;
+ }
+
+ inline const T1& former() const
+ {
+ if (pos != first)
+ throw WrongTypeException("Access of XBMCAddon::Alternative as incorrect type");
+ return d1;
+ }
+
+ inline T2& later()
+ {
+ if (pos == first)
+ throw WrongTypeException("Access of XBMCAddon::Alternative as incorrect type");
+ if (pos == none)
+ d2 = T2();
+ pos = second;
+ return d2;
+ }
+
+ inline const T2& later() const
+ {
+ if (pos != second)
+ throw WrongTypeException("Access of XBMCAddon::Alternative as incorrect type");
+ return d2;
+ }
+
+ inline operator T1& () { return former(); }
+ inline operator const T1& () const { return former(); }
+ inline operator T2& () { return later(); }
+ inline operator const T2& () const { return later(); }
+ };
+}
+