1 //===-- MICmnMIValueList.cpp ------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "MICmnMIValueList.h"
11 #include "MICmnResources.h"
14 // Details: CMICmnMIValueList constructor.
16 // Args: vbValueTypeList - (R) True = yes value type list, false = result
21 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList) {
26 // Details: CMICmnMIValueList constructor.
27 // Construct a results only list.
28 // return MIstatus::failure.
30 // Args: vResult - (R) MI result object.
34 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult) {
35 m_strValue = vResult.GetString();
37 m_bJustConstructed = false;
41 // Details: CMICmnMIValueList constructor.
42 // Construct a value only list.
44 // Args: vValue - (R) MI value object.
48 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue) {
49 m_strValue = vValue.GetString();
51 m_bJustConstructed = false;
55 // Details: CMICmnMIValueList destructor.
56 // Type: Overrideable.
61 CMICmnMIValueList::~CMICmnMIValueList() {}
64 // Details: Build the result value's mandatory data part, one tuple
70 void CMICmnMIValueList::BuildList() {
71 const char *pFormat = "[%s]";
72 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
76 // Details: Add another MI result object to the value list's of list is
78 // Only result objects can be added to a list of result otherwise this
80 // will return MIstatus::failure.
82 // Args: vResult - (R) The MI result object.
86 void CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult) {
91 // Details: Add another MI value object to the value list's of list is values.
92 // Only values objects can be added to a list of values otherwise this
94 // will return MIstatus::failure.
96 // Args: vValue - (R) The MI value object.
100 void CMICmnMIValueList::Add(const CMICmnMIValue &vValue) { BuildList(vValue); }
103 // Details: Add another MI result object to the value list's of list is
105 // Only result objects can be added to a list of result otherwise this
107 // will return MIstatus::failure.
109 // Args: vResult - (R) The MI result object.
113 void CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult) {
114 // Clear out the default "<Invalid>" text
115 if (m_bJustConstructed) {
116 m_bJustConstructed = false;
117 m_strValue = vResult.GetString();
122 const CMIUtilString data(ExtractContentNoBrackets());
123 const char *pFormat = "[%s,%s]";
125 CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
129 // Details: Add another MI value object to the value list's of list is values.
130 // Only values objects can be added to a list of values otherwise this
132 // will return MIstatus::failure.
134 // Args: vValue - (R) The MI value object.
138 void CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue) {
139 // Clear out the default "<Invalid>" text
140 if (m_bJustConstructed) {
141 m_bJustConstructed = false;
142 m_strValue = vValue.GetString();
147 // Remove already present '[' and ']' from the start and end
148 m_strValue = m_strValue.Trim();
149 size_t len = m_strValue.size();
150 if ((len > 1) && (m_strValue[0] == '[') && (m_strValue[len - 1] == ']'))
151 m_strValue = m_strValue.substr(1, len - 2);
152 const char *pFormat = "[%s,%s]";
153 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(),
154 vValue.GetString().c_str());
158 // Details: Retrieve the contents of *this value object but without the outer
163 // Return: CMIUtilString - Data within the object.
166 CMIUtilString CMICmnMIValueList::ExtractContentNoBrackets() const {
167 CMIUtilString data(m_strValue);
169 if (data[0] == '[') {
170 data = data.substr(1, data.length() - 1);
172 if (data[data.size() - 1] == ']') {
173 data = data.substr(0, data.length() - 1);