00001 /* 00002 QoreBoolNode.h 00003 00004 Qore Programming Language 00005 00006 Copyright 2003 - 2009 David Nichols 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef _QORE_QOREBOOLNODE_H 00024 00025 #define _QORE_QOREBOOLNODE_H 00026 00027 #include <qore/AbstractQoreNode.h> 00028 00033 00034 00036 class QoreBoolNode : public UniqueValueQoreNode 00037 { 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 00091 DLLLOCAL static const char *getStaticTypeName() 00092 { 00093 return "bool"; 00094 } 00095 00096 DLLLOCAL bool getValue() const 00097 { 00098 return b; 00099 } 00100 }; 00101 00103 00106 class QoreBoolTrueNode : public QoreBoolNode 00107 { 00108 public: 00109 DLLLOCAL QoreBoolTrueNode(); 00110 }; 00111 00113 00116 class QoreBoolFalseNode : public QoreBoolNode 00117 { 00118 public: 00119 DLLLOCAL QoreBoolFalseNode(); 00120 }; 00121 00123 DLLEXPORT extern QoreBoolFalseNode False; 00124 00126 DLLEXPORT extern QoreBoolTrueNode True; 00127 00129 static inline QoreBoolNode *get_bool_node(bool v) 00130 { 00131 return v ? (QoreBoolNode *)&True : (QoreBoolNode *)&False; 00132 } 00133 00134 #endif