DCL 3.7.4
Loading...
Searching...
No Matches
XOutputStream.cpp
Go to the documentation of this file.
1#include <dcl/Config.h>
2
3#ifdef __WINNT__
4#include <windows.h> // dcl/Thread.h
5#endif
6
7#include <dcl/XOutputStream.h>
8
9#if __DCL_HAVE_THIS_FILE__
10#undef __THIS_FILE__
11static const char_t __THIS_FILE__[] = __T("dcl/XOutputStream.cpp");
12#endif
13
14__DCL_BEGIN_NAMESPACE
15
17
18String XOutputStream::toString() const
19{
20 StringBuilder r = className() + __T("(");
21 if (__output)
22 r += __output->toString();
23 else
24 r += __T("null");
25 r += __T(")");
26
27 return r;
28}
29
30XOutputStream::XOutputStream(OutputStream* __destroy__ _pOutput)
31{
32 __output = _pOutput;
33}
34
35OutputStream* XOutputStream::setOutputStream(OutputStream* __destroy__ _pOutput)
36{
37 OutputStream* r = __output;
38 __output = _pOutput;
39 return r;
40}
41
42XOutputStream::~XOutputStream()
43{
44 try {
45 close();
46 }
47 catch (Exception* cause) {
48 __DCL_TRACE1(__T("%ls\n"), cause->toString().data());
49 cause->destroy();
50 }
51}
52
53void XOutputStream::close()
55{
56 if (__output) {
57 Thread::SingleLockMutex lockAndUnlock(__lock);
58 Exception* e = NULL;
59 OutputStream* output = __output;
60 __output = NULL;
61 try {
62 output->close();
63 }
64 catch (Exception* cause) {
65 e = cause;
66 }
67 output->destroy();
68
69 if (e) {
70 throw e;
71 }
72 }
73}
74
75void XOutputStream::flush()
77{
78 if (__output) {
79 Thread::SingleLockMutex lockAndUnlock(__lock);
80 __output->flush();
81 }
82}
83
84OutputStream& XOutputStream::write(const void* _buf, size_t _nbytes)
86{
87 if (__output) {
88 Thread::SingleLockMutex lockAndUnlock(__lock);
89 __output->write(_buf, _nbytes);
90 }
91 return *this;
92}
93
94int XOutputStream::vprintf(const char* _format, va_list _arglist)
96{
97 int n = 0;
98 if (__output) {
99 Thread::SingleLockMutex lockAndUnlock(__lock);
100 n = __output->vprintf(_format, _arglist);
101 }
102 return n;
103}
104
105__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:312
#define __destroy__
Definition Config.h:334
wchar_t char_t
Definition Config.h:247
#define __DCL_THROWS1(e)
Definition Config.h:152
IOException *size_t r
Definition MediaInfo.cpp:82
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:399
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:245
#define __T(str)
Definition Object.h:60
virtual String toString() const
Definition Exception.cpp:40
virtual void destroy()
Definition Exception.cpp:74
virtual String toString() const
Definition Object.cpp:187
virtual void destroy()
Definition Object.cpp:192
String className() const
Definition Object.cpp:163
SingleLock< Mutex > SingleLockMutex
Definition Thread.h:411