Qore Programming Language 1.19.5
Loading...
Searching...
No Matches
BinaryNode.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 BinaryNode.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 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_BINARYNODE_H
33
34#define _QORE_BINARYNODE_H
35
36#include <qore/AbstractQoreNode.h>
37
39
42private:
44 void* ptr;
46 size_t len;
47
48 // not yet implemented
49 DLLLOCAL BinaryNode(const BinaryNode&);
50 DLLLOCAL BinaryNode& operator=(const BinaryNode&);
51
52protected:
54 DLLEXPORT virtual ~BinaryNode();
55
56 DLLLOCAL void checkOffset(qore_offset_t& offset) const;
57 DLLLOCAL void checkOffset(qore_offset_t& offset, qore_offset_t& num) const;
58
59public:
61
64 DLLEXPORT BinaryNode(void* p = 0, size_t size = 0);
65
67
69 DLLEXPORT virtual bool getAsBoolImpl() const;
70
72
78 DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
79
81
88 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
89
90 DLLEXPORT virtual class AbstractQoreNode* realCopy() const;
91
93
97 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink *xsink) const;
98
100
104 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink *xsink) const;
105
107 DLLEXPORT virtual const char *getTypeName() const;
108
110 DLLLOCAL virtual int parseInit(QoreValue& val, QoreParseContext& parse_context);
111
113 DLLEXPORT int compare(const BinaryNode* obj) const;
114
116 DLLEXPORT size_t size() const;
117
119 DLLEXPORT bool empty() const;
120
122
125 DLLEXPORT BinaryNode* copy() const;
126
128 DLLEXPORT const void* getPtr() const;
129
131 DLLEXPORT void append(const void* nptr, size_t size);
132
134 DLLEXPORT void append(const BinaryNode* b);
135
137 DLLEXPORT void append(const BinaryNode &b);
138
140
150 DLLEXPORT int writeTo(size_t pos, const void* nptr, size_t size);
151
153 DLLEXPORT void prepend(const void* nptr, size_t size);
154
156
161 DLLEXPORT void* giveBuffer();
162
164
170 DLLEXPORT int preallocate(size_t size);
171
173
178 DLLEXPORT int setSize(size_t size);
179
181
187 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, BinaryNode* extract = 0);
188
190
198 DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const void* data, size_t data_len, BinaryNode* extract = 0);
199
201
207 DLLEXPORT int substr(BinaryNode& b, qore_offset_t offset) const;
208
210
217 DLLEXPORT int substr(BinaryNode& b, qore_offset_t offset, qore_offset_t length) const;
218
220 DLLEXPORT void clear();
221
222 // references the object and returns itself
225 DLLEXPORT BinaryNode* binRefSelf() const;
226
228 DLLLOCAL static const char *getStaticTypeName() {
229 return "binary";
230 }
231
233 DLLLOCAL static qore_type_t getStaticTypeCode() {
234 return NT_BINARY;
235 }
236};
237
239
240#endif // _QORE_BINARYNODE_H
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
holds arbitrary binary data
Definition: BinaryNode.h:41
DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, BinaryNode *extract=0)
removes "length" characters from the binary data starting at position "offset"
DLLEXPORT void append(const void *nptr, size_t size)
resizes the object and appends a copy of the data passed to the object
DLLEXPORT void append(const BinaryNode *b)
resizes the object and appends a copy of the data passed to the object
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const void *data, size_t data_len, BinaryNode *extract=0)
removes "length" characters from the binary data starting at position "offset" and replaces them with...
DLLEXPORT int preallocate(size_t size)
pre-allocates a buffer of a certain size
virtual DLLEXPORT QoreString * getAsString(bool &del, int foff, class ExceptionSink *xsink) const
returns a QoreString giving the verbose string representation of the List (including all contained va...
DLLEXPORT int substr(BinaryNode &b, qore_offset_t offset, qore_offset_t length) const
copies data to the BinaryNode argument starting with byte position "offset"
DLLEXPORT BinaryNode(void *p=0, size_t size=0)
creates the object
DLLEXPORT size_t size() const
returns the number of bytes in the object
DLLEXPORT int writeTo(size_t pos, const void *nptr, size_t size)
writes the given data to the given location in the object
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality
DLLEXPORT void * giveBuffer()
returns the data being managed and leaves this object empty
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: BinaryNode.h:233
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: BinaryNode.h:228
virtual DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const
concatenate the verbose string representation of the value to an existing QoreString
virtual DLLEXPORT ~BinaryNode()
frees and memory owned by the object
DLLEXPORT bool empty() const
returns true if empty
DLLEXPORT int setSize(size_t size)
sets the buffer size after preallocation
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
virtual DLLEXPORT class AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
DLLEXPORT void clear()
frees any managed memory and sets the size to 0
virtual DLLLOCAL int parseInit(QoreValue &val, QoreParseContext &parse_context)
returns the type information
DLLEXPORT BinaryNode * binRefSelf() const
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality
DLLEXPORT int substr(BinaryNode &b, qore_offset_t offset) const
copies data to the BinaryNode argument starting with byte position "offset"
DLLEXPORT void append(const BinaryNode &b)
resizes the object and appends a copy of the data passed to the object
DLLEXPORT BinaryNode * copy() const
returns a copy of the object
DLLEXPORT const void * getPtr() const
returns the pointer to the data
DLLEXPORT void prepend(const void *nptr, size_t size)
resizes the object and prepends a copy of the data passed to the beginning of the object
DLLEXPORT int compare(const BinaryNode *obj) const
returns 0 = equal, 1 = not equal
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:127
base class for simple value types
Definition: AbstractQoreNode.h:372
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
const qore_type_t NT_BINARY
type value for BinaryNode
Definition: node_types.h:49
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:279