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 // File: MICmnMIResult.h
13 // Overview: CMICmnMIValueResult implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmnMIValueResult.h"
24 #include "MICmnResources.h"
27 const CMIUtilString CMICmnMIValueResult::ms_constStrEqual( "=" );
29 //++ ------------------------------------------------------------------------------------
30 // Details: CMICmnMIValueResult constructor.
36 CMICmnMIValueResult::CMICmnMIValueResult( void )
37 : m_bEmptyConstruction( true )
41 //++ ------------------------------------------------------------------------------------
42 // Details: CMICmnMIValueResult constructor.
44 // Args: vrVariable - (R) MI value's name.
45 // vrValue - (R) The MI value.
49 CMICmnMIValueResult::CMICmnMIValueResult( const CMIUtilString & vrVariable, const CMICmnMIValue & vrValue )
50 : m_strPartVariable( vrVariable )
51 , m_partMIValue( vrValue )
52 , m_bEmptyConstruction( false )
53 , m_bUseSpacing( false )
58 //++ ------------------------------------------------------------------------------------
59 // Details: CMICmnMIValueResult constructor.
61 // Args: vrVariable - (R) MI value's name.
62 // vrValue - (R) The MI value.
63 // vbUseSpacing - (R) True = put space seperators into the string, false = no spaces used.
67 CMICmnMIValueResult::CMICmnMIValueResult( const CMIUtilString & vrVariable, const CMICmnMIValue & vrValue, const bool vbUseSpacing )
68 : m_strPartVariable( vrVariable )
69 , m_partMIValue( vrValue )
70 , m_bEmptyConstruction( false )
71 , m_bUseSpacing( vbUseSpacing )
76 //++ ------------------------------------------------------------------------------------
77 // Details: CMICmnMIValueResult destructor.
78 // Type: Overrideable.
83 CMICmnMIValueResult::~CMICmnMIValueResult( void )
87 //++ ------------------------------------------------------------------------------------
88 // Details: Build the MI value result string.
91 // Return: MIstatus::success - Functional succeeded.
92 // MIstatus::failure - Functional failed.
95 bool CMICmnMIValueResult::BuildResult( void )
97 const MIchar * pFormat = m_bUseSpacing ? "%s %s %s" : "%s%s%s";
98 m_strValue = CMIUtilString::Format( pFormat, m_strPartVariable.c_str(), ms_constStrEqual.c_str(), m_partMIValue.GetString().c_str() );
100 return MIstatus::success;
103 //++ ------------------------------------------------------------------------------------
104 // Details: Build the MI value result string.
106 // Args: vrVariable - (R) MI value's name.
107 // vrValue - (R) The MI value.
108 // Return: MIstatus::success - Functional succeeded.
109 // MIstatus::failure - Functional failed.
112 bool CMICmnMIValueResult::BuildResult( const CMIUtilString & vVariable, const CMICmnMIValue & vValue )
114 const MIchar * pFormat = m_bUseSpacing ? "%s, %s %s %s" : "%s,%s%s%s";
115 m_strValue = CMIUtilString::Format( pFormat, m_strValue.c_str(), vVariable.c_str(), ms_constStrEqual.c_str(), vValue.GetString().c_str() );
117 return MIstatus::success;
120 //++ ------------------------------------------------------------------------------------
121 // Details: Append another MI value object to *this MI value result.
123 // Args: vrVariable - (R) MI value's name.
124 // vrValue - (R) The MI value.
125 // Return: MIstatus::success - Functional succeeded.
126 // MIstatus::failure - Functional failed.
129 bool CMICmnMIValueResult::Add( const CMIUtilString & vrVariable, const CMICmnMIValue & vrValue )
131 if( !m_bEmptyConstruction )
132 return BuildResult( vrVariable, vrValue );
135 m_bEmptyConstruction = false;
136 m_strPartVariable = vrVariable;
137 m_partMIValue = vrValue;
138 return BuildResult();