blob: efbf0ddbbfb1a794e17671dbd93af6e0b85ead85 [file] [log] [blame]
Bruce Mitchener39e88232015-07-21 13:09:39 +00001//===-- MICmnMIValueResult.cpp ----------------------------------*- C++ -*-===//
Deepak Panickal6f9c4682014-05-16 10:51:01 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Deepak Panickal6f9c4682014-05-16 10:51:01 +000010// In-house headers:
11#include "MICmnMIValueResult.h"
12#include "MICmnResources.h"
13
14// Instantiations:
Zachary Turner1d6af022014-11-17 18:06:21 +000015const CMIUtilString CMICmnMIValueResult::ms_constStrEqual("=");
Deepak Panickal6f9c4682014-05-16 10:51:01 +000016
Kate Stoneb9c1b512016-09-06 20:57:50 +000017//++
18//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000019// Details: CMICmnMIValueResult constructor.
20// Type: Method.
21// Args: None.
22// Return: None.
23// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000024//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000025CMICmnMIValueResult::CMICmnMIValueResult() : m_bEmptyConstruction(true) {}
Deepak Panickal6f9c4682014-05-16 10:51:01 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027//++
28//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000029// Details: CMICmnMIValueResult constructor.
30// Type: Method.
31// Args: vrVariable - (R) MI value's name.
32// vrValue - (R) The MI value.
33// Return: None.
34// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000035//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000036CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
37 const CMICmnMIValue &vrValue)
38 : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
39 m_bEmptyConstruction(false), m_bUseSpacing(false) {
40 BuildResult();
Deepak Panickal6f9c4682014-05-16 10:51:01 +000041}
42
Kate Stoneb9c1b512016-09-06 20:57:50 +000043//++
44//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000045// Details: CMICmnMIValueResult constructor.
46// Type: Method.
47// Args: vrVariable - (R) MI value's name.
48// vrValue - (R) The MI value.
Kate Stoneb9c1b512016-09-06 20:57:50 +000049// vbUseSpacing - (R) True = put space separators into the string,
50// false = no spaces used.
Zachary Turner1d6af022014-11-17 18:06:21 +000051// Return: None.
52// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000053//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000054CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable,
55 const CMICmnMIValue &vrValue,
56 const bool vbUseSpacing)
57 : m_strPartVariable(vrVariable), m_partMIValue(vrValue),
58 m_bEmptyConstruction(false), m_bUseSpacing(vbUseSpacing) {
59 BuildResult();
Deepak Panickal6f9c4682014-05-16 10:51:01 +000060}
61
Kate Stoneb9c1b512016-09-06 20:57:50 +000062//++
63//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000064// Details: CMICmnMIValueResult destructor.
65// Type: Overrideable.
66// Args: None.
67// Return: None.
68// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000069//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000070CMICmnMIValueResult::~CMICmnMIValueResult() {}
Deepak Panickal6f9c4682014-05-16 10:51:01 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072//++
73//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000074// Details: Build the MI value result string.
75// Type: Method.
76// Args: None.
Bruce Mitchener2c674d32015-07-22 17:07:27 +000077// Return: None.
Zachary Turner1d6af022014-11-17 18:06:21 +000078// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000079//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000080void CMICmnMIValueResult::BuildResult() {
81 const char *pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s";
82 m_strValue = CMIUtilString::Format(pFormat, m_strPartVariable.c_str(),
83 ms_constStrEqual.c_str(),
84 m_partMIValue.GetString().c_str());
Deepak Panickal6f9c4682014-05-16 10:51:01 +000085}
86
Kate Stoneb9c1b512016-09-06 20:57:50 +000087//++
88//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +000089// Details: Build the MI value result string.
90// Type: Method.
91// Args: vrVariable - (R) MI value's name.
92// vrValue - (R) The MI value.
Bruce Mitchener2c674d32015-07-22 17:07:27 +000093// Return: None.
Zachary Turner1d6af022014-11-17 18:06:21 +000094// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +000095//--
Kate Stoneb9c1b512016-09-06 20:57:50 +000096void CMICmnMIValueResult::BuildResult(const CMIUtilString &vVariable,
97 const CMICmnMIValue &vValue) {
98 const char *pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s";
99 m_strValue = CMIUtilString::Format(
100 pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(),
101 vValue.GetString().c_str());
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000102}
103
Kate Stoneb9c1b512016-09-06 20:57:50 +0000104//++
105//------------------------------------------------------------------------------------
Zachary Turner1d6af022014-11-17 18:06:21 +0000106// Details: Append another MI value object to *this MI value result.
107// Type: Method.
108// Args: vrVariable - (R) MI value's name.
109// vrValue - (R) The MI value.
110// Return: MIstatus::success - Functional succeeded.
111// MIstatus::failure - Functional failed.
112// Throws: None.
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000113//--
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114void CMICmnMIValueResult::Add(const CMIUtilString &vrVariable,
115 const CMICmnMIValue &vrValue) {
116 if (!m_bEmptyConstruction)
117 BuildResult(vrVariable, vrValue);
118 else {
119 m_bEmptyConstruction = false;
120 m_strPartVariable = vrVariable;
121 m_partMIValue = vrValue;
122 BuildResult();
123 }
Deepak Panickal6f9c4682014-05-16 10:51:01 +0000124}