Qore Programming Language 1.14.0
Loading...
Searching...
No Matches
BinaryNode Class Reference

holds arbitrary binary data More...

#include <BinaryNode.h>

Inheritance diagram for BinaryNode:
[legend]
Collaboration diagram for BinaryNode:
[legend]

Public Member Methods

DLLEXPORT BinaryNode (void *p=0, size_t size=0)
 creates the object More...
 
DLLEXPORT void append (const BinaryNode &b)
 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
 
DLLEXPORT void append (const void *nptr, size_t size)
 resizes the object and appends a copy of the data passed to the object
 
DLLEXPORT BinaryNodebinRefSelf () const
 
DLLEXPORT void clear ()
 frees any managed memory and sets the size to 0
 
DLLEXPORT int compare (const BinaryNode *obj) const
 returns 0 = equal, 1 = not equal
 
DLLEXPORT BinaryNodecopy () const
 returns a copy of the object More...
 
DLLEXPORT bool empty () const
 returns true if empty
 
virtual DLLEXPORT bool getAsBoolImpl () const
 returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when empty More...
 
virtual DLLEXPORT QoreStringgetAsString (bool &del, int foff, class ExceptionSink *xsink) const
 returns a QoreString giving the verbose string representation of the List (including all contained values for container types) More...
 
virtual DLLEXPORT int getAsString (QoreString &str, int foff, class ExceptionSink *xsink) const
 concatenate the verbose string representation of the value to an existing QoreString More...
 
DLLEXPORT const void * getPtr () const
 returns the pointer to the data
 
virtual DLLEXPORT const char * getTypeName () const
 returns the type name as a c string
 
DLLEXPORT void * giveBuffer ()
 returns the data being managed and leaves this object empty More...
 
virtual DLLEXPORT bool is_equal_hard (const AbstractQoreNode *v, ExceptionSink *xsink) const
 tests for equality More...
 
virtual DLLEXPORT bool is_equal_soft (const AbstractQoreNode *v, ExceptionSink *xsink) const
 tests for equality More...
 
virtual DLLLOCAL int parseInit (QoreValue &val, QoreParseContext &parse_context)
 returns the type information
 
DLLEXPORT int preallocate (size_t size)
 pre-allocates a buffer of a certain size More...
 
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
 
virtual DLLEXPORT class AbstractQoreNoderealCopy () const
 returns a copy of the object; the caller owns the reference count More...
 
DLLEXPORT int setSize (size_t size)
 sets the buffer size after preallocation More...
 
DLLEXPORT size_t size () const
 returns the number of bytes in the object
 
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" More...
 
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 the data passed More...
 
DLLEXPORT int substr (BinaryNode &b, qore_offset_t offset) const
 copies data to the BinaryNode argument starting with byte position "offset" More...
 
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" More...
 
DLLEXPORT int writeTo (size_t pos, const void *nptr, size_t size)
 writes the given data to the given location in the object More...
 
- Public Member Methods inherited from SimpleValueQoreNode
DLLLOCAL SimpleValueQoreNode (qore_type_t t, bool n_there_can_be_only_one=false)
 creates the object by assigning the type code and setting the "value" flag, unsetting the "needs_eval" flag, and setting "there_can_be_only_one"
 
- Public Member Methods inherited from SimpleQoreNode
DLLLOCAL SimpleQoreNode (const SimpleQoreNode &v)
 copy constructor
 
DLLLOCAL SimpleQoreNode (qore_type_t t, bool n_value, bool n_needs_eval, bool n_there_can_be_only_one=false)
 constructor takes the type and value arguments
 
DLLEXPORT void deref (ExceptionSink *xsink)
 decrements the reference count and deletes the object when references = 0 More...
 
SimpleQoreNodeoperator= (const SimpleQoreNode &)=delete
 this function is not implemented
 
- Public Member Methods inherited from AbstractQoreNode
DLLEXPORT AbstractQoreNode (const AbstractQoreNode &v)
 copy constructor
 
DLLEXPORT AbstractQoreNode (qore_type_t t, bool n_value, bool n_needs_eval, bool n_there_can_be_only_one=false, bool n_custom_reference_handlers=false)
 constructor takes the type More...
 
virtual DLLEXPORT void customDeref (ExceptionSink *xsink)
 
virtual DLLEXPORT void customRef () const
 special processing when the object's reference count transitions from 0-1 More...
 
DLLEXPORT void deref (ExceptionSink *xsink)
 decrements the reference count and calls derefImpl() if there_can_be_only_one is false, otherwise does nothing More...
 
virtual DLLEXPORT bool derefImpl (ExceptionSink *xsink)
 decrements the reference count More...
 
DLLEXPORT QoreValue eval (bool &needs_deref, ExceptionSink *xsink) const
 optionally evaluates the argument More...
 
DLLEXPORT QoreValue eval (ExceptionSink *xsink) const
 evaluates the object and returns a value (or 0) More...
 
virtual DLLEXPORT QoreValue evalImpl (bool &needs_deref, ExceptionSink *xsink) const =0
 optionally evaluates the argument More...
 
DLLEXPORT int64 getAsBigInt () const
 returns the 64-bit integer value of the object More...
 
virtual DLLLOCAL int64 getAsBigIntImpl () const
 default implementation, returns 0 More...
 
DLLEXPORT bool getAsBool () const
 returns the boolean value of the object More...
 
virtual DLLLOCAL bool getAsBoolImpl () const
 default implementation, returns false More...
 
DLLEXPORT double getAsFloat () const
 returns the float value of the object More...
 
virtual DLLLOCAL double getAsFloatImpl () const
 default implementation, returns 0.0 More...
 
DLLEXPORT int getAsInt () const
 returns the integer value of the object More...
 
virtual DLLLOCAL int getAsIntImpl () const
 default implementation, returns 0 More...
 
virtual DLLEXPORT QoreStringgetAsString (bool &del, int foff, ExceptionSink *xsink) const =0
 returns a QoreString giving the verbose string representation of the value (including all contained values for container types) More...
 
virtual DLLEXPORT int getAsString (QoreString &str, int foff, ExceptionSink *xsink) const =0
 concatenate the verbose string representation of the value (including all contained values for container types) to an existing QoreString More...
 
virtual DLLEXPORT class DateTimegetDateTimeRepresentation (bool &del) const
 returns the DateTime representation of this type (default implementation: returns ZeroDate, del = false) More...
 
virtual DLLEXPORT void getDateTimeRepresentation (DateTime &dt) const
 assigns the date representation of a value to the DateTime reference passed, default implementation does nothing More...
 
virtual DLLEXPORT QoreStringgetStringRepresentation (bool &del) const
 returns the value of the type converted to a string, default implementation: returns the empty string More...
 
virtual DLLEXPORT void getStringRepresentation (QoreString &str) const
 concatentates the value of the type to an existing QoreString reference, default implementation does nothing More...
 
DLLLOCAL qore_type_t getType () const
 returns the data type More...
 
virtual DLLEXPORT const char * getTypeName () const =0
 returns the type name as a c string More...
 
virtual DLLEXPORT bool is_equal_hard (const AbstractQoreNode *v, ExceptionSink *xsink) const =0
 tests for equality ("deep compare" including all contained values for container types) without type conversions (hard compare) More...
 
virtual DLLEXPORT bool is_equal_soft (const AbstractQoreNode *v, ExceptionSink *xsink) const =0
 tests for equality ("deep compare" including all contained values for container types) with possible type conversion (soft compare) More...
 
DLLLOCAL bool is_value () const
 returns true if the node represents a value More...
 
DLLLOCAL bool isReferenceCounted () const
 returns true if the object is reference-counted
 
DLLLOCAL bool needs_eval () const
 returns true if the object needs evaluation to return a value, false if not More...
 
DLLLOCAL AbstractQoreNodeoperator= (const AbstractQoreNode &)
 this function is not implemented; it is here as a private function in order to prohibit it from being used
 
virtual DLLLOCAL int parseInit (QoreValue &val, QoreParseContext &parse_context)
 for use by parse types to initialize them for execution during stage 1 parsing More...
 
virtual DLLEXPORT AbstractQoreNoderealCopy () const =0
 returns a copy of the object; the caller owns the reference count More...
 
DLLEXPORT void ref () const
 increments the reference count
 
DLLEXPORT AbstractQoreNoderefSelf () const
 returns "this" with an incremented reference count More...
 
- Public Member Methods inherited from QoreReferenceCounter
DLLEXPORT QoreReferenceCounter ()
 creates the reference counter object
 
DLLEXPORT QoreReferenceCounter (const QoreReferenceCounter &old)
 creates a new object with a reference count of 1 More...
 
DLLEXPORT ~QoreReferenceCounter ()
 destroys the reference counter object
 
DLLEXPORT bool is_unique () const
 returns true if the reference count is 1 More...
 
DLLEXPORT int reference_count () const
 gets the reference count More...
 
DLLEXPORT bool ROdereference () const
 atomically decrements the reference count More...
 
DLLEXPORT void ROreference () const
 atomically increments the reference count
 

Static Public Member Methods

static DLLLOCAL qore_type_t getStaticTypeCode ()
 returns the type code (useful in templates)
 
static DLLLOCAL const char * getStaticTypeName ()
 returns the type name (useful in templates)
 

Private Member Methods

virtual DLLEXPORT ~BinaryNode ()
 frees and memory owned by the object
 
- Private Member Methods inherited from SimpleValueQoreNode
virtual DLLEXPORT QoreValue evalImpl (bool &needs_deref, ExceptionSink *xsink) const
 should never be called for value types More...
 
- Private Member Methods inherited from AbstractQoreNode
virtual DLLEXPORT ~AbstractQoreNode ()
 default destructor does nothing More...
 

Additional Inherited Members

- Private Attributes inherited from AbstractQoreNode
bool custom_reference_handlers: 1
 set to one for objects that need custom reference handlers
 
bool needs_eval_flag: 1
 if this is true then the type can be evaluated
 
bool there_can_be_only_one: 1
 if this is set to true, then reference counting is turned off for objects of this class
 
qore_type_t type: 11
 the type of the object More...
 
bool value: 1
 this is true for values, if false then either the type needs evaluation to produce a value or is a parse expression
 

Detailed Description

holds arbitrary binary data

this class is implemented simply as a pointer and a length indicator

Constructor & Destructor Documentation

◆ BinaryNode()

DLLEXPORT BinaryNode::BinaryNode ( void *  p = 0,
size_t  size = 0 
)

creates the object

Parameters
pa pointer to the memory, the BinaryNode object takes over ownership of this pointer
sizethe byte length of the memory

Member Function Documentation

◆ binRefSelf()

DLLEXPORT BinaryNode * BinaryNode::binRefSelf ( ) const
Since
Qore 0.9

◆ copy()

DLLEXPORT BinaryNode * BinaryNode::copy ( ) const

returns a copy of the object

Returns
a copy of the current object

◆ getAsBoolImpl()

virtual DLLEXPORT bool BinaryNode::getAsBoolImpl ( ) const
virtual

returns false unless perl-boolean-evaluation is enabled, in which case it returns false only when empty

Returns
false unless perl-boolean-evaluation is enabled, in which case it returns false only when empty

Reimplemented from AbstractQoreNode.

◆ getAsString() [1/2]

virtual DLLEXPORT QoreString * BinaryNode::getAsString ( bool &  del,
int  foff,
class ExceptionSink xsink 
) const
virtual

returns a QoreString giving the verbose string representation of the List (including all contained values for container types)

used for n and N printf formatting

Parameters
delif this is true when the function returns, then the returned QoreString pointer should be deleted, if false, then it must not be
fofffor multi-line formatting offset, -1 = no line breaks
xsinkif an error occurs, the Qore-language exception information will be added here NOTE: Use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead of using this function directly
See also
QoreNodeAsStringHelper

Implements AbstractQoreNode.

◆ getAsString() [2/2]

virtual DLLEXPORT int BinaryNode::getAsString ( QoreString str,
int  foff,
class ExceptionSink xsink 
) const
virtual

concatenate the verbose string representation of the value to an existing QoreString

used for n and N printf formatting

Parameters
strthe string representation of the type will be concatenated to this QoreString reference
fofffor multi-line formatting offset, -1 = no line breaks
xsinkif an error occurs, the Qore-language exception information will be added here
Returns
-1 for exception raised, 0 = OK

Implements AbstractQoreNode.

◆ giveBuffer()

DLLEXPORT void * BinaryNode::giveBuffer ( )

returns the data being managed and leaves this object empty

Returns
the data being managed (leaves this object empty)
Note
it would be a grevious error to call this function on an object with a reference_count > 1 (i.e. is_unique() is false)

◆ is_equal_hard()

virtual DLLEXPORT bool BinaryNode::is_equal_hard ( const AbstractQoreNode v,
ExceptionSink xsink 
) const
virtual

tests for equality

this function does not throw a Qore-language exception with the BinaryNode class

Parameters
vthe value to compare
xsinkis not used in this implementation of the function

Implements AbstractQoreNode.

◆ is_equal_soft()

virtual DLLEXPORT bool BinaryNode::is_equal_soft ( const AbstractQoreNode v,
ExceptionSink xsink 
) const
virtual

tests for equality

this function does not throw a Qore-language exception with the BinaryNode class

Parameters
vthe value to compare
xsinkis not used in this implementation of the function

Implements AbstractQoreNode.

◆ preallocate()

DLLEXPORT int BinaryNode::preallocate ( size_t  size)

pre-allocates a buffer of a certain size

This function can be used to write data directly to a new BinaryNode object. This call can be made more than once, subsequent calls will cause realloc() to be called on the buffer which can be used to extend the buffer size.

Parameters
sizethe number of bytes to pre-allocate
Returns
0 for OK, -1 for error (memory could not be allocated)

◆ realCopy()

virtual DLLEXPORT class AbstractQoreNode * BinaryNode::realCopy ( ) const
virtual

returns a copy of the object; the caller owns the reference count

Returns
a copy of the object; the caller owns the reference count

Implements AbstractQoreNode.

◆ setSize()

DLLEXPORT int BinaryNode::setSize ( size_t  size)

sets the buffer size after preallocation

This function is designed to be used with BinaryNode::preallocate(). The size to be set must be less than the currently allocated size.

Parameters
sizethe size of the BinaryNode to set
Returns
0 for OK, -1 for error (size > current size)

◆ splice() [1/2]

DLLEXPORT void BinaryNode::splice ( qore_offset_t  offset,
qore_offset_t  length,
BinaryNode extract = 0 
)

removes "length" characters from the binary data starting at position "offset"

Parameters
offsetbyte position to start (rest of the data is removed) (offset starts with 0, negative offset means that many positions from the end of the data)
lengththe number of bytes to remove (negative length means all but that many bytes from the end of the data)
extractif non-null, the data removed will be written to this argument
Since
Qore 0.8.8

◆ splice() [2/2]

DLLEXPORT void BinaryNode::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 the data passed

Parameters
offsetbyte position to start (rest of the data is removed) (offset starts with 0, negative offset means that many positions from the end of the data)
lengththe number of bytes to remove (negative length means all but that many bytes from the end of the data)
datathe data to insert at byte position "offset" after "length" characters are removed
data_lenthe lenght of the data to insert
extractif non-null, the data removed will be written to this argument
Since
Qore 0.8.8

◆ substr() [1/2]

DLLEXPORT int BinaryNode::substr ( BinaryNode b,
qore_offset_t  offset 
) const

copies data to the BinaryNode argument starting with byte position "offset"

Parameters
bthe target for copying the data
offsetthe offset in bytes from the beginning of the data (starting with 0)
Returns
0 = OK, -1 = error (invalid offset)
Since
Qore 0.8.8

◆ substr() [2/2]

DLLEXPORT int BinaryNode::substr ( BinaryNode b,
qore_offset_t  offset,
qore_offset_t  length 
) const

copies data to the BinaryNode argument starting with byte position "offset"

Parameters
bthe target for copying the data
offsetthe offset in bytes from the beginning of the data (starting with 0)
lengththe number of bytes to copy
Returns
0 = OK, -1 = error (invalid offset)
Since
Qore 0.8.8

◆ writeTo()

DLLEXPORT int BinaryNode::writeTo ( size_t  pos,
const void *  nptr,
size_t  size 
)

writes the given data to the given location in the object

resizes the object if necessary

Parameters
posthe byte position where to start writing
nptrthe data to copy to the object
sizethe number of bytes to copy to the object
Returns
-1 if the resize failed (out of memory), 0 if OK
Since
Qore 1.12

The documentation for this class was generated from the following file: