1 //===-- Platform.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 // File: MICmnMIValueList.h
13 // Overview: CMICmnMIValueList implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmnMIValueList.h"
24 #include "MICmnResources.h"
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueList constructor.
29 // Args: vbValueTypeList - (R) True = yes value type list, false = result type list.
33 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList)
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmnMIValueList constructor.
40 // Construct a results only list.
41 // return MIstatus::failure.
43 // Args: vResult - (R) MI result object.
47 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult)
49 m_strValue = vResult.GetString();
51 m_bJustConstructed = false;
54 //++ ------------------------------------------------------------------------------------
55 // Details: CMICmnMIValueList constructor.
56 // Construct a value only list.
58 // Args: vValue - (R) MI value object.
62 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue)
64 m_strValue = vValue.GetString();
66 m_bJustConstructed = false;
69 //++ ------------------------------------------------------------------------------------
70 // Details: CMICmnMIValueList destructor.
71 // Type: Overrideable.
76 CMICmnMIValueList::~CMICmnMIValueList(void)
80 //++ ------------------------------------------------------------------------------------
81 // Details: Build the result value's mandatory data part, one tuple
84 // Return: MIstatus::success - Functional succeeded.
85 // MIstatus::failure - Functional failed.
89 CMICmnMIValueList::BuildList(void)
91 const MIchar *pFormat = "[%s]";
92 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
94 return MIstatus::success;
97 //++ ------------------------------------------------------------------------------------
98 // Details: Add another MI result object to the value list's of list is results.
99 // Only result obejcts can be added to a list of result otherwise this function
100 // will return MIstatus::failure.
102 // Args: vResult - (R) The MI result object.
103 // Return: MIstatus::success - Functional succeeded.
104 // MIstatus::failure - Functional failed.
108 CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult)
110 return BuildList(vResult);
113 //++ ------------------------------------------------------------------------------------
114 // Details: Add another MI value object to the value list's of list is values.
115 // Only values objects can be added to a list of values otherwise this function
116 // will return MIstatus::failure.
118 // Args: vValue - (R) The MI value object.
119 // Return: MIstatus::success - Functional succeeded.
120 // MIstatus::failure - Functional failed.
124 CMICmnMIValueList::Add(const CMICmnMIValue &vValue)
126 return BuildList(vValue);
129 //++ ------------------------------------------------------------------------------------
130 // Details: Add another MI result object to the value list's of list is results.
131 // Only result obejcts can be added to a list of result otherwise this function
132 // will return MIstatus::failure.
134 // Args: vResult - (R) The MI result object.
135 // Return: MIstatus::success - Functional succeeded.
136 // MIstatus::failure - Functional failed.
140 CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult)
142 // Clear out the default "<Invalid>" text
143 if (m_bJustConstructed)
145 m_bJustConstructed = false;
146 m_strValue = vResult.GetString();
150 const CMIUtilString data(ExtractContentNoBrackets());
151 const MIchar *pFormat = "[%s,%s]";
152 m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
154 return MIstatus::success;
157 //++ ------------------------------------------------------------------------------------
158 // Details: Add another MI value object to the value list's of list is values.
159 // Only values objects can be added to a list of values otherwise this function
160 // will return MIstatus::failure.
162 // Args: vValue - (R) The MI value object.
163 // Return: MIstatus::success - Functional succeeded.
164 // MIstatus::failure - Functional failed.
168 CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue)
170 // Clear out the default "<Invalid>" text
171 if (m_bJustConstructed)
173 m_bJustConstructed = false;
174 m_strValue = vValue.GetString();
178 const MIchar *pFormat = "[%s,%s]";
179 m_strValue = m_strValue.FindAndReplace("[", "");
180 m_strValue = m_strValue.FindAndReplace("]", "");
181 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(), vValue.GetString().c_str());
183 return MIstatus::success;
186 //++ ------------------------------------------------------------------------------------
187 // Details: Retrieve the contents of *this value object but without the outer most
191 // Return: CMIUtilString - Data within the object.
195 CMICmnMIValueList::ExtractContentNoBrackets(void) const
197 CMIUtilString data(m_strValue);
201 data = data.substr(1, data.length() - 1);
203 if (data[data.size() - 1] == ']')
205 data = data.substr(0, data.length() - 1);