File indexing completed on 2024-05-12 04:39:42
0001 /* 0002 SPDX-FileCopyrightText: 2004 Roberto Raggi <roberto@kdevelop.org> 0003 SPDX-FileCopyrightText: 2005-2006 Vladimir Prus <ghost@cs.msu.su> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "mi.h" 0009 0010 using namespace KDevMI::MI; 0011 0012 0013 type_error::type_error() 0014 : std::logic_error("MI type error") 0015 {} 0016 0017 QString Value::literal() const 0018 { 0019 throw type_error(); 0020 } 0021 0022 int Value::toInt(int /*base*/) const 0023 { 0024 throw type_error(); 0025 } 0026 0027 bool Value::hasField(const QString&) const 0028 { 0029 throw type_error(); 0030 } 0031 0032 const Value& Value::operator[](const QString&) const 0033 { 0034 throw type_error(); 0035 } 0036 0037 bool Value::empty() const 0038 { 0039 throw type_error(); 0040 } 0041 0042 int Value::size() const 0043 { 0044 throw type_error(); 0045 } 0046 0047 0048 const Value& Value::operator[](int) const 0049 { 0050 throw type_error(); 0051 } 0052 0053 QString StringLiteralValue::literal() const 0054 { 0055 return literal_; 0056 } 0057 0058 int StringLiteralValue::toInt(int base) const 0059 { 0060 bool ok; 0061 int result = literal_.toInt(&ok, base); 0062 if (!ok) 0063 throw type_error(); 0064 return result; 0065 } 0066 0067 TupleValue::~TupleValue() 0068 { 0069 qDeleteAll(results); 0070 } 0071 0072 bool TupleValue::hasField(const QString& variable) const 0073 { 0074 return results_by_name.contains(variable); 0075 } 0076 0077 const Value& TupleValue::operator[](const QString& variable) const 0078 { 0079 Result* result = results_by_name.value(variable); 0080 if (!result) 0081 throw type_error(); 0082 return *result->value; 0083 } 0084 0085 ListValue::~ListValue() 0086 { 0087 qDeleteAll(results); 0088 } 0089 0090 bool ListValue::empty() const 0091 { 0092 return results.isEmpty(); 0093 } 0094 0095 int ListValue::size() const 0096 { 0097 return results.size(); 0098 } 0099 0100 const Value& ListValue::operator[](int index) const 0101 { 0102 if (index < results.size()) 0103 { 0104 return *results[index]->value; 0105 } 0106 else 0107 throw type_error(); 0108 } 0109 0110 0111 0112