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 "MICmnMIValueTuple.h"
13 //++ ------------------------------------------------------------------------------------
14 // Details: CMICmnMIValueTuple constructor.
20 CMICmnMIValueTuple::CMICmnMIValueTuple(void)
21 : m_bSpaceAfterComma(false)
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueTuple constructor.
29 // Args: vResult - (R) MI result object.
33 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult)
34 : m_bSpaceAfterComma(false)
36 m_strValue = vResult.GetString();
38 m_bJustConstructed = false;
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmnMIValueTuple constructor.
44 // Args: vResult - (R) MI result object.
45 // vbUseSpacing - (R) True = put space separators into the string, false = no spaces used.
49 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult, const bool vbUseSpacing)
50 : m_bSpaceAfterComma(vbUseSpacing)
52 m_strValue = vResult.GetString();
54 m_bJustConstructed = false;
57 //++ ------------------------------------------------------------------------------------
58 // Details: CMICmnMIValueTuple destructor.
59 // Type: Overrideable.
64 CMICmnMIValueTuple::~CMICmnMIValueTuple(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 CMICmnMIValueTuple::BuildTuple(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's list of tuples.
88 // Args: vResult - (R) The MI result object.
89 // Return: MIstatus::success - Functional succeeded.
90 // MIstatus::failure - Functional failed.
94 CMICmnMIValueTuple::BuildTuple(const CMICmnMIValueResult &vResult)
96 // Clear out the default "<Invalid>" text
97 if (m_bJustConstructed)
99 m_bJustConstructed = false;
100 m_strValue = vResult.GetString();
104 if (m_strValue[0] == '{')
106 m_strValue = m_strValue.substr(1, m_strValue.size() - 1);
108 if (m_strValue[m_strValue.size() - 1] == '}')
110 m_strValue = m_strValue.substr(0, m_strValue.size() - 1);
113 const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
114 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(), vResult.GetString().c_str());
116 return MIstatus::success;
119 //++ ------------------------------------------------------------------------------------
120 // Details: Add string value to the value's list of tuples.
122 // Args: vValue - (R) The string object.
123 // Return: MIstatus::success - Functional succeeded.
124 // MIstatus::failure - Functional failed.
128 CMICmnMIValueTuple::BuildTuple(const CMIUtilString &vValue)
130 // Clear out the default "<Invalid>" text
131 if (m_bJustConstructed)
133 m_bJustConstructed = false;
138 const CMIUtilString data(ExtractContentNoBrackets());
139 const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
140 m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vValue.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 CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult)
158 return BuildTuple(vResult);
161 //++ ------------------------------------------------------------------------------------
162 // Details: Add another MI value object to the value list's of list is values.
163 // Only values objects can be added to a list of values otherwise this function
164 // will return MIstatus::failure.
166 // Args: vValue - (R) The MI value object.
167 // vbUseSpacing - (R) True = put space separators into the string, false = no spaces used.
168 // Return: MIstatus::success - Functional succeeded.
169 // MIstatus::failure - Functional failed.
173 CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult, const bool vbUseSpacing)
175 m_bSpaceAfterComma = vbUseSpacing;
176 return BuildTuple(vResult);
179 //++ ------------------------------------------------------------------------------------
180 // Details: Add another MI value object to the value list's of list is values.
181 // Only values objects can be added to a list of values otherwise this function
182 // will return MIstatus::failure.
184 // Args: vValue - (R) The MI value object.
185 // vbUseSpacing - (R) True = put space separators into the string, false = no spaces used.
186 // Return: MIstatus::success - Functional succeeded.
187 // MIstatus::failure - Functional failed.
191 CMICmnMIValueTuple::Add(const CMICmnMIValueConst &vValue, const bool vbUseSpacing)
193 m_bSpaceAfterComma = vbUseSpacing;
194 return BuildTuple(vValue.GetString());
197 //++ ------------------------------------------------------------------------------------
198 // Details: Retrieve the contents of *this value object but without the outer most
202 // Return: CMIUtilString - Data within the object.
206 CMICmnMIValueTuple::ExtractContentNoBrackets(void) const
208 CMIUtilString data(m_strValue);
212 data = data.substr(1, data.length() - 1);
214 if (data[data.size() - 1] == '}')
216 data = data.substr(0, data.length() - 1);