Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Properties | Friends | List of all members
QPatternist::DayTimeDuration Class Reference

Implements the value instance of the xs:dayTimeDuration type. More...

#include <qdaytimeduration_p.h>

Inheritance diagram for QPatternist::DayTimeDuration:
QPatternist::AbstractDuration QPatternist::AtomicValue QSharedData QPatternist::CppCastingHelper< AtomicValue >

Public Types

typedef QExplicitlySharedDataPointer< DayTimeDurationPtr
 
- Public Types inherited from QPatternist::AbstractDuration
typedef QExplicitlySharedDataPointer< AbstractDurationPtr
 
typedef qint64 Value
 The amount in milli seconds. More...
 
- Public Types inherited from QPatternist::AtomicValue
typedef QList< AtomicValue::PtrList
 
typedef QExplicitlySharedDataPointer< AtomicValuePtr
 

Public Functions

virtual DayCountProperty days () const
 
virtual Item fromValue (const Value val) const
 
virtual HourProperty hours () const
 
virtual MinuteProperty minutes () const
 
virtual MonthProperty months () const
 
virtual MSecondProperty mseconds () const
 
virtual SecondProperty seconds () const
 
virtual QString stringValue () const
 
virtual ItemType::Ptr type () const
 
virtual Value value () const
 
virtual YearProperty years () const
 
- Public Functions inherited from QPatternist::AbstractDuration
bool isPositive () const
 
bool operator== (const AbstractDuration &other) const
 
- Public Functions inherited from QPatternist::AtomicValue
virtual bool evaluateEBV (const QExplicitlySharedDataPointer< DynamicContext > &context) const
 
virtual bool hasError () const
 
virtual ~AtomicValue ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
const TCastTarget * as () const
 
TCastTarget * as ()
 

Static Public Functions

static DayTimeDuration::Ptr fromComponents (const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
 
static DayTimeDuration::Ptr fromLexical (const QString &string)
 
static DayTimeDuration::Ptr fromSeconds (const SecondCountProperty secs, const MSecondProperty msecs=0)
 
- Static Public Functions inherited from QPatternist::AtomicValue
static ItemType::Ptr qtToXDMType (const QXmlItem &item)
 
static QVariant toQt (const AtomicValue *const value)
 
static QVariant toQt (const AtomicValue::Ptr &value)
 
static Item toXDM (const QVariant &value)
 

Protected Functions

 DayTimeDuration (const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
 
- Protected Functions inherited from QPatternist::AbstractDuration
 AbstractDuration (const bool isPos)
 
- Protected Functions inherited from QPatternist::AtomicValue
 AtomicValue ()
 
- Protected Functions inherited from QPatternist::CppCastingHelper< AtomicValue >
 CppCastingHelper ()
 

Properties

const DayCountProperty m_days
 
const HourProperty m_hours
 
const MinuteProperty m_minutes
 
const MSecondProperty m_mseconds
 
const SecondProperty m_seconds
 

Friends

class CommonValues
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Static Protected Functions inherited from QPatternist::AbstractDuration
static AtomicValue::Ptr create (const CaptureTable &captTable, const QString &lexical, bool *isPositive, YearProperty *years, MonthProperty *months, DayCountProperty *days, HourProperty *hours, MinuteProperty *minutes, SecondProperty *seconds, MSecondProperty *mseconds)
 
static QString serializeMSeconds (const MSecondProperty mseconds)
 
- Protected Variables inherited from QPatternist::AbstractDuration
const bool m_isPositive
 

Detailed Description

Implements the value instance of the xs:dayTimeDuration type.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 70 of file qdaytimeduration_p.h.

Typedefs

◆ Ptr

Definition at line 74 of file qdaytimeduration_p.h.

Constructors and Destructors

◆ DayTimeDuration()

DayTimeDuration::DayTimeDuration ( const bool  isPositive,
const DayCountProperty  days,
const HourProperty  hours,
const MinuteProperty  minutes,
const SecondProperty  seconds,
const MSecondProperty  mseconds 
)
protected

Definition at line 52 of file qdaytimeduration.cpp.

Referenced by fromComponents(), fromLexical(), and fromSeconds().

57  : AbstractDuration(isPositiveP),
58  m_days(daysP),
59  m_hours(hoursP),
60  m_minutes(minutesP),
61  m_seconds(secs),
62  m_mseconds(msecs)
63 {
64 }
const DayCountProperty m_days
const SecondProperty m_seconds
const MinuteProperty m_minutes
const MSecondProperty m_mseconds

Functions

◆ days()

DayCountProperty DayTimeDuration::days ( ) const
virtual

Implements QPatternist::AbstractDuration.

Definition at line 217 of file qdaytimeduration.cpp.

Referenced by fromLexical(), and fromSeconds().

218 {
219  return m_days;
220 }
const DayCountProperty m_days

◆ fromComponents()

DayTimeDuration::Ptr DayTimeDuration::fromComponents ( const bool  isPositive,
const DayCountProperty  days,
const HourProperty  hours,
const MinuteProperty  minutes,
const SecondProperty  seconds,
const MSecondProperty  mseconds 
)
static

Definition at line 104 of file qdaytimeduration.cpp.

Referenced by QPatternist::AbstractDurationToDayTimeDurationCaster::castFrom().

110 {
112  days,
113  hours,
114  minutes,
115  seconds,
116  mseconds));
117 }
virtual SecondProperty seconds() const
DayTimeDuration(const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
QExplicitlySharedDataPointer< DayTimeDuration > Ptr
virtual HourProperty hours() const
virtual MinuteProperty minutes() const
virtual DayCountProperty days() const
virtual MSecondProperty mseconds() const

◆ fromLexical()

DayTimeDuration::Ptr DayTimeDuration::fromLexical ( const QString string)
static

Creates an instance from the lexical representation string.

Definition at line 66 of file qdaytimeduration.cpp.

Referenced by QPatternist::StringToDayTimeDurationCaster::castFrom().

67 {
68  static const CaptureTable captureTable(
69  /* The extra paranthesis is a build fix for GCC 3.3. */
71  "^\\s*" /* Any preceding whitespace. */
72  "(-)?" /* Any minus sign. */
73  "P" /* Delimiter. */
74  "(?:(\\d+)D)?" /* Day part. */
75  "(?:" /* Here starts the optional time part. */
76  "(T)" /* SchemaTime delimiter. */
77  "(?:(\\d+)H)?" /* Hour part. */
78  "(?:(\\d+)M)?" /* Minute part. */
79  "(?:(\\d+)(?:\\.(\\d+))?S)?" /* Seconds & milli seconds. */
80  ")?" /* End of optional time part. */
81  "\\s*$" /* Any terminating whitespace. */))),
82  /*yearP*/ -1,
83  /*monthP*/ -1,
84  /*dayP*/ 2,
85  /*tDelimiterP*/ 3,
86  /*hourP*/ 4,
87  /*minutesP*/ 5,
88  /*secondsP*/ 6,
89  /*msecondsP*/ 7);
90 
92  HourProperty hours = 0;
94  SecondProperty sec = 0;
95  MSecondProperty msec = 0;
96  bool isPos;
97 
98  const DayTimeDuration::Ptr err(create(captureTable, lexical, &isPos, 0, 0, &days,
99  &hours, &minutes, &sec, &msec));
100  return err ? err : DayTimeDuration::Ptr(new DayTimeDuration(isPos, days, hours, minutes,
101  sec, msec));
102 }
qint32 DayCountProperty
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
qint8 MinuteProperty
qint32 SecondProperty
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
qint8 HourProperty
DayTimeDuration(const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
QExplicitlySharedDataPointer< DayTimeDuration > Ptr
virtual HourProperty hours() const
virtual MinuteProperty minutes() const
static AtomicValue::Ptr create(const CaptureTable &captTable, const QString &lexical, bool *isPositive, YearProperty *years, MonthProperty *months, DayCountProperty *days, HourProperty *hours, MinuteProperty *minutes, SecondProperty *seconds, MSecondProperty *mseconds)
qint16 MSecondProperty
virtual DayCountProperty days() const

◆ fromSeconds()

DayTimeDuration::Ptr DayTimeDuration::fromSeconds ( const SecondCountProperty  secs,
const MSecondProperty  msecs = 0 
)
static

Creates a DayTimeDuration that has the value expressed in seconds secs and milli seconds msecs. The signedness of secs communicates whether this DayTimeDuration is positive or negative. msecs must always be positive.

Definition at line 119 of file qdaytimeduration.cpp.

Referenced by QPatternist::AbstractDateTimeMathematician::calculate(), and fromValue().

121 {
122  Q_ASSERT(msecs >= 0);
123  const SecondCountProperty source = qAbs(sourceSecs);
124  const bool isPos = sourceSecs >= 0;
125  const SecondCountProperty secs = source % 60;
126  const MinuteCountProperty mins = (source / 60) % 60;
127  const HourCountProperty hours = source / (60 * 60) % 24;
128  const DayCountProperty days = source / (60 * 60) / 24;
129 
130  return DayTimeDuration::Ptr(new DayTimeDuration(isPos, days, hours, mins, secs, msecs));
131 }
qint32 DayCountProperty
qint32 MinuteCountProperty
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
DayTimeDuration(const bool isPositive, const DayCountProperty days, const HourProperty hours, const MinuteProperty minutes, const SecondProperty seconds, const MSecondProperty mseconds)
QExplicitlySharedDataPointer< DayTimeDuration > Ptr
virtual HourProperty hours() const
qint32 HourCountProperty
virtual DayCountProperty days() const
qint32 SecondCountProperty

◆ fromValue()

Item DayTimeDuration::fromValue ( const Value  val) const
virtual

Creates a DayTimeDuration containing the value val. val is expressed in milli seconds.

If val is zero, is CommonValues::DayTimeDurationZero returned.

Implements QPatternist::AbstractDuration.

Definition at line 194 of file qdaytimeduration.cpp.

195 {
196  if(val == 0)
198  else
199  return toItem(fromSeconds(val / 1000, qAbs(val) % 1000));
200 }
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
static DayTimeDuration::Ptr fromSeconds(const SecondCountProperty secs, const MSecondProperty msecs=0)
static const DayTimeDuration::Ptr DayTimeDurationZero

◆ hours()

HourProperty DayTimeDuration::hours ( ) const
virtual

Implements QPatternist::AbstractDuration.

Definition at line 222 of file qdaytimeduration.cpp.

Referenced by fromLexical(), and fromSeconds().

223 {
224  return m_hours;
225 }

◆ minutes()

MinuteProperty DayTimeDuration::minutes ( ) const
virtual

Implements QPatternist::AbstractDuration.

Definition at line 227 of file qdaytimeduration.cpp.

Referenced by fromLexical().

228 {
229  return m_minutes;
230 }
const MinuteProperty m_minutes

◆ months()

MonthProperty DayTimeDuration::months ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 212 of file qdaytimeduration.cpp.

213 {
214  return 0;
215 }

◆ mseconds()

MSecondProperty DayTimeDuration::mseconds ( ) const
virtual

Implements QPatternist::AbstractDuration.

Definition at line 237 of file qdaytimeduration.cpp.

238 {
239  return m_mseconds;
240 }
const MSecondProperty m_mseconds

◆ seconds()

SecondProperty DayTimeDuration::seconds ( ) const
virtual

Implements QPatternist::AbstractDuration.

Definition at line 232 of file qdaytimeduration.cpp.

233 {
234  return m_seconds;
235 }
const SecondProperty m_seconds

◆ stringValue()

QString DayTimeDuration::stringValue ( ) const
virtual

Implements QPatternist::AtomicValue.

Definition at line 133 of file qdaytimeduration.cpp.

134 {
135  QString retval;
136 
137  if(!m_isPositive)
138  retval.append(QLatin1Char('-'));
139 
140  retval.append(QLatin1Char('P'));
141 
142  if(m_days)
143  {
144  retval.append(QString::number(m_days));
145  retval.append(QLatin1Char('D'));
146  }
147 
148  if(!m_hours && !m_minutes && !m_seconds && !m_seconds)
149  {
150  if(!m_days)
151  return QLatin1String("PT0S");
152  else
153  return retval;
154  }
155 
156  retval.append(QLatin1Char('T'));
157 
158  if(m_hours)
159  {
160  retval.append(QString::number(m_hours));
161  retval.append(QLatin1Char('H'));
162  }
163 
164  if(m_minutes)
165  {
167  retval.append(QLatin1Char('M'));
168  }
169 
170  if(m_seconds || m_seconds)
171  {
173 
174  if(m_mseconds)
176 
177  retval.append(QLatin1Char('S'));
178  }
179  else if(!m_days && !m_hours && !m_minutes)
180  retval.append(QLatin1String("0S"));
181 
182  return retval;
183 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const DayCountProperty m_days
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & append(QChar c)
Definition: qstring.cpp:1777
const SecondProperty m_seconds
const MinuteProperty m_minutes
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const MSecondProperty m_mseconds
static QString serializeMSeconds(const MSecondProperty mseconds)

◆ type()

ItemType::Ptr DayTimeDuration::type ( ) const
virtual

Implements QPatternist::AtomicValue.

Definition at line 202 of file qdaytimeduration.cpp.

203 {
205 }
static const AtomicType::Ptr xsDayTimeDuration

◆ value()

AbstractDuration::Value DayTimeDuration::value ( ) const
virtual
Returns
the value of this xs:dayTimeDuration in milli seconds.
See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 10.3.2.2 Calculating the value of a xs:dayTimeDuration from the lexical representation

Implements QPatternist::AbstractDuration.

Definition at line 185 of file qdaytimeduration.cpp.

186 {
187  return ((m_days * 24 * 60 * 60 * 1000) +
188  (m_hours * 60 * 60 * 1000) +
189  (m_minutes * 60 * 1000) +
190  (m_seconds * 1000) +
191  m_mseconds) * (m_isPositive ? 1 : -1);
192 }
const DayCountProperty m_days
const SecondProperty m_seconds
const MinuteProperty m_minutes
const MSecondProperty m_mseconds

◆ years()

YearProperty DayTimeDuration::years ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 207 of file qdaytimeduration.cpp.

208 {
209  return 0;
210 }

Friends and Related Functions

◆ CommonValues

friend class CommonValues
friend

Definition at line 132 of file qdaytimeduration_p.h.

Properties

◆ m_days

const DayCountProperty QPatternist::DayTimeDuration::m_days
private

Definition at line 142 of file qdaytimeduration_p.h.

Referenced by days(), stringValue(), and value().

◆ m_hours

const HourProperty QPatternist::DayTimeDuration::m_hours
private

Definition at line 143 of file qdaytimeduration_p.h.

Referenced by hours(), stringValue(), and value().

◆ m_minutes

const MinuteProperty QPatternist::DayTimeDuration::m_minutes
private

Definition at line 144 of file qdaytimeduration_p.h.

Referenced by minutes(), stringValue(), and value().

◆ m_mseconds

const MSecondProperty QPatternist::DayTimeDuration::m_mseconds
private

Definition at line 146 of file qdaytimeduration_p.h.

Referenced by mseconds(), stringValue(), and value().

◆ m_seconds

const SecondProperty QPatternist::DayTimeDuration::m_seconds
private

Definition at line 145 of file qdaytimeduration_p.h.

Referenced by seconds(), stringValue(), and value().


The documentation for this class was generated from the following files: