DCL 4.0
Loading...
Searching...
No Matches
XOutputStream.cpp
Go to the documentation of this file.
1
2#include <dcl/Config.h>
3
4#if __DCL_WINDOWS
5#include <windows.h> // for dcl/Thread.h
6#endif
7
8#include <dcl/XOutputStream.h>
9
10#undef __THIS_FILE__
11static const char_t __THIS_FILE__[] = __T("dcl/FileOutputStream.cpp");
12
13__DCL_BEGIN_NAMESPACE
14
16
17String XOutputStream::toString() const
18{
19 StringBuilder r = className() + __T("(");
20 if (__output)
21 r += __output->toString();
22 else
23 r += __T("null");
24 r += __T(")");
25
26 return r;
27}
28
29XOutputStream::XOutputStream(OutputStream* __destroy__ _pOutput)
30{
31 __output = _pOutput;
32}
33
34OutputStream* XOutputStream::setOutputStream(OutputStream* __destroy__ _pOutput)
35{
36 OutputStream* r = __output;
37 __output = _pOutput;
38 return r;
39}
40
41XOutputStream::~XOutputStream()
42{
43 try
44 {
45 close();
46 }
47 catch (Exception* cause)
48 {
49 __DCL_TRACE1(__T("%ls\n"), cause->toString().data());
50 cause->destroy();
51 }
52}
53
54void XOutputStream::close()
56{
57 if (__output)
58 {
59 Thread::SingleLockMutex lockAndUnlock(__lock);
60 Exception* e = NULL;
61 OutputStream* output = __output;
62 __output = NULL;
63 try
64 {
65 output->close();
66 }
67 catch (Exception* cause)
68 {
69 e = cause;
70 }
71 output->destroy();
72
73 if (e)
74 throw e;
75 }
76}
77
78void XOutputStream::flush()
80{
81 if (__output)
82 {
83 Thread::SingleLockMutex lockAndUnlock(__lock);
84 __output->flush();
85 }
86}
87
88OutputStream& XOutputStream::write(const void* _buf, size_t _nbytes)
90{
91 if (__output)
92 {
93 Thread::SingleLockMutex lockAndUnlock(__lock);
94 __output->write(_buf, _nbytes);
95 }
96 return *this;
97}
98
99int XOutputStream::vprintf(const char* _format, va_list _arglist)
101{
102 int n = 0;
103 if (__output)
104 {
105 Thread::SingleLockMutex lockAndUnlock(__lock);
106 n = __output->vprintf(_format, _arglist);
107 }
108 return n;
109}
110
111__DCL_END_NAMESPACE
#define __THIS_FILE__
Definition _trace.h:14
#define NULL
Definition Config.h:340
#define __destroy__
Definition Config.h:363
wchar_t char_t
Definition Config.h:275
#define __DCL_THROWS1(e)
Definition Config.h:167
#define __DCL_TRACE1(fmt, arg1)
Definition Object.h:376
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
Definition Object.h:228
#define __T(str)
Definition Object.h:44
ByteString r
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
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:403