summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBCommandReturnObject.cpp
blob: 3910cc4b03d2fac1379e2b7a383355fbb9a527b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//===-- SBCommandReturnObject.cpp -------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Interpreter/CommandReturnObject.h"

#include "SBCommandReturnObject.h"

using namespace lldb;

SBCommandReturnObject::SBCommandReturnObject () :
    m_return_object_ap (new lldb_private::CommandReturnObject ())
{
}

SBCommandReturnObject::~SBCommandReturnObject ()
{
    // m_return_object_ap will automatically delete any pointer it owns
}

bool
SBCommandReturnObject::IsValid() const
{
    return m_return_object_ap.get() != NULL;
}


const char *
SBCommandReturnObject::GetOutput ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->GetOutputStream().GetData();
    return NULL;
}

const char *
SBCommandReturnObject::GetError ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->GetErrorStream().GetData();
    return NULL;
}

size_t
SBCommandReturnObject::GetOutputSize ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->GetOutputStream().GetSize();
    return 0;
}

size_t
SBCommandReturnObject::GetErrorSize ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->GetErrorStream().GetSize();
    return 0;
}

size_t
SBCommandReturnObject::PutOutput (FILE *fh)
{
    if (fh)
    {
        size_t num_bytes = GetOutputSize ();
        if (num_bytes)
            return ::fprintf (fh, "%s", GetOutput());
    }
    return 0;
}

size_t
SBCommandReturnObject::PutError (FILE *fh)
{
    if (fh)
    {
        size_t num_bytes = GetErrorSize ();
        if (num_bytes)
            return ::fprintf (fh, "%s", GetError());
    }
    return 0;
}

void
SBCommandReturnObject::Clear()
{
    if (m_return_object_ap.get())
        m_return_object_ap->Clear();
}

lldb::ReturnStatus
SBCommandReturnObject::GetStatus()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->GetStatus();
    return lldb::eReturnStatusInvalid;
}

bool
SBCommandReturnObject::Succeeded ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->Succeeded();
    return false;
}

bool
SBCommandReturnObject::HasResult ()
{
    if (m_return_object_ap.get())
        return m_return_object_ap->HasResult();
    return false;
}

void
SBCommandReturnObject::AppendMessage (const char *message)
{
    if (m_return_object_ap.get())
        m_return_object_ap->AppendMessage (message);
}

lldb_private::CommandReturnObject *
SBCommandReturnObject::GetLLDBObjectPtr()
{
    return m_return_object_ap.get();
}


lldb_private::CommandReturnObject &
SBCommandReturnObject::GetLLDBObjectRef()
{
    assert(m_return_object_ap.get());
    return *(m_return_object_ap.get());
}


void
SBCommandReturnObject::SetLLDBObjectPtr (lldb_private::CommandReturnObject *ptr)
{
    if (m_return_object_ap.get())
        m_return_object_ap.reset (ptr);
}

OpenPOWER on IntegriCloud