Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame^] | 1 | //===-- SBCommandReturnObject.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/CommandReturnObject.h" |
| 11 | |
| 12 | #include "SBCommandReturnObject.h" |
| 13 | |
| 14 | using namespace lldb; |
| 15 | |
| 16 | SBCommandReturnObject::SBCommandReturnObject () : |
| 17 | m_return_object_ap (new lldb_private::CommandReturnObject ()) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | SBCommandReturnObject::~SBCommandReturnObject () |
| 22 | { |
| 23 | // m_return_object_ap will automatically delete any pointer it owns |
| 24 | } |
| 25 | |
| 26 | bool |
| 27 | SBCommandReturnObject::IsValid() const |
| 28 | { |
| 29 | return m_return_object_ap.get() != NULL; |
| 30 | } |
| 31 | |
| 32 | |
| 33 | const char * |
| 34 | SBCommandReturnObject::GetOutput () |
| 35 | { |
| 36 | if (m_return_object_ap.get()) |
| 37 | return m_return_object_ap->GetOutputStream().GetData(); |
| 38 | return NULL; |
| 39 | } |
| 40 | |
| 41 | const char * |
| 42 | SBCommandReturnObject::GetError () |
| 43 | { |
| 44 | if (m_return_object_ap.get()) |
| 45 | return m_return_object_ap->GetErrorStream().GetData(); |
| 46 | return NULL; |
| 47 | } |
| 48 | |
| 49 | size_t |
| 50 | SBCommandReturnObject::GetOutputSize () |
| 51 | { |
| 52 | if (m_return_object_ap.get()) |
| 53 | return m_return_object_ap->GetOutputStream().GetSize(); |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | size_t |
| 58 | SBCommandReturnObject::GetErrorSize () |
| 59 | { |
| 60 | if (m_return_object_ap.get()) |
| 61 | return m_return_object_ap->GetErrorStream().GetSize(); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | size_t |
| 66 | SBCommandReturnObject::PutOutput (FILE *fh) |
| 67 | { |
| 68 | if (fh) |
| 69 | { |
| 70 | size_t num_bytes = GetOutputSize (); |
| 71 | if (num_bytes) |
| 72 | return ::fprintf (fh, "%s", GetOutput()); |
| 73 | } |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | size_t |
| 78 | SBCommandReturnObject::PutError (FILE *fh) |
| 79 | { |
| 80 | if (fh) |
| 81 | { |
| 82 | size_t num_bytes = GetErrorSize (); |
| 83 | if (num_bytes) |
| 84 | return ::fprintf (fh, "%s", GetError()); |
| 85 | } |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | void |
| 90 | SBCommandReturnObject::Clear() |
| 91 | { |
| 92 | if (m_return_object_ap.get()) |
| 93 | m_return_object_ap->Clear(); |
| 94 | } |
| 95 | |
| 96 | lldb::ReturnStatus |
| 97 | SBCommandReturnObject::GetStatus() |
| 98 | { |
| 99 | if (m_return_object_ap.get()) |
| 100 | return m_return_object_ap->GetStatus(); |
| 101 | return lldb::eReturnStatusInvalid; |
| 102 | } |
| 103 | |
| 104 | bool |
| 105 | SBCommandReturnObject::Succeeded () |
| 106 | { |
| 107 | if (m_return_object_ap.get()) |
| 108 | return m_return_object_ap->Succeeded(); |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | bool |
| 113 | SBCommandReturnObject::HasResult () |
| 114 | { |
| 115 | if (m_return_object_ap.get()) |
| 116 | return m_return_object_ap->HasResult(); |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | SBCommandReturnObject::AppendMessage (const char *message) |
| 122 | { |
| 123 | if (m_return_object_ap.get()) |
| 124 | m_return_object_ap->AppendMessage (message); |
| 125 | } |
| 126 | |
| 127 | lldb_private::CommandReturnObject * |
| 128 | SBCommandReturnObject::GetLLDBObjectPtr() |
| 129 | { |
| 130 | return m_return_object_ap.get(); |
| 131 | } |
| 132 | |
| 133 | |
| 134 | lldb_private::CommandReturnObject & |
| 135 | SBCommandReturnObject::GetLLDBObjectRef() |
| 136 | { |
| 137 | assert(m_return_object_ap.get()); |
| 138 | return *(m_return_object_ap.get()); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void |
| 143 | SBCommandReturnObject::SetLLDBObjectPtr (lldb_private::CommandReturnObject *ptr) |
| 144 | { |
| 145 | if (m_return_object_ap.get()) |
| 146 | m_return_object_ap.reset (ptr); |
| 147 | } |
| 148 | |