00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _QORE_DATETIMENODE_H
00026
00027 #define _QORE_DATETIMENODE_H
00028
00029 #include <qore/AbstractQoreNode.h>
00030 #include <qore/DateTime.h>
00031
00033 class DateTimeNode : public SimpleValueQoreNode, public DateTime
00034 {
00035 private:
00037 DLLLOCAL DateTimeNode(const DateTime *);
00038
00040 DLLLOCAL DateTimeNode& operator=(const DateTimeNode &);
00041
00043
00047 DLLEXPORT virtual bool getAsBoolImpl() const;
00048
00050
00053 DLLEXPORT virtual int getAsIntImpl() const;
00054
00056
00059 DLLEXPORT virtual int64 getAsBigIntImpl() const;
00060
00062
00065 DLLEXPORT virtual double getAsFloatImpl() const;
00066
00067 protected:
00069 DLLEXPORT virtual ~DateTimeNode();
00070
00071 public:
00073
00076 DLLEXPORT DateTimeNode(bool r = false);
00077
00079
00089 DLLEXPORT DateTimeNode(int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, short n_ms = 0, bool n_relative = false);
00090
00092
00095 DLLEXPORT DateTimeNode(int64 seconds);
00096
00098
00102 DLLEXPORT DateTimeNode(int64 seconds, int ms);
00103
00105
00108 DLLEXPORT DateTimeNode(const char *date);
00109
00111
00114 DLLEXPORT DateTimeNode(struct tm *tms);
00115
00117 DLLEXPORT DateTimeNode(const DateTimeNode &dt);
00118
00120 DLLEXPORT DateTimeNode(const DateTime &dt);
00121
00123
00128 DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
00129
00131
00134 DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
00135
00137
00141 DLLEXPORT virtual class DateTime *getDateTimeRepresentation(bool &del) const;
00142
00144
00147 DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
00148
00150
00159 DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, class ExceptionSink *xsink) const;
00160
00162
00169 DLLEXPORT virtual int getAsString(QoreString &str, int foff, class ExceptionSink *xsink) const;
00170
00171 DLLEXPORT virtual class AbstractQoreNode *realCopy() const;
00172
00174
00178 DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00179 DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
00180
00182 DLLEXPORT virtual const char *getTypeName() const;
00183
00184 DLLLOCAL static const char *getStaticTypeName()
00185 {
00186 return "date";
00187 }
00188
00190
00193 DLLEXPORT DateTimeNode *copy() const;
00194
00196
00199 DLLEXPORT DateTimeNode *add(const class DateTime *dt) const;
00200
00202
00205 DLLEXPORT DateTimeNode *subtractBy(const class DateTime *dt) const;
00206
00208
00215 DLLEXPORT static DateTimeNode *getDateFromISOWeek(int year, int week, int day, class ExceptionSink *xsink);
00216 };
00217
00218 DLLEXPORT extern DateTimeNode *ZeroDate;
00219
00221
00226 class DateTimeValueHelper {
00227 private:
00228 const DateTime *dt;
00229 bool del;
00230
00231 DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&);
00232 DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&);
00233 DLLLOCAL void *operator new(size_t);
00234
00235 public:
00237 DLLLOCAL DateTimeValueHelper(const AbstractQoreNode *n)
00238 {
00239
00240 if (n) {
00241 if (n->getType() == NT_DATE) {
00242 dt = reinterpret_cast<const DateTimeNode *>(n);
00243 del = false;
00244 }
00245 else
00246 dt = n->getDateTimeRepresentation(del);
00247 }
00248 else {
00249 dt = ZeroDate;
00250 del = false;
00251 }
00252 }
00253
00255 DLLLOCAL ~DateTimeValueHelper()
00256 {
00257 if (del)
00258 delete const_cast<DateTime *>(dt);
00259 }
00260 DLLLOCAL const DateTime *operator->() { return dt; }
00261 DLLLOCAL const DateTime *operator*() { return dt; }
00262 };
00263
00265
00268 class DateTimeNodeValueHelper {
00269 private:
00270 DateTimeNode *dt;
00271 bool temp;
00272
00273 DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&);
00274 DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&);
00275 DLLLOCAL void *operator new(size_t);
00276
00277 public:
00279 DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n)
00280 {
00281 if (!n) {
00282 dt = ZeroDate;
00283 temp = false;
00284 return;
00285 }
00286
00287
00288 if (n->getType() == NT_DATE) {
00289 dt = const_cast<DateTimeNode *>(reinterpret_cast<const DateTimeNode *>(n));
00290 temp = false;
00291 return;
00292 }
00293
00294 dt = new DateTimeNode();
00295 n->getDateTimeRepresentation(*dt);
00296 temp = true;
00297 }
00298
00300 DLLLOCAL ~DateTimeNodeValueHelper()
00301 {
00302 if (dt && temp)
00303 dt->deref();
00304 }
00305
00306 DLLLOCAL const DateTimeNode *operator->() { return dt; }
00307 DLLLOCAL const DateTimeNode *operator*() { return dt; }
00308
00310
00314 DLLLOCAL DateTimeNode *getReferencedValue()
00315 {
00316 if (temp)
00317 temp = false;
00318 else if (dt)
00319 dt->ref();
00320 return dt;
00321 }
00322 };
00323
00324 #endif