1 //===-- MICmnMIValueTuple.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"
14 //------------------------------------------------------------------------------------
15 // Details: CMICmnMIValueTuple constructor.
21 CMICmnMIValueTuple::CMICmnMIValueTuple() : 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) {
35 m_strValue = vResult.GetString();
37 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,
46 // false = no spaces used.
50 CMICmnMIValueTuple::CMICmnMIValueTuple(const CMICmnMIValueResult &vResult,
51 const bool vbUseSpacing)
52 : m_bSpaceAfterComma(vbUseSpacing) {
53 m_strValue = vResult.GetString();
55 m_bJustConstructed = false;
59 //------------------------------------------------------------------------------------
60 // Details: CMICmnMIValueTuple destructor.
61 // Type: Overrideable.
66 CMICmnMIValueTuple::~CMICmnMIValueTuple() {}
69 //------------------------------------------------------------------------------------
70 // Details: Build the result value's mandatory data part, one tuple
76 void CMICmnMIValueTuple::BuildTuple() {
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's list of tuples.
85 // Args: vResult - (R) The MI result object.
89 void CMICmnMIValueTuple::BuildTuple(const CMICmnMIValueResult &vResult) {
90 // Clear out the default "<Invalid>" text
91 if (m_bJustConstructed) {
92 m_bJustConstructed = false;
93 m_strValue = vResult.GetString();
98 if (m_strValue[0] == '{') {
99 m_strValue = m_strValue.substr(1, m_strValue.size() - 1);
101 if (m_strValue[m_strValue.size() - 1] == '}') {
102 m_strValue = m_strValue.substr(0, m_strValue.size() - 1);
105 const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
106 m_strValue = CMIUtilString::Format(pFormat, m_strValue.c_str(),
107 vResult.GetString().c_str());
111 //------------------------------------------------------------------------------------
112 // Details: Add string value to the value's list of tuples.
114 // Args: vValue - (R) The string object.
118 void CMICmnMIValueTuple::BuildTuple(const CMIUtilString &vValue) {
119 // Clear out the default "<Invalid>" text
120 if (m_bJustConstructed) {
121 m_bJustConstructed = false;
127 const CMIUtilString data(ExtractContentNoBrackets());
128 const char *pFormat = m_bSpaceAfterComma ? "{%s, %s}" : "{%s,%s}";
129 m_strValue = CMIUtilString::Format(pFormat, data.c_str(), vValue.c_str());
133 //------------------------------------------------------------------------------------
134 // Details: Add another MI value object to the value list's of list is values.
135 // Only values objects can be added to a list of values otherwise this
137 // will return MIstatus::failure.
139 // Args: vValue - (R) The MI value object.
143 void CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult) {
148 //------------------------------------------------------------------------------------
149 // Details: Add another MI value object to the value list's of list is values.
150 // Only values objects can be added to a list of values otherwise this
152 // will return MIstatus::failure.
154 // Args: vValue - (R) The MI value object.
155 // vbUseSpacing - (R) True = put space separators into the string,
156 // false = no spaces used.
160 void CMICmnMIValueTuple::Add(const CMICmnMIValueResult &vResult,
161 const bool vbUseSpacing) {
162 m_bSpaceAfterComma = vbUseSpacing;
167 //------------------------------------------------------------------------------------
168 // Details: Add another MI value object to the value list's of list is values.
169 // Only values objects can be added to a list of values otherwise this
171 // will return MIstatus::failure.
173 // Args: vValue - (R) The MI value object.
174 // vbUseSpacing - (R) True = put space separators into the string,
175 // false = no spaces used.
179 void CMICmnMIValueTuple::Add(const CMICmnMIValueConst &vValue,
180 const bool vbUseSpacing) {
181 m_bSpaceAfterComma = vbUseSpacing;
182 BuildTuple(vValue.GetString());
186 //------------------------------------------------------------------------------------
187 // Details: Retrieve the contents of *this value object but without the outer
192 // Return: CMIUtilString - Data within the object.
195 CMIUtilString CMICmnMIValueTuple::ExtractContentNoBrackets() const {
196 CMIUtilString data(m_strValue);
198 if (data[0] == '{') {
199 data = data.substr(1, data.length() - 1);
201 if (data[data.size() - 1] == '}') {
202 data = data.substr(0, data.length() - 1);