All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreStringValueHelper Class Reference

this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simple QoreString value is needed, stack only, may not be dynamically allocated More...

`#include <QoreStringNode.h>`

Collaboration diagram for QoreStringValueHelper:
[legend]

## Public Member Functions

DLLEXPORT | QoreStringValueHelper (const AbstractQoreNode *n)
| creates the object and acquires a pointer to the QoreString representation of the AbstractQoreNode passed
DLLEXPORT | QoreStringValueHelper (const QoreValue &n)
| creates the object and acquires a pointer to the QoreString representation of the QoreValue passed
DLLEXPORT | QoreStringValueHelper (const AbstractQoreNode *n, const QoreEncoding *enc, ExceptionSink *xsink)
| gets the QoreString representation and ensures that it's in the desired encoding More...
DLLEXPORT | QoreStringValueHelper (const QoreValue &n, const QoreEncoding *enc, ExceptionSink *xsink)
| gets the QoreString representation and ensures that it's in the desired encoding
DLLLOCAL | ~QoreStringValueHelper ()
| destroys the object and deletes the QoreString pointer being managed if it was a temporary pointer
DLLLOCAL char * | giveBuffer ()
| returns a char* string that the caller owns and must free() More...
DLLLOCAL QoreString * | giveString ()
| returns a copy of the QoreString that the caller owns More...
DLLLOCAL bool | is_temp () const
| returns true if the pointer being managed is temporary
DLLLOCAL const QoreString * | operator* ()
| returns the object being managed More...
DLLLOCAL const QoreString * | operator-> ()
| returns the object being managed More...

## Protected Member Functions

DLLLOCAL | QoreStringValueHelper (const QoreStringValueHelper &)
| this function is not implemented; it is here as a private function in order to prohibit it from being used
DLLLOCAL void * | operator new (size_t)
| this function is not implemented; it is here as a private function in order to prohibit it from being used
DLLLOCAL QoreStringValueHelper & | operator= (const QoreStringValueHelper &)
| this function is not implemented; it is here as a private function in order to prohibit it from being used
DLLLOCAL void | setup (ExceptionSink *xsink, const QoreValue n, const QoreEncoding *enc=0)
| sets up the object / common initialization

## Detailed Description

this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simple QoreString value is needed, stack only, may not be dynamically allocated

the QoreString value returned by this function is managed safely in an exception-safe way with this class

QoreStringValueHelper str(n);
printf("str='%s'\n", str->getBuffer());

## Constructor & Destructor Documentation

DLLEXPORT QoreStringValueHelper::QoreStringValueHelper | ( | const AbstractQoreNode * | n,
|  | const QoreEncoding * | enc,
|  | ExceptionSink * | xsink
| ) |  |

gets the QoreString representation and ensures that it's in the desired encoding

a Qore-language exception may be thrown if an encoding error occurs

// get a QoreString value from "node" and ensure it's in UTF-8 encoding
QoreStringValueHelper t(node, QCS_UTF8, xsink);
// return if there was an exception converting the encoding to UTF-8
if (*xsink)
return 0;
// use the string value
return new MStringData(t->getBuffer(), MEncoding::M_ASCII);

## Member Function Documentation

DLLLOCAL char* QoreStringValueHelper::giveBuffer | ( |  | ) |

inline

returns a char* string that the caller owns and must free()

the object is empty after this call

References QoreString::getBuffer(), and QoreString::giveBuffer().

DLLLOCAL QoreString* QoreStringValueHelper::giveString | ( |  | ) |

inline

returns a copy of the QoreString that the caller owns

the object may be left empty after this call

Returns
  a QoreString pointer owned by the caller

References QoreString::copy().

DLLLOCAL const QoreString* QoreStringValueHelper::operator* | ( |  | ) |

inline

returns the object being managed

Returns
  the object being managed

DLLLOCAL const QoreString* QoreStringValueHelper::operator-> | ( |  | ) |

inline

returns the object being managed

Returns
  the object being managed

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

- include/qore/QoreStringNode.h (6de6cc3b438610bf03b2bec44a3d7c61f90e3165)