Qore Programming Language  0.8.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DateTimeNode.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  DateTimeNode.h
4 
5  DateTimeNode Class Definition
6 
7  Qore Programming Language
8 
9  Copyright 2003 - 2013 David Nichols
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 2.1 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25 
26 #ifndef _QORE_DATETIMENODE_H
27 
28 #define _QORE_DATETIMENODE_H
29 
30 #include <qore/AbstractQoreNode.h>
31 #include <qore/DateTime.h>
32 
33 class qore_date_private;
34 
36 class DateTimeNode : public SimpleValueQoreNode, public DateTime {
37 private:
39  DLLLOCAL DateTimeNode(const DateTime *);
40 
42  DLLLOCAL DateTimeNode& operator=(const DateTimeNode &);
43 
45 
49  DLLEXPORT virtual bool getAsBoolImpl() const;
50 
52 
55  DLLEXPORT virtual int getAsIntImpl() const;
56 
58 
61  DLLEXPORT virtual int64 getAsBigIntImpl() const;
62 
64 
67  DLLEXPORT virtual double getAsFloatImpl() const;
68 
70  DLLLOCAL DateTimeNode(qore_date_private *n_priv);
71 
72 protected:
74  DLLEXPORT virtual ~DateTimeNode();
75 
76 public:
78 
81  DLLEXPORT DateTimeNode(bool r = false);
82 
84 
94  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);
95 
97 
100  DLLEXPORT DateTimeNode(int64 seconds);
101 
103 
107  DLLEXPORT DateTimeNode(int64 seconds, int ms);
108 
110 
112  DLLEXPORT DateTimeNode(const char *date);
113 
115 
118  DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo *zone, const char *date);
119 
121 
124  DLLEXPORT DateTimeNode(struct tm *tms);
125 
127  DLLEXPORT DateTimeNode(const DateTimeNode &dt);
128 
130  DLLEXPORT DateTimeNode(const DateTime &dt);
131 
133 
138  DLLEXPORT virtual QoreString *getStringRepresentation(bool &del) const;
139 
141 
144  DLLEXPORT virtual void getStringRepresentation(QoreString &str) const;
145 
147 
151  DLLEXPORT virtual DateTime *getDateTimeRepresentation(bool &del) const;
152 
154 
157  DLLEXPORT virtual void getDateTimeRepresentation(DateTime &dt) const;
158 
160 
169  DLLEXPORT virtual QoreString *getAsString(bool &del, int foff, ExceptionSink *xsink) const;
170 
172 
179  DLLEXPORT virtual int getAsString(QoreString &str, int foff, ExceptionSink *xsink) const;
180 
181  DLLEXPORT virtual class AbstractQoreNode *realCopy() const;
182 
184 
188  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const;
189  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode *v, ExceptionSink *xsink) const;
190 
192  DLLEXPORT virtual const char *getTypeName() const;
193 
195 
198  DLLEXPORT DateTimeNode *copy() const;
199 
201 
204  DLLEXPORT DateTimeNode *add(const DateTime *dt) const;
205 
207 
210  DLLEXPORT DateTimeNode *subtractBy(const DateTime *dt) const;
211 
213  DLLEXPORT DateTimeNode *unaryMinus() const;
214 
216  DLLLOCAL static const char *getStaticTypeName() {
217  return "date";
218  }
219 
221  DLLLOCAL static qore_type_t getStaticTypeCode() {
222  return NT_DATE;
223  }
224 
226 
233  DLLEXPORT static DateTimeNode *getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink);
234 
236  DLLEXPORT static DateTimeNode *makeAbsolute(const AbstractQoreZoneInfo *n_zone, int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, int n_us = 0);
237 
239 
244  DLLEXPORT static DateTimeNode *makeAbsolute(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
245 
247 
252  DLLEXPORT static DateTimeNode *makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us = 0);
253 
255  DLLEXPORT static DateTimeNode *makeRelative(int n_year, int n_month, int n_day, int n_hour = 0, int n_minute = 0, int n_second = 0, int n_us = 0);
256 };
257 
258 DLLEXPORT extern DateTimeNode *ZeroDate;
259 
261 
267 private:
268  const DateTime *dt;
269  bool del;
270 
271  DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&); // not implemented
272  DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&); // not implemented
273  DLLLOCAL void *operator new(size_t); // not implemented, make sure it is not new'ed
274 
275 public:
278  // optmization without virtual function call for most common case
279  if (n) {
280  if (n->getType() == NT_DATE) {
281  dt = reinterpret_cast<const DateTimeNode *>(n);
282  del = false;
283  }
284  else
285  dt = n->getDateTimeRepresentation(del);
286  }
287  else {
288  dt = ZeroDate;
289  del = false;
290  }
291  }
292 
294  DLLLOCAL ~DateTimeValueHelper() {
295  if (del)
296  delete const_cast<DateTime *>(dt);
297  }
298  DLLLOCAL const DateTime *operator->() { return dt; }
299  DLLLOCAL const DateTime *operator*() { return dt; }
300 };
301 
303 
307 private:
308  DateTimeNode *dt;
309  bool temp;
310 
311  DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&); // not implemented
312  DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&); // not implemented
313  DLLLOCAL void *operator new(size_t); // not implemented, make sure it is not new'ed
314 
315 public:
318  if (!n) {
319  dt = ZeroDate;
320  temp = false;
321  return;
322  }
323 
324  // optmization without virtual function call for most common case
325  if (n->getType() == NT_DATE) {
326  dt = const_cast<DateTimeNode *>(reinterpret_cast<const DateTimeNode *>(n));
327  temp = false;
328  return;
329  }
330 
331  dt = new DateTimeNode();
333  temp = true;
334  }
335 
338  if (dt && temp)
339  dt->deref();
340  }
341 
342  DLLLOCAL const DateTimeNode *operator->() { return dt; }
343  DLLLOCAL const DateTimeNode *operator*() { return dt; }
344 
346 
351  if (temp)
352  temp = false;
353  else if (dt)
354  dt->ref();
355  return dt;
356  }
357 };
358 
359 #endif
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n)
gets the DateTimeNode value and sets the temporary flag
Definition: DateTimeNode.h:317
static DLLEXPORT DateTimeNode * makeRelative(int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0)
static &quot;constructor&quot; to create a relative time, including microseconds
DLLLOCAL DateTimeValueHelper(const AbstractQoreNode *n)
gets the DateTime value and set the delete flag
Definition: DateTimeNode.h:277
DLLEXPORT DateTimeNode * unaryMinus() const
returns the negative time from the current time
virtual DLLEXPORT bool is_equal_soft(const AbstractQoreNode *v, ExceptionSink *xsink) const
tests for equality with possible type conversion (soft compare)
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...
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
DLLLOCAL ~DateTimeNodeValueHelper()
dereferences the DateTimeNode value if necessary
Definition: DateTimeNode.h:337
const qore_type_t NT_DATE
type value for DateTimeNode
Definition: node_types.h:38
virtual DLLEXPORT class DateTime * getDateTimeRepresentation(bool &del) const
returns the DateTime representation of this type (default implementation: returns ZeroDate...
static DLLLOCAL const char * getStaticTypeName()
returns the type name (useful in templates)
Definition: DateTimeNode.h:216
DLLEXPORT DateTimeNode * add(const DateTime *dt) const
adds a DateTime value to the current value and returns the new value, the caller owns the pointer&#39;s r...
virtual DLLEXPORT ~DateTimeNode()
protected destructor only called when references = 0, use deref() instead
DLLEXPORT DateTimeNode * subtractBy(const DateTime *dt) const
subtracts a DateTime value from the current value and returns the new value, the caller owns the poin...
signed short qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:59
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: DateTimeNode.h:221
virtual DLLEXPORT class AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a simple DateTime value is requir...
Definition: DateTimeNode.h:266
Qore&#39;s parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:36
virtual DLLEXPORT const char * getTypeName() const
returns the type name as a c string
virtual DLLEXPORT DateTime * getDateTimeRepresentation(bool &del) const
returns &quot;this&quot; as a DateTime, del is set to false
virtual DLLEXPORT QoreString * getAsString(bool &del, int foff, ExceptionSink *xsink) const
returns the date/time value as a formatted string for n and N printf formatting, del is set to true ...
DLLEXPORT void ref() const
increments the reference count
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns a string in the format YYYYMMDDHHmmSS, del is set to true
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a DateTimeNode value is required ...
Definition: DateTimeNode.h:306
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:286
DLLLOCAL DateTimeNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: DateTimeNode.h:350
static DLLEXPORT DateTimeNode * makeAbsoluteLocal(const AbstractQoreZoneInfo *zone, int64 seconds, int us=0)
static &quot;constructor&quot; to create an absolute time as an offset from the given time zone&#39;s epoch...
static DLLEXPORT DateTimeNode * getDateFromISOWeek(int year, int week, int day, ExceptionSink *xsink)
returns a DateTimeNode value as generated from the ISO-8601 week information
base class for simple value types
Definition: AbstractQoreNode.h:417
DLLEXPORT DateTimeNode * copy() const
returns a copy of the DateTimeNode, the caller owns the pointer&#39;s reference count ...
DLLLOCAL ~DateTimeValueHelper()
deletes the DateTime value being managed if necessary
Definition: DateTimeNode.h:294
static DLLEXPORT DateTimeNode * makeAbsolute(const AbstractQoreZoneInfo *n_zone, int n_year, int n_month, int n_day, int n_hour=0, int n_minute=0, int n_second=0, int n_us=0)
static &quot;constructor&quot; to create an absolute time, including microseconds