1 //===-- OptionValueBoolean.cpp ------------------------------------*- C++ -*-===// 2 // 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 10 #include "lldb/Interpreter/OptionValueBoolean.h" 11 12 // C Includes 13 // C++ Includes 14 // Other libraries and framework includes 15 // Project includes 16 #include "lldb/Core/Stream.h" 17 #include "lldb/Interpreter/Args.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 void 23 OptionValueBoolean::DumpValue (const ExecutionContext *exe_ctx, Stream &strm, uint32_t dump_mask) 24 { 25 if (dump_mask & eDumpOptionType) 26 strm.Printf ("(%s)", GetTypeAsCString ()); 27 // if (dump_mask & eDumpOptionName) 28 // DumpQualifiedName (strm); 29 if (dump_mask & eDumpOptionValue) 30 { 31 if (dump_mask & eDumpOptionType) 32 strm.PutCString (" = "); 33 strm.PutCString (m_current_value ? "true" : "false"); 34 } 35 } 36 37 Error 38 OptionValueBoolean::SetValueFromCString (const char *value_cstr, 39 VarSetOperationType op) 40 { 41 Error error; 42 switch (op) 43 { 44 case eVarSetOperationClear: 45 Clear(); 46 break; 47 48 case eVarSetOperationReplace: 49 case eVarSetOperationAssign: 50 { 51 bool success = false; 52 bool value = Args::StringToBoolean(value_cstr, false, &success); 53 if (success) 54 { 55 m_value_was_set = true; 56 m_current_value = value; 57 } 58 else 59 { 60 if (value_cstr == NULL) 61 error.SetErrorString ("invalid boolean string value: NULL"); 62 else if (value_cstr[0] == '\0') 63 error.SetErrorString ("invalid boolean string value <empty>"); 64 else 65 error.SetErrorStringWithFormat ("invalid boolean string value: '%s'", value_cstr); 66 } 67 } 68 break; 69 70 case eVarSetOperationInsertBefore: 71 case eVarSetOperationInsertAfter: 72 case eVarSetOperationRemove: 73 case eVarSetOperationAppend: 74 case eVarSetOperationInvalid: 75 error = OptionValue::SetValueFromCString (value_cstr, op); 76 break; 77 } 78 return error; 79 } 80 81 lldb::OptionValueSP 82 OptionValueBoolean::DeepCopy () const 83 { 84 return OptionValueSP(new OptionValueBoolean(*this)); 85 } 86 87 88