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: MICmnMIValueList.h
13 // Overview: CMICmnMIValueList implementation.
15 // Environment: Compilers: Visual C++ 12.
16 // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
17 // Libraries: See MIReadmetxt.
23 #include "MICmnMIValueList.h"
24 #include "MICmnResources.h"
26 //++ ------------------------------------------------------------------------------------
27 // Details: CMICmnMIValueList constructor.
29 // Args: vbValueTypeList - (R) True = yes value type list, false = result type list.
33 CMICmnMIValueList::CMICmnMIValueList( const bool vbValueTypeList )
38 //++ ------------------------------------------------------------------------------------
39 // Details: CMICmnMIValueList constructor.
40 // Construct a results only list.
41 // return MIstatus::failure.
43 // Args: vResult - (R) MI result object.
47 CMICmnMIValueList::CMICmnMIValueList( const CMICmnMIValueResult & vResult )
49 m_strValue = vResult.GetString();
51 m_bJustConstructed = false;
54 //++ ------------------------------------------------------------------------------------
55 // Details: CMICmnMIValueList constructor.
56 // Construct a value only list.
58 // Args: vValue - (R) MI value object.
62 CMICmnMIValueList::CMICmnMIValueList( const CMICmnMIValue & vValue )
64 m_strValue = vValue.GetString();
66 m_bJustConstructed = false;
69 //++ ------------------------------------------------------------------------------------
70 // Details: CMICmnMIValueList destructor.
71 // Type: Overrideable.
76 CMICmnMIValueList::~CMICmnMIValueList( void )
80 //++ ------------------------------------------------------------------------------------
81 // Details: Build the result value's mandatory data part, one tuple
84 // Return: MIstatus::success - Functional succeeded.
85 // MIstatus::failure - Functional failed.
88 bool CMICmnMIValueList::BuildList( void )
90 const MIchar * pFormat = "[%s]";
91 m_strValue = CMIUtilString::Format( pFormat, m_strValue.c_str() );
93 return MIstatus::success;
96 //++ ------------------------------------------------------------------------------------
97 // Details: Add another MI result object to the value list's of list is results.
98 // Only result obejcts can be added to a list of result otherwise this function
99 // will return MIstatus::failure.
101 // Args: vResult - (R) The MI result object.
102 // Return: MIstatus::success - Functional succeeded.
103 // MIstatus::failure - Functional failed.
106 bool CMICmnMIValueList::Add( const CMICmnMIValueResult & vResult )
108 return BuildList( vResult );
111 //++ ------------------------------------------------------------------------------------
112 // Details: Add another MI value object to the value list's of list is values.
113 // Only values objects can be added to a list of values otherwise this function
114 // will return MIstatus::failure.
116 // Args: vValue - (R) The MI value object.
117 // Return: MIstatus::success - Functional succeeded.
118 // MIstatus::failure - Functional failed.
121 bool CMICmnMIValueList::Add( const CMICmnMIValue & vValue )
123 return BuildList( vValue );
126 //++ ------------------------------------------------------------------------------------
127 // Details: Add another MI result object to the value list's of list is results.
128 // Only result obejcts can be added to a list of result otherwise this function
129 // will return MIstatus::failure.
131 // Args: vResult - (R) The MI result object.
132 // Return: MIstatus::success - Functional succeeded.
133 // MIstatus::failure - Functional failed.
136 bool CMICmnMIValueList::BuildList( const CMICmnMIValueResult & vResult )
138 // Clear out the default "<Invalid>" text
139 if( m_bJustConstructed )
141 m_bJustConstructed = false;
142 m_strValue = vResult.GetString();
146 const CMIUtilString data( ExtractContentNoBrackets() );
147 const MIchar * pFormat = "[%s,%s]";
148 m_strValue = CMIUtilString::Format( pFormat, data.c_str(), vResult.GetString().c_str() );
150 return MIstatus::success;
153 //++ ------------------------------------------------------------------------------------
154 // Details: Add another MI value object to the value list's of list is values.
155 // Only values objects can be added to a list of values otherwise this function
156 // will return MIstatus::failure.
158 // Args: vValue - (R) The MI value object.
159 // Return: MIstatus::success - Functional succeeded.
160 // MIstatus::failure - Functional failed.
163 bool CMICmnMIValueList::BuildList( const CMICmnMIValue & vValue )
165 // Clear out the default "<Invalid>" text
166 if( m_bJustConstructed )
168 m_bJustConstructed = false;
169 m_strValue = vValue.GetString();
173 const MIchar * pFormat = "[%s,%s]";
174 m_strValue = m_strValue.FindAndReplace( "[", "" );
175 m_strValue = m_strValue.FindAndReplace( "]", "" );
176 m_strValue = CMIUtilString::Format( pFormat, m_strValue.c_str(), vValue.GetString().c_str() );
178 return MIstatus::success;
181 //++ ------------------------------------------------------------------------------------
182 // Details: Retrieve the contents of *this value object but without the outer most
186 // Return: CMIUtilString - Data within the object.
189 CMIUtilString CMICmnMIValueList::ExtractContentNoBrackets( void ) const
191 CMIUtilString data( m_strValue );
193 if( data[ 0 ] == '[' )
195 data = data.substr( 1, data.length() - 1 );
197 if( data[ data.size() - 1 ] == ']' )
199 data = data.substr( 0, data.length() - 1 );