Qore Programming Language 1.19.5
Loading...
Searching...
No Matches
OutputStreamWrapper.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 OutputStreamWrapper.h
4
5 Qore Programming Language
6
7 Copyright (C) 2016 - 2023 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_OUTPUTSTREAMWRAPPER_H
33#define _QORE_OUTPUTSTREAMWRAPPER_H
34
35#include "qore/OutputStream.h"
36
41
42public:
47 OutputStreamWrapper(QoreObject *self) : self(self) {
48 }
49
50 DLLLOCAL virtual void close(ExceptionSink* xsink) override {
51 self->evalMethod("close", 0, xsink);
52 }
53
54 DLLLOCAL virtual void write(const void* ptr, int64 count, ExceptionSink* xsink) override {
55 assert(count >= 0);
56
58 buf->preallocate(count);
59 memcpy(const_cast<void *>(buf->getPtr()), ptr, count);
60
61 ReferenceHolder<QoreListNode> args(new QoreListNode(autoTypeInfo), xsink);
62 args->push(buf.release(), xsink);
63 self->evalMethod("write", *args, xsink);
64 }
65
66 DLLLOCAL bool isClosed() override {
67 return false;
68 }
69
70 DLLLOCAL virtual const char* getName() override {
71 return "OutputStreamWrapper";
72 }
73
74private:
75 QoreObject* self;
76};
77
78#endif // _QORE_OUTPUTSTREAMWRAPPER_H
holds arbitrary binary data
Definition: BinaryNode.h:41
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Interface for private data of output streams.
Definition: OutputStream.h:44
Implements the private data for all subclasses of Qore::OutputStream implemented in the Qore language...
Definition: OutputStreamWrapper.h:40
virtual DLLLOCAL const char * getName() override
Returns the name of the class.
Definition: OutputStreamWrapper.h:70
OutputStreamWrapper(QoreObject *self)
Constructor.
Definition: OutputStreamWrapper.h:47
virtual DLLLOCAL void close(ExceptionSink *xsink) override
Flushes any buffered (unwritten) bytes, closes the output stream and releases resources.
Definition: OutputStreamWrapper.h:50
DLLLOCAL bool isClosed() override
Returns true is the stream has been closed.
Definition: OutputStreamWrapper.h:66
virtual DLLLOCAL void write(const void *ptr, int64 count, ExceptionSink *xsink) override
Writes bytes to the output stream.
Definition: OutputStreamWrapper.h:54
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
the implementation of Qore's object data type, reference counted, dynamically-allocated only
Definition: QoreObject.h:62
DLLEXPORT QoreValue evalMethod(const QoreString *name, const QoreListNode *args, ExceptionSink *xsink)
evaluates the given method with the arguments passed and returns the return value,...
a templated class to manage a reference count of an object that can throw a Qore-language exception w...
Definition: ReferenceHolder.h:52
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:127
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260