1 /*
2     SPDX-FileCopyrightText: 2004 Roberto Raggi <roberto@kdevelop.org>
3     SPDX-FileCopyrightText: 2005-2006 Vladimir Prus <ghost@cs.msu.su>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "mi.h"
9 
10 using namespace KDevMI::MI;
11 
12 
type_error()13 type_error::type_error()
14 : std::logic_error("MI type error")
15 {}
16 
literal() const17 QString Value::literal() const
18 {
19     throw type_error();
20 }
21 
toInt(int) const22 int Value::toInt(int /*base*/) const
23 {
24     throw type_error();
25 }
26 
hasField(const QString &) const27 bool Value::hasField(const QString&) const
28 {
29     throw type_error();
30 }
31 
operator [](const QString &) const32 const Value& Value::operator[](const QString&) const
33 {
34     throw type_error();
35 }
36 
empty() const37 bool Value::empty() const
38 {
39     throw type_error();
40 }
41 
size() const42 int Value::size() const
43 {
44     throw type_error();
45 }
46 
47 
operator [](int) const48 const Value& Value::operator[](int) const
49 {
50     throw type_error();
51 }
52 
literal() const53 QString StringLiteralValue::literal() const
54 {
55     return literal_;
56 }
57 
toInt(int base) const58 int StringLiteralValue::toInt(int base) const
59 {
60     bool ok;
61     int result = literal_.toInt(&ok, base);
62     if (!ok)
63         throw type_error();
64     return result;
65 }
66 
~TupleValue()67 TupleValue::~TupleValue()
68 {
69     qDeleteAll(results);
70 }
71 
hasField(const QString & variable) const72 bool TupleValue::hasField(const QString& variable) const
73 {
74     return results_by_name.contains(variable);
75 }
76 
operator [](const QString & variable) const77 const Value& TupleValue::operator[](const QString& variable) const
78 {
79     Result* result = results_by_name.value(variable);
80     if (!result)
81         throw type_error();
82     return *result->value;
83 }
84 
~ListValue()85 ListValue::~ListValue()
86 {
87     qDeleteAll(results);
88 }
89 
empty() const90 bool ListValue::empty() const
91 {
92     return results.isEmpty();
93 }
94 
size() const95 int ListValue::size() const
96 {
97     return results.size();
98 }
99 
operator [](int index) const100 const Value& ListValue::operator[](int index) const
101 {
102     if (index < results.size())
103     {
104         return *results[index]->value;
105     }
106     else
107         throw type_error();
108 }
109 
110 
111 
112 
113