Qore Programming Language - C/C++ Library  0.8.12.2
 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 (C) 2003 - 2015 David Nichols
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_DATETIMENODE_H
35 
36 #define _QORE_DATETIMENODE_H
37 
38 #include <qore/AbstractQoreNode.h>
39 #include <qore/DateTime.h>
40 
41 class qore_date_private;
42 
44 class DateTimeNode : public SimpleValueQoreNode, public DateTime {
45 private:
47  DLLLOCAL DateTimeNode(const DateTime* );
48 
50  DLLLOCAL DateTimeNode& operator=(const DateTimeNode&);
51 
53 
57  DLLEXPORT virtual bool getAsBoolImpl() const;
58 
60 
63  DLLEXPORT virtual int getAsIntImpl() const;
64 
66 
69  DLLEXPORT virtual int64 getAsBigIntImpl() const;
70 
72 
75  DLLEXPORT virtual double getAsFloatImpl() const;
76 
78  DLLLOCAL DateTimeNode(qore_date_private* n_priv);
79 
80 protected:
82  DLLEXPORT virtual ~DateTimeNode();
83 
84 public:
86 
89  DLLEXPORT DateTimeNode(bool r = false);
90 
92 
102  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);
103 
105 
108  DLLEXPORT DateTimeNode(int64 seconds);
109 
111 
115  DLLEXPORT DateTimeNode(int64 seconds, int ms);
116 
118 
124  DLLEXPORT explicit DateTimeNode(const AbstractQoreZoneInfo* zone, const QoreValue v);
125 
127 
130  DLLEXPORT explicit DateTimeNode(const QoreValue v);
131 
133 
135  DLLEXPORT DateTimeNode(const char* date);
136 
138 
142  DLLEXPORT DateTimeNode(const AbstractQoreZoneInfo* zone, const char* date);
143 
145 
148  DLLEXPORT DateTimeNode(struct tm* tms);
149 
151  DLLEXPORT DateTimeNode(const DateTimeNode& dt);
152 
154  DLLEXPORT DateTimeNode(const DateTime& dt);
155 
157 
162  DLLEXPORT virtual QoreString* getStringRepresentation(bool& del) const;
163 
165 
168  DLLEXPORT virtual void getStringRepresentation(QoreString& str) const;
169 
171 
175  DLLEXPORT virtual DateTime* getDateTimeRepresentation(bool& del) const;
176 
178 
181  DLLEXPORT virtual void getDateTimeRepresentation(DateTime& dt) const;
182 
184 
193  DLLEXPORT virtual QoreString* getAsString(bool& del, int foff, ExceptionSink* xsink) const;
194 
196 
203  DLLEXPORT virtual int getAsString(QoreString& str, int foff, ExceptionSink* xsink) const;
204 
205  DLLEXPORT virtual AbstractQoreNode* realCopy() const;
206 
208 
212  DLLEXPORT virtual bool is_equal_soft(const AbstractQoreNode* v, ExceptionSink* xsink) const;
213  DLLEXPORT virtual bool is_equal_hard(const AbstractQoreNode* v, ExceptionSink* xsink) const;
214 
216  DLLEXPORT virtual const char* getTypeName() const;
217 
219 
222  DLLEXPORT DateTimeNode* copy() const;
223 
225 
228  DLLEXPORT DateTimeNode* add(const DateTime* dt) const;
229 
231 
234  DLLEXPORT DateTimeNode* add(const DateTime& dt) const;
235 
237 
240  DLLEXPORT DateTimeNode* subtractBy(const DateTime* dt) const;
241 
243 
246  DLLEXPORT DateTimeNode* subtractBy(const DateTime& dt) const;
247 
249  DLLEXPORT DateTimeNode* unaryMinus() const;
250 
252  DLLEXPORT DateTimeNode* refSelf() const;
253 
255  DLLLOCAL static const char* getStaticTypeName() {
256  return "date";
257  }
258 
260  DLLLOCAL static qore_type_t getStaticTypeCode() {
261  return NT_DATE;
262  }
263 
265 
272  DLLEXPORT static DateTimeNode* getDateFromISOWeek(int year, int week, int day, ExceptionSink* xsink);
273 
275  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);
276 
278 
283  DLLEXPORT static DateTimeNode* makeAbsolute(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
284 
286 
291  DLLEXPORT static DateTimeNode* makeAbsoluteLocal(const AbstractQoreZoneInfo* zone, int64 seconds, int us = 0);
292 
294  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);
295 
297  DLLEXPORT static DateTimeNode* makeRelativeFromSeconds(int64 n_second, int n_us = 0);
298 };
299 
300 DLLEXPORT extern DateTimeNode* ZeroDate;
301 DLLEXPORT extern DateTimeNode* OneDate;
302 
304 
310 private:
311  const DateTime* dt;
312  bool del;
313 
314  DLLLOCAL DateTimeValueHelper(const DateTimeValueHelper&); // not implemented
315  DLLLOCAL DateTimeValueHelper& operator=(const DateTimeValueHelper&); // not implemented
316  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
317 
318 public:
320  DLLEXPORT DateTimeValueHelper(const AbstractQoreNode* n);
321 
323  DLLEXPORT DateTimeValueHelper(const QoreValue& n);
324 
326  DLLEXPORT ~DateTimeValueHelper();
327 
328  DLLLOCAL const DateTime* operator->() { return dt; }
329  DLLLOCAL const DateTime* operator*() { return dt; }
330 };
331 
333 
337 private:
338  DateTimeNode* dt;
339  bool temp;
340 
341  DLLLOCAL DateTimeNodeValueHelper(const DateTimeNodeValueHelper&); // not implemented
342  DLLLOCAL DateTimeNodeValueHelper& operator=(const DateTimeNodeValueHelper&); // not implemented
343  DLLLOCAL void* operator new(size_t); // not implemented, make sure it is not new'ed
344 
345 public:
348  if (!n) {
349  dt = ZeroDate;
350  temp = false;
351  return;
352  }
353 
354  // optmization without virtual function call for most common case
355  if (n->getType() == NT_DATE) {
356  dt = const_cast<DateTimeNode* >(reinterpret_cast<const DateTimeNode* >(n));
357  temp = false;
358  return;
359  }
360 
361  dt = new DateTimeNode();
363  temp = true;
364  }
365 
368  if (dt && temp)
369  dt->deref();
370  }
371 
372  DLLLOCAL const DateTimeNode* operator->() { return dt; }
373  DLLLOCAL const DateTimeNode* operator*() { return dt; }
374 
376 
381  if (temp)
382  temp = false;
383  else if (dt)
384  dt->ref();
385  return dt;
386  }
387 };
388 
389 #endif
DLLLOCAL DateTimeNodeValueHelper(const AbstractQoreNode *n)
gets the DateTimeNode value and sets the temporary flag
Definition: DateTimeNode.h:347
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
virtual DLLEXPORT AbstractQoreNode * realCopy() const
returns a copy of the object; the caller owns the reference count
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:93
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
static DLLEXPORT DateTimeNode * makeRelativeFromSeconds(int64 n_second, int n_us=0)
static &quot;constructor&quot; to create a relative time, including microseconds
DLLLOCAL ~DateTimeNodeValueHelper()
dereferences the DateTimeNode value if necessary
Definition: DateTimeNode.h:367
const qore_type_t NT_DATE
type value for DateTimeNode
Definition: node_types.h:46
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:255
DLLEXPORT DateTimeNode * refSelf() const
returns this with an incremented ref count
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...
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
static DLLLOCAL qore_type_t getStaticTypeCode()
returns the type code (useful in templates)
Definition: DateTimeNode.h:260
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a simple DateTime value is requir...
Definition: DateTimeNode.h:309
Qore&#39;s parse tree/value type for date-time values, reference-counted, dynamically-allocated only...
Definition: DateTimeNode.h:44
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:43
virtual DLLEXPORT QoreString * getStringRepresentation(bool &del) const
returns a string in the format YYYYMMDDHHmmSS, del is set to true
DLLEXPORT ~DateTimeValueHelper()
deletes the DateTime value being managed if necessary
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:228
manages calls to AbstractQoreNode::getDateTimeRepresentation() when a DateTimeNode value is required ...
Definition: DateTimeNode.h:336
DLLLOCAL qore_type_t getType() const
returns the data type
Definition: AbstractQoreNode.h:297
DLLLOCAL DateTimeNode * getReferencedValue()
returns a referenced value - the caller will own the reference
Definition: DateTimeNode.h:380
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...
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode) ...
Definition: common.h:68
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:435
DLLEXPORT DateTimeNode * copy() const
returns a copy of the DateTimeNode, the caller owns the pointer&#39;s reference count ...
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