QoreBoolNode.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreBoolNode.h
Qore Programming Language
Copyright (C) 2003 - 2015 David Nichols
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_QOREBOOLNODE_H
#define _QORE_QOREBOOLNODE_H
#include <qore/AbstractQoreNode.h>
class QoreBoolNode : public UniqueValueQoreNode {
private:
DLLLOCAL virtual bool getAsBoolImpl() const;
DLLLOCAL virtual int getAsIntImpl() const;
DLLLOCAL virtual int64 getAsBigIntImpl() const;
DLLLOCAL virtual double getAsFloatImpl() const;
protected:
bool b;
DLLLOCAL QoreBoolNode(bool n_b);
public:
DLLEXPORT virtual ~QoreBoolNode();
// get the value of the type in a string context (default implementation = del = false and returns NullString)
// if del is true, then the returned QoreString * should be deleted, if false, then it must not be
// use the QoreStringValueHelper class (defined in QoreStringNode.h) instead of using this function directly
DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
// concatenate string representation to a QoreString (no action for complex types = default implementation)
DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
// if del is true, then the returned DateTime * should be deleted, if false, then it should not
DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
// assign date representation to a DateTime (no action for complex types = default implementation)
DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
// get string representation (for %n and %N), foff is for multi-line formatting offset, -1 = no line breaks
// the ExceptionSink is only needed for QoreObject where a method may be executed
// use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead of using these functions directly
// returns -1 for exception raised, 0 = OK
DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
// if del is true, then the returned QoreString * should be deleted, if false, then it must not be
DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
// the type passed must always be equal to the current type
DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
// returns the type name as a c string
DLLEXPORT virtual const char *getTypeName() const;
DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
DLLLOCAL bool getValue() const {
return b;
}
DLLLOCAL static const char *getStaticTypeName() {
return "bool";
}
DLLLOCAL static qore_type_t getStaticTypeCode() {
return NT_BOOLEAN;
}
static const qore_type_t TYPE = NT_BOOLEAN;
DLLLOCAL static bool getValue(QoreBoolNode *v) {
return v->b;
}
};
class QoreBoolTrueNode : public QoreBoolNode {
public:
DLLLOCAL QoreBoolTrueNode();
};
class QoreBoolFalseNode : public QoreBoolNode {
public:
DLLLOCAL QoreBoolFalseNode();
};
DLLEXPORT extern QoreBoolFalseNode False;
DLLEXPORT extern QoreBoolTrueNode True;
static inline QoreBoolNode *get_bool_node(bool v) {
return v ? (QoreBoolNode *)&True : (QoreBoolNode *)&False;
}
#endif
QoreBoolNode::is_equal_hard
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values for container types) without type c...
False
DLLEXPORT QoreBoolFalseNode False
Qore's boolean false value.
DateTime
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
QoreBoolNode::getStaticTypeName
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreBoolNode.h:108
QoreBoolTrueNode
Qore's boolean "true" node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:129
QoreBoolNode::b
bool b
boolean value for the object
Definition: QoreBoolNode.h:61
QoreBoolNode::getAsString
virtual DLLEXPORT int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const
concatenate the verbose string representation of the value (including all contained values for contai...
QoreBoolNode::QoreBoolNode
DLLLOCAL QoreBoolNode(bool n_b)
the constructor can only be called by a subclass
get_bool_node
static QoreBoolNode * get_bool_node(bool v)
a little inline helper function for getting a boolean node
Definition: QoreBoolNode.h:150
QoreBoolNode
base class for Qore's 2 boolean classes: QoreBoolTrueNode and QoreBoolFalseNode
Definition: QoreBoolNode.h:45
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:82
True
DLLEXPORT QoreBoolTrueNode True
Qore's boolean true value.
UniqueValueQoreNode
this class is for value types that will exists only once in the Qore library, reference counting is d...
Definition: AbstractQoreNode.h:479
QoreBoolNode::getTypeName
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
QoreBoolNode::getValue
DLLLOCAL bool getValue() const
returns the boolean value of the object
Definition: QoreBoolNode.h:103
QoreBoolNode::getDateTimeRepresentation
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
QoreBoolFalseNode
Qore's boolean "false" node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:138
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
QoreBoolNode::parseInit
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
QoreBoolNode::is_equal_soft
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality ("deep compare" including all contained values for container types) with possible ...
NT_BOOLEAN
const qore_type_t NT_BOOLEAN
type value for QoreBoolNode
Definition: node_types.h:47
int64
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:228
QoreBoolNode::getValue
static DLLLOCAL bool getValue(QoreBoolNode *v)
returns the value of the argument (useful in templates)
Definition: QoreBoolNode.h:120
QoreBoolNode::getStaticTypeCode
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreBoolNode.h:113
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
QoreBoolNode::getStringRepresentation
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...