00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */ 00002 /* 00003 QoreBoolNode.h 00004 00005 Qore Programming Language 00006 00007 Copyright 2003 - 2010 David Nichols 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00023 00024 #ifndef _QORE_QOREBOOLNODE_H 00025 00026 #define _QORE_QOREBOOLNODE_H 00027 00028 #include <qore/AbstractQoreNode.h> 00029 00034 00035 00037 class QoreBoolNode : public UniqueValueQoreNode { 00038 private: 00040 DLLLOCAL virtual bool getAsBoolImpl() const; 00041 00043 DLLLOCAL virtual int getAsIntImpl() const; 00044 00046 DLLLOCAL virtual int64 getAsBigIntImpl() const; 00047 00049 DLLLOCAL virtual double getAsFloatImpl() const; 00050 00051 protected: 00053 bool b; 00054 00056 DLLLOCAL QoreBoolNode(bool n_b); 00057 00058 public: 00059 DLLEXPORT virtual ~QoreBoolNode(); 00060 00061 // get the value of the type in a string context (default implementation = del = false and returns NullString) 00062 // if del is true, then the returned QoreString * should be deleted, if false, then it must not be 00063 // use the QoreStringValueHelper class (defined in QoreStringNode.h) instead of using this function directly 00064 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const; 00065 00066 // concatenate string representation to a QoreString (no action for complex types = default implementation) 00067 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const; 00068 00069 // if del is true, then the returned DateTime * should be deleted, if false, then it should not 00070 DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const; 00071 00072 // assign date representation to a DateTime (no action for complex types = default implementation) 00073 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const; 00074 00075 // get string representation (for %n and %N), foff is for multi-line formatting offset, -1 = no line breaks 00076 // the ExceptionSink is only needed for QoreObject where a method may be executed 00077 // use the QoreNodeAsStringHelper class (defined in QoreStringNode.h) instead of using these functions directly 00078 // returns -1 for exception raised, 0 = OK 00079 DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const; 00080 00081 // if del is true, then the returned QoreString * should be deleted, if false, then it must not be 00082 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const; 00083 00084 // the type passed must always be equal to the current type 00085 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const; 00086 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const; 00087 00088 // returns the type name as a c string 00089 DLLEXPORT virtual const char *getTypeName() const; 00090 00092 DLLLOCAL virtual AbstractQoreNode *parseInit(LocalVar *oflag, int pflag, int &lvids, const QoreTypeInfo *&typeInfo); 00093 00094 DLLLOCAL static const char *getStaticTypeName() { 00095 return "bool"; 00096 } 00097 00098 DLLLOCAL bool getValue() const { 00099 return b; 00100 } 00101 }; 00102 00104 00107 class QoreBoolTrueNode : public QoreBoolNode { 00108 public: 00109 DLLLOCAL QoreBoolTrueNode(); 00110 }; 00111 00113 00116 class QoreBoolFalseNode : public QoreBoolNode { 00117 public: 00118 DLLLOCAL QoreBoolFalseNode(); 00119 }; 00120 00122 DLLEXPORT extern QoreBoolFalseNode False; 00123 00125 DLLEXPORT extern QoreBoolTrueNode True; 00126 00128 static inline QoreBoolNode *get_bool_node(bool v) { 00129 return v ? (QoreBoolNode *)&True : (QoreBoolNode *)&False; 00130 } 00131 00132 #endif