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 "MICmnMIValueResult.h"
12 #include "MICmnResources.h"
15 const CMIUtilString CMICmnMIValueResult::ms_constStrEqual("=");
17 //++ ------------------------------------------------------------------------------------
18 // Details: CMICmnMIValueResult constructor.
24 CMICmnMIValueResult::CMICmnMIValueResult(void)
25 : m_bEmptyConstruction(true)
29 //++ ------------------------------------------------------------------------------------
30 // Details: CMICmnMIValueResult constructor.
32 // Args: vrVariable - (R) MI value's name.
33 // vrValue - (R) The MI value.
37 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable, const CMICmnMIValue &vrValue)
38 : m_strPartVariable(vrVariable)
39 , m_partMIValue(vrValue)
40 , m_bEmptyConstruction(false)
41 , m_bUseSpacing(false)
46 //++ ------------------------------------------------------------------------------------
47 // Details: CMICmnMIValueResult constructor.
49 // Args: vrVariable - (R) MI value's name.
50 // vrValue - (R) The MI value.
51 // vbUseSpacing - (R) True = put space separators into the string, false = no spaces used.
55 CMICmnMIValueResult::CMICmnMIValueResult(const CMIUtilString &vrVariable, const CMICmnMIValue &vrValue, const bool vbUseSpacing)
56 : m_strPartVariable(vrVariable)
57 , m_partMIValue(vrValue)
58 , m_bEmptyConstruction(false)
59 , m_bUseSpacing(vbUseSpacing)
64 //++ ------------------------------------------------------------------------------------
65 // Details: CMICmnMIValueResult destructor.
66 // Type: Overrideable.
71 CMICmnMIValueResult::~CMICmnMIValueResult(void)
75 //++ ------------------------------------------------------------------------------------
76 // Details: Build the MI value result string.
79 // Return: MIstatus::success - Functional succeeded.
80 // MIstatus::failure - Functional failed.
84 CMICmnMIValueResult::BuildResult(void)
86 const char *pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s";
87 m_strValue = CMIUtilString::Format(pFormat, m_strPartVariable.c_str(), ms_constStrEqual.c_str(), m_partMIValue.GetString().c_str());
89 return MIstatus::success;
92 //++ ------------------------------------------------------------------------------------
93 // Details: Build the MI value result string.
95 // Args: vrVariable - (R) MI value's name.
96 // vrValue - (R) The MI value.
97 // Return: MIstatus::success - Functional succeeded.
98 // MIstatus::failure - Functional failed.
102 CMICmnMIValueResult::BuildResult(const CMIUtilString &vVariable, const CMICmnMIValue &vValue)
104 const char *pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s";
106 CMIUtilString::Format(pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(), vValue.GetString().c_str());
108 return MIstatus::success;
111 //++ ------------------------------------------------------------------------------------
112 // Details: Append another MI value object to *this MI value result.
114 // Args: vrVariable - (R) MI value's name.
115 // vrValue - (R) The MI value.
116 // Return: MIstatus::success - Functional succeeded.
117 // MIstatus::failure - Functional failed.
121 CMICmnMIValueResult::Add(const CMIUtilString &vrVariable, const CMICmnMIValue &vrValue)
123 if (!m_bEmptyConstruction)
124 return BuildResult(vrVariable, vrValue);
127 m_bEmptyConstruction = false;
128 m_strPartVariable = vrVariable;
129 m_partMIValue = vrValue;
130 return BuildResult();