File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ===-- Either.h -----------------------------------------------*- C++ -*-===//
2
+ //
3
+ // The LLVM Compiler Infrastructure
4
+ //
5
+ // This file is distributed under the University of Illinois Open Source
6
+ // License. See LICENSE.TXT for details.
7
+ //
8
+ // ===----------------------------------------------------------------------===//
9
+
10
+ #ifndef liblldb_Either_h_
11
+ #define liblldb_Either_h_
12
+
13
+ #include " llvm/ADT/Optional.h"
14
+
15
+ namespace lldb_utility {
16
+ template <typename T1, typename T2>
17
+ class Either {
18
+ private:
19
+ enum class Selected {
20
+ One, Two
21
+ };
22
+
23
+ Selected m_selected;
24
+ union {
25
+ T1 m_t1;
26
+ T2 m_t2;
27
+ };
28
+
29
+ public:
30
+ Either (const T1& t1)
31
+ {
32
+ m_t1 = t1;
33
+ m_selected = Selected::One;
34
+ }
35
+
36
+ Either (const T2& t2)
37
+ {
38
+ m_t2 = t2;
39
+ m_selected = Selected::Two;
40
+ }
41
+
42
+ template <class X , typename std::enable_if<std::is_same<T1,X>::value>::type * = nullptr >
43
+ llvm::Optional<T1>
44
+ GetAs ()
45
+ {
46
+ switch (m_selected)
47
+ {
48
+ case Selected::One:
49
+ return m_t1;
50
+ default :
51
+ return llvm::Optional<T1>();
52
+ }
53
+ }
54
+
55
+ template <class X , typename std::enable_if<std::is_same<T2,X>::value>::type * = nullptr >
56
+ llvm::Optional<T2>
57
+ GetAs ()
58
+ {
59
+ switch (m_selected)
60
+ {
61
+ case Selected::Two:
62
+ return m_t2;
63
+ default :
64
+ return llvm::Optional<T2>();
65
+ }
66
+ }
67
+ };
68
+
69
+ } // namespace lldb_utility
70
+
71
+ #endif // #ifndef liblldb_Either_h_
72
+
Original file line number Diff line number Diff line change 2431
2431
9475C18D14E5F834001BFC6D /* SBTypeNameSpecifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBTypeNameSpecifier.cpp; path = source/API/SBTypeNameSpecifier.cpp; sourceTree = "<group>"; };
2432
2432
947A1D621616476A0017C8D1 /* CommandObjectPlugin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CommandObjectPlugin.cpp; path = source/Commands/CommandObjectPlugin.cpp; sourceTree = "<group>"; };
2433
2433
947A1D631616476A0017C8D1 /* CommandObjectPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CommandObjectPlugin.h; path = source/Commands/CommandObjectPlugin.h; sourceTree = "<group>"; };
2434
+ 9481FE6B1B5F2D9200DED357 /* Either.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Either.h; path = include/lldb/Utility/Either.h; sourceTree = "<group>"; };
2434
2435
9492E2A41A8AC11000295BBD /* CoreMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CoreMedia.cpp; path = source/DataFormatters/CoreMedia.cpp; sourceTree = "<group>"; };
2435
2436
949ADF001406F62E004833E1 /* ValueObjectConstResultImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ValueObjectConstResultImpl.h; path = include/lldb/Core/ValueObjectConstResultImpl.h; sourceTree = "<group>"; };
2436
2437
949ADF021406F648004833E1 /* ValueObjectConstResultImpl.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ValueObjectConstResultImpl.cpp; path = source/Core/ValueObjectConstResultImpl.cpp; sourceTree = "<group>"; };
3532
3533
264723A511FA076E00DE380C /* CleanUp.h */,
3533
3534
3F81691B1ABA242B001DA9DF /* ConvertEnum.h */,
3534
3535
3F8169171ABA2419001DA9DF /* ConvertEnum.cpp */,
3536
+ 9481FE6B1B5F2D9200DED357 /* Either.h */,
3535
3537
4C73152119B7D71700F865A4 /* Iterable.h */,
3536
3538
942829541A89614000521B30 /* JSON.h */,
3537
3539
942829551A89614C00521B30 /* JSON.cpp */,
You can’t perform that action at this time.
0 commit comments