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 #include "MICmnMIValueList.h"
12 #include "MICmnResources.h"
14 //++ ------------------------------------------------------------------------------------
15 // Details: CMICmnMIValueList constructor.
17 // Args: vbValueTypeList - (R) True = yes value type list, false = result type list.
21 CMICmnMIValueList::CMICmnMIValueList(const bool vbValueTypeList)
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueList constructor.
28 // Construct a results only list.
29 // return MIstatus::failure.
31 // Args: vResult - (R) MI result object.
35 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValueResult &vResult)
37 m_strValue = vResult.GetString();
39 m_bJustConstructed = false;
42 //++ ------------------------------------------------------------------------------------
43 // Details: CMICmnMIValueList constructor.
44 // Construct a value only list.
46 // Args: vValue - (R) MI value object.
50 CMICmnMIValueList::CMICmnMIValueList(const CMICmnMIValue &vValue)
52 m_strValue = vValue.GetString();
54 m_bJustConstructed = false;
57 //++ ------------------------------------------------------------------------------------
58 // Details: CMICmnMIValueList destructor.
59 // Type: Overrideable.
64 CMICmnMIValueList::~CMICmnMIValueList(void)
68 //++ ------------------------------------------------------------------------------------
69 // Details: Build the result value's mandatory data part, one tuple
72 // Return: MIstatus::success - Functional succeeded.
73 // MIstatus::failure - Functional failed.
77 CMICmnMIValueList::BuildList(void)
79 const char *pFormat = "[%s]";
80 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str());
82 return MIstatus::success;
85 //++ ------------------------------------------------------------------------------------
86 // Details: Add another MI result object to the value list's of list is results.
87 // Only result objects can be added to a list of result otherwise this function
88 // will return MIstatus::failure.
90 // Args: vResult - (R) The MI result object.
91 // Return: MIstatus::success - Functional succeeded.
92 // MIstatus::failure - Functional failed.
96 CMICmnMIValueList::Add(const CMICmnMIValueResult &vResult)
98 return BuildList(vResult);
101 //++ ------------------------------------------------------------------------------------
102 // Details: Add another MI value object to the value list's of list is values.
103 // Only values objects can be added to a list of values otherwise this function
104 // will return MIstatus::failure.
106 // Args: vValue - (R) The MI value object.
107 // Return: MIstatus::success - Functional succeeded.
108 // MIstatus::failure - Functional failed.
112 CMICmnMIValueList::Add(const CMICmnMIValue &vValue)
114 return BuildList(vValue);
117 //++ ------------------------------------------------------------------------------------
118 // Details: Add another MI result object to the value list's of list is results.
119 // Only result objects can be added to a list of result otherwise this function
120 // will return MIstatus::failure.
122 // Args: vResult - (R) The MI result object.
123 // Return: MIstatus::success - Functional succeeded.
124 // MIstatus::failure - Functional failed.
128 CMICmnMIValueList::BuildList(const CMICmnMIValueResult &vResult)
130 // Clear out the default "<Invalid>" text
131 if (m_bJustConstructed)
133 m_bJustConstructed = false;
134 m_strValue = vResult.GetString();
138 const CMIUtilString data(ExtractContentNoBrackets());
139 const char *pFormat = "[%s,%s]";
140 m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vResult.GetString().c_str());
142 return MIstatus::success;
145 //++ ------------------------------------------------------------------------------------
146 // Details: Add another MI value object to the value list's of list is values.
147 // Only values objects can be added to a list of values otherwise this function
148 // will return MIstatus::failure.
150 // Args: vValue - (R) The MI value object.
151 // Return: MIstatus::success - Functional succeeded.
152 // MIstatus::failure - Functional failed.
156 CMICmnMIValueList::BuildList(const CMICmnMIValue &vValue)
158 // Clear out the default "<Invalid>" text
159 if (m_bJustConstructed)
161 m_bJustConstructed = false;
162 m_strValue = vValue.GetString();
166 // Remove already present '[' and ']' from the start and end
167 m_strValue = m_strValue.Trim();
168 size_t len = m_strValue.size();
169 if ( (len > 1) && (m_strValue[0] == '[') && (m_strValue[len - 1] == ']') )
170 m_strValue = m_strValue.substr(1, len - 2);
171 const char *pFormat = "[%s,%s]";
172 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(), vValue.GetString().c_str());
174 return MIstatus::success;
177 //++ ------------------------------------------------------------------------------------
178 // Details: Retrieve the contents of *this value object but without the outer most
182 // Return: CMIUtilString - Data within the object.
186 CMICmnMIValueList::ExtractContentNoBrackets(void) const
188 CMIUtilString data(m_strValue);
192 data = data.substr(1, data.length() - 1);
194 if (data[data.size() - 1] == ']')
196 data = data.substr(0, data.length() - 1);