BinaryNode.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
BinaryNode.h
Qore Programming Language
Copyright (C) 2003 - 2018 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_BINARYNODE_H
#define _QORE_BINARYNODE_H
#include <qore/AbstractQoreNode.h>
class BinaryNode : public SimpleValueQoreNode {
private:
void *ptr;
qore_size_t len;
// not yet implemented
DLLLOCAL BinaryNode(const BinaryNode&);
DLLLOCAL BinaryNode& operator=(const BinaryNode&);
protected:
DLLEXPORT virtual ~BinaryNode();
DLLLOCAL void checkOffset(qore_offset_t& offset) const;
DLLLOCAL void checkOffset(qore_offset_t& offset, qore_offset_t& num) const;
public:
DLLEXPORT BinaryNode(void *p = 0, qore_size_t size = 0);
DLLEXPORT virtual bool getAsBoolImpl() const;
DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
DLLEXPORT virtual class AbstractQoreNode *realCopy() const;
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
DLLEXPORT virtual const char *getTypeName() const;
DLLLOCAL virtual void parseInit(QoreValue& val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
DLLEXPORT int compare(const BinaryNode *obj) const;
DLLEXPORT qore_size_t size() const;
DLLEXPORT bool empty() const;
DLLEXPORT BinaryNode *copy() const;
DLLEXPORT const void *getPtr() const;
DLLEXPORT void append(const void *nptr, qore_size_t size);
DLLEXPORT void append(const BinaryNode *b);
DLLEXPORT void append(const BinaryNode &b);
DLLEXPORT void prepend(const void *nptr, qore_size_t size);
DLLEXPORT void *giveBuffer();
DLLEXPORT int preallocate(qore_size_t size);
DLLEXPORT int setSize(qore_size_t size);
DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, BinaryNode* extract = 0);
DLLEXPORT void splice(qore_offset_t offset, qore_offset_t length, const void* data, qore_size_t data_len, BinaryNode* extract = 0);
DLLEXPORT int substr(BinaryNode& b, qore_offset_t offset) const;
DLLEXPORT int substr(BinaryNode& b, qore_offset_t offset, qore_offset_t length) const;
DLLEXPORT void clear();
// references the object and returns itself
DLLEXPORT BinaryNode* binRefSelf() const;
DLLLOCAL static const char *getStaticTypeName() {
return "binary";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_BINARY;
}
};
typedef SimpleRefHolder<BinaryNode> BinaryNodeHolder;
#endif // _QORE_BINARYNODE_H
NT_BINARY
const qore_type_t NT_BINARY
type value for BinaryNode
Definition: node_types.h:49
BinaryNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality
BinaryNode::empty
DLLEXPORT bool empty() const
returns true if empty
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
BinaryNode::prepend
DLLEXPORT void prepend(const void *nptr, qore_size_t size)
resizes the object and prepends a copy of the data passed to the beginning of the object ...
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
BinaryNode::preallocate
DLLEXPORT int preallocate(qore_size_t size)
pre-allocates a buffer of a certain size
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
BinaryNode::splice
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"
BinaryNode::setSize
DLLEXPORT int setSize(qore_size_t size)
sets the buffer size after preallocation
BinaryNode::binRefSelf
DLLEXPORT BinaryNode * binRefSelf() const
BinaryNode::~BinaryNode
virtual DLLEXPORT ~BinaryNode()
frees and memory owned by the object
BinaryNode::getAsString
virtual DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const
concatenate the verbose string representation of the value to an existing QoreString ...
BinaryNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
BinaryNode::clear
DLLEXPORT void clear()
frees any managed memory and sets the size to 0
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
SimpleRefHolder
manages a reference count of a pointer to a class that takes a simple "deref()" call with no argument...
Definition: ReferenceHolder.h:118
BinaryNode::compare
DLLEXPORT int compare(const BinaryNode *obj) const
returns 0 = equal, 1 = not equal
BinaryNode::realCopy
virtual DLLEXPORT class AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
BinaryNode::getPtr
DLLEXPORT const void * getPtr() const
returns the pointer to the data
BinaryNode::giveBuffer
DLLEXPORT void * giveBuffer()
returns the data being managed and leaves this object empty
qore_offset_t
intptr_t qore_offset_t
used for offsets that could be negative
Definition: common.h:76
BinaryNode::getAsBoolImpl
virtual DLLEXPORT bool getAsBoolImpl() const
returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when emp...
BinaryNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: BinaryNode.h:215
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:70
BinaryNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
BinaryNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: BinaryNode.h:220
SimpleValueQoreNode
base class for simple value types
Definition: AbstractQoreNode.h:366
BinaryNode::size
DLLEXPORT qore_size_t size() const
returns the number of bytes in the object
BinaryNode::substr
DLLEXPORT int substr(BinaryNode &b, qore_offset_t offset) const
copies data to the BinaryNode argument starting with byte position "offset"
BinaryNode::copy
DLLEXPORT BinaryNode * copy() const
returns a copy of the object
BinaryNode::append
DLLEXPORT void append(const void *nptr, qore_size_t size)
resizes the object and appends a copy of the data passed to the object
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
BinaryNode::parseInit
virtual DLLLOCAL void parseInit(QoreValue &val, LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information