1 //===-- MICmnMIValueResult.cpp ----------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 #include "MICmnMIValueResult.h"
11 #include "MICmnResources.h"
14 const CMIUtilString CMICmnMIValueResult::ms_constStrEqual("=");
17 // Details: CMICmnMIValueResult constructor.
23 CMICmnMIValueResult::CMICmnMIValueResult() : m_bEmptyConstruction(true) {}
26 // Details: CMICmnMIValueResult constructor.
28 // Args: vrVariable - (R) MI value's name.
29 // vrValue - (R) The MI value.
33 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
34 const CMICmnMIValue &vrValue)
35 : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
36 m_bEmptyConstruction(false), m_bUseSpacing(false) {
41 // Details: CMICmnMIValueResult constructor.
43 // Args: vrVariable - (R) MI value's name.
44 // vrValue - (R) The MI value.
45 // vbUseSpacing - (R) True = put space separators into the string,
46 // false = no spaces used.
50 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
51 const CMICmnMIValue &vrValue,
52 const bool vbUseSpacing)
53 : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
54 m_bEmptyConstruction(false), m_bUseSpacing(vbUseSpacing) {
59 // Details: CMICmnMIValueResult destructor.
60 // Type: Overrideable.
65 CMICmnMIValueResult::~CMICmnMIValueResult() {}
68 // Details: Build the MI value result string.
74 void CMICmnMIValueResult::BuildResult() {
75 const char *pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s";
76 m_strValue = CMIUtilString::Format(pFormat, m_strPartVariable.c_str(),
77 ms_constStrEqual.c_str(),
78 m_partMIValue.GetString().c_str());
82 // Details: Build the MI value result string.
84 // Args: vrVariable - (R) MI value's name.
85 // vrValue - (R) The MI value.
89 void CMICmnMIValueResult::BuildResult(const CMIUtilString &vVariable,
90 const CMICmnMIValue &vValue) {
91 const char *pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s";
92 m_strValue = CMIUtilString::Format(
93 pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(),
94 vValue.GetString().c_str());
98 // Details: Append another MI value object to *this MI value result.
100 // Args: vrVariable - (R) MI value's name.
101 // vrValue - (R) The MI value.
102 // Return: MIstatus::success - Functional succeeded.
103 // MIstatus::failure - Functional failed.
106 void CMICmnMIValueResult::Add(const CMIUtilString &vrVariable,
107 const CMICmnMIValue &vrValue) {
108 if (!m_bEmptyConstruction)
109 BuildResult(vrVariable, vrValue);
111 m_bEmptyConstruction = false;
112 m_strPartVariable = vrVariable;
113 m_partMIValue = vrValue;