Qore Programming Language  0.8.11.1
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 (C) 2003 - 2014 David Nichols
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_QOREBOOLNODE_H
33 
34 #define _QORE_QOREBOOLNODE_H
35 
36 #include <qore/AbstractQoreNode.h>
37 
42 
46 private:
48  DLLLOCAL virtual bool getAsBoolImpl() const;
49 
51  DLLLOCAL virtual int getAsIntImpl() const;
52 
54  DLLLOCAL virtual int64 getAsBigIntImpl() const;
55 
57  DLLLOCAL virtual double getAsFloatImpl() const;
58 
59 protected:
61  bool b;
62 
64  DLLLOCAL QoreBoolNode(bool n_b);
65 
66 public:
67  DLLEXPORT virtual ~QoreBoolNode();
68 
69  // get the value of the type in a string context (default implementation = del = false and returns NullString)
70  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
71  // use the QoreStringValueHelper class (defined in QoreStringNode.h) instead of using this function directly
72  DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
73 
74  // concatenate string representation to a QoreString (no action for complex types = default implementation)
75  DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
76 
77  // if del is true, then the returned DateTime * should be deleted, if false, then it should not
78  DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
79 
80  // assign date representation to a DateTime (no action for complex types = default implementation)
81  DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
82 
83  // get string representation (for %n and %N), foff is for multi-line formatting offset, -1 = no line breaks
84  // the ExceptionSink is only needed for QoreObject where a method may be executed
85  // use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead of using these functions directly
86  // returns -1 for exception raised, 0 = OK
87  DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
88 
89  // if del is true, then the returned QoreString * should be deleted, if false, then it must not be
90  DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
91 
92  // the type passed must always be equal to the current type
93  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
94  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
95 
96  // returns the type name as a c string
97  DLLEXPORT virtual const char *getTypeName() const;
98 
100  DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo);
101 
103  DLLLOCAL bool getValue() const {
104  return b;
105  }
106 
108  DLLLOCAL static const char *getStaticTypeName() {
109  return "bool";
110  }
111 
113  DLLLOCAL static qore_type_t getStaticTypeCode() {
114  return NT_BOOLEAN;
115  }
116 
118  DLLLOCAL static bool getValue(QoreBoolNode *v) {
119  return v->b;
120  }
121 };
122 
124 
128 public:
129  DLLLOCAL QoreBoolTrueNode();
130 };
131 
133 
137 public:
138  DLLLOCAL QoreBoolFalseNode();
139 };
140 
142 DLLEXPORT extern QoreBoolFalseNode False;
143 
145 DLLEXPORT extern QoreBoolTrueNode True;
146 
148 static inline QoreBoolNode *get_bool_node(bool v) {
149  return v ? (QoreBoolNode *)&True : (QoreBoolNode *)&False;
150 }
151 
152 #endif
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...
DLLEXPORT QoreBoolFalseNode False
Qore's boolean false value.
Holds absolute and relative date/time values in Qore with precision to the microsecond.
Definition: DateTime.h:93
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: QoreBoolNode.h:108
Qore's boolean "true" node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:127
bool b
boolean value for the object
Definition: QoreBoolNode.h:61
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:67
static QoreBoolNode * get_bool_node(bool v)
a little inline helper function for getting a boolean node
Definition: QoreBoolNode.h:148
base class for Qore's 2 boolean classes: QoreBoolTrueNode and QoreBoolFalseNode
Definition: QoreBoolNode.h:45
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:50
DLLEXPORT QoreBoolTrueNode True
Qore'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:469
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:103
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
Qore's boolean "false" node, unique, not dynamically-allocated, not reference-counted.
Definition: QoreBoolNode.h:136
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
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 ("deep compare" including all contained values for container types) with possible ...
const qore_type_t NT_BOOLEAN
type value for QoreBoolNode
Definition: node_types.h:47
static DLLLOCAL bool getValue(QoreBoolNode *v)
returns the value of the argument (useful in templates)
Definition: QoreBoolNode.h:118
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: QoreBoolNode.h:113
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns the value of the type converted to a string, default implementation: returns the empty string...