Qore Programming Language  0.8.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreBoolNode.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreBoolNode.h
4 
5  Qore Programming Language
6 
7  Copyright 2003 - 2013 David Nichols
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef _QORE_QOREBOOLNODE_H
25 
26 #define _QORE_QOREBOOLNODE_H
27 
28 #include <qore/AbstractQoreNode.h>
29 
34 
38 private:
40  DLLLOCAL virtual bool getAsBoolImpl() const;
41 
43  DLLLOCAL virtual int getAsIntImpl() const;
44 
46  DLLLOCAL virtual int64 getAsBigIntImpl() const;
47 
49  DLLLOCAL virtual double getAsFloatImpl() const;
50 
51 protected:
53  bool b;
54 
56  DLLLOCAL QoreBoolNode(bool n_b);
57 
58 public:
59  DLLEXPORT virtual ~QoreBoolNode();
60 
61  // get the value of the type in a string context (default implementation = del = false and returns NullString)
62  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
63  // use the QoreStringValueHelper class (defined in QoreStringNode.h) instead of using this function directly
64  DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
65 
66  // concatenate string representation to a QoreString (no action for complex types = default implementation)
67  DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
68 
69  // if del is true, then the returned DateTime * should be deleted, if false, then it should not
70  DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
71 
72  // assign date representation to a DateTime (no action for complex types = default implementation)
73  DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
74 
75  // get string representation (for %n and %N), foff is for multi-line formatting offset, -1 = no line breaks
76  // the ExceptionSink is only needed for QoreObject where a method may be executed
77  // use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead of using these functions directly
78  // returns -1 for exception raised, 0 = OK
79  DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
80 
81  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
82  DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
83 
84  // the type passed must always be equal to the current type
85  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
86  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
87 
88  // returns the type name as a c string
89  DLLEXPORT virtual const char *getTypeName() const;
90 
92  DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
93 
95  DLLLOCAL bool getValue() const {
96  return b;
97  }
98 
100  DLLLOCAL static const char *getStaticTypeName() {
101  return "bool";
102  }
103 
105  DLLLOCAL static qore_type_t getStaticTypeCode() {
106  return NT_BOOLEAN;
107  }
108 
110  DLLLOCAL static bool getValue(QoreBoolNode *v) {
111  return v->b;
112  }
113 };
114 
116 
120 public:
121  DLLLOCAL QoreBoolTrueNode();
122 };
123 
125 
129 public:
130  DLLLOCAL QoreBoolFalseNode();
131 };
132 
134 DLLEXPORT extern QoreBoolFalseNode False;
135 
137 DLLEXPORT extern QoreBoolTrueNode True;
138 
140 static inline QoreBoolNode *get_bool_node(bool v) {
141  return v ? (QoreBoolNode *)&True : (QoreBoolNode *)&False;
142 }
143 
144 #endif
virtual DLLEXPORT bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values for container types) without type c...
DLLEXPORT QoreBoolFalseNode False
Qore&#39;s boolean false value.
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:85
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreBoolNode.h:100
Qore&#39;s boolean &quot;true&quot; node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:119
bool b
boolean value for the object
Definition: QoreBoolNode.h:53
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...
DLLLOCAL QoreBoolNode(bool n_b)
the constructor can only be called by a subclass
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:59
static QoreBoolNode * get_bool_node(bool v)
a little inline helper function for getting a boolean node
Definition: QoreBoolNode.h:140
base class for Qore&#39;s 2 boolean classes: QoreBoolTrueNode and QoreBoolFalseNode
Definition: QoreBoolNode.h:37
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
DLLEXPORT QoreBoolTrueNode True
Qore&#39;s boolean true value.
this class is for value types that will exists only once in the Qore library, reference counting is d...
Definition: AbstractQoreNode.h:461
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
DLLLOCAL bool getValue() const
returns the boolean value of the object
Definition: QoreBoolNode.h:95
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
Qore&#39;s boolean &quot;false&quot; node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:128
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
virtual DLLLOCAL AbstractQoreNode * parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo)
returns the type information
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality (&quot;deep compare&quot; including all contained values for container types) with possible ...
const qore_type_t NT_BOOLEAN
type value for QoreBoolNode
Definition: node_types.h:39
static DLLLOCAL bool getValue(QoreBoolNode *v)
returns the value of the argument (useful in templates)
Definition: QoreBoolNode.h:110
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreBoolNode.h:105
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...