1 //===-- MICmnMIValueList.cpp ------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 #include "MICmnMIValueList.h"
12 #include "MICmnResources.h"
15 //------------------------------------------------------------------------------------
16 // Details: CMICmnMIValueList constructor.
18 // Args: vbValueTypeList - (R) True = yes value type list, false = result
23 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList) {
28 //------------------------------------------------------------------------------------
29 // Details: CMICmnMIValueList constructor.
30 // Construct a results only list.
31 // return MIstatus::failure.
33 // Args: vResult - (R) MI result object.
37 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult) {
38 m_strValue = vResult.GetString();
40 m_bJustConstructed = false;
44 //------------------------------------------------------------------------------------
45 // Details: CMICmnMIValueList constructor.
46 // Construct a value only list.
48 // Args: vValue - (R) MI value object.
52 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue) {
53 m_strValue = vValue.GetString();
55 m_bJustConstructed = false;
59 //------------------------------------------------------------------------------------
60 // Details: CMICmnMIValueList destructor.
61 // Type: Overrideable.
66 CMICmnMIValueList::~CMICmnMIValueList() {}
69 //------------------------------------------------------------------------------------
70 // Details: Build the result value's mandatory data part, one tuple
76 void CMICmnMIValueList::BuildList() {
77 const char *pFormat = "[%s]";
78 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
82 //------------------------------------------------------------------------------------
83 // Details: Add another MI result object to the value list's of list is
85 // Only result objects can be added to a list of result otherwise this
87 // will return MIstatus::failure.
89 // Args: vResult - (R) The MI result object.
93 void CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult) {
98 //------------------------------------------------------------------------------------
99 // Details: Add another MI value object to the value list's of list is values.
100 // Only values objects can be added to a list of values otherwise this
102 // will return MIstatus::failure.
104 // Args: vValue - (R) The MI value object.
108 void CMICmnMIValueList::Add(const CMICmnMIValue &vValue) { BuildList(vValue); }
111 //------------------------------------------------------------------------------------
112 // Details: Add another MI result object to the value list's of list is
114 // Only result objects can be added to a list of result otherwise this
116 // will return MIstatus::failure.
118 // Args: vResult - (R) The MI result object.
122 void CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult) {
123 // Clear out the default "<Invalid>" text
124 if (m_bJustConstructed) {
125 m_bJustConstructed = false;
126 m_strValue = vResult.GetString();
131 const CMIUtilString data(ExtractContentNoBrackets());
132 const char *pFormat = "[%s,%s]";
134 CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
138 //------------------------------------------------------------------------------------
139 // Details: Add another MI value object to the value list's of list is values.
140 // Only values objects can be added to a list of values otherwise this
142 // will return MIstatus::failure.
144 // Args: vValue - (R) The MI value object.
148 void CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue) {
149 // Clear out the default "<Invalid>" text
150 if (m_bJustConstructed) {
151 m_bJustConstructed = false;
152 m_strValue = vValue.GetString();
157 // Remove already present '[' and ']' from the start and end
158 m_strValue = m_strValue.Trim();
159 size_t len = m_strValue.size();
160 if ((len > 1) && (m_strValue[0] == '[') && (m_strValue[len - 1] == ']'))
161 m_strValue = m_strValue.substr(1, len - 2);
162 const char *pFormat = "[%s,%s]";
163 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(),
164 vValue.GetString().c_str());
168 //------------------------------------------------------------------------------------
169 // Details: Retrieve the contents of *this value object but without the outer
174 // Return: CMIUtilString - Data within the object.
177 CMIUtilString CMICmnMIValueList::ExtractContentNoBrackets() const {
178 CMIUtilString data(m_strValue);
180 if (data[0] == '[') {
181 data = data.substr(1, data.length() - 1);
183 if (data[data.size() - 1] == ']') {
184 data = data.substr(0, data.length() - 1);