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

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

#include <qyearmonthduration_p.h>

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

Public Types

typedef AtomicValue::Ptr Ptr
 
- 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 YearMonthDuration::Ptr fromComponents (const bool isPositive, const YearProperty years, const MonthProperty months)
 
static YearMonthDuration::Ptr fromLexical (const QString &string)
 
- 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

 YearMonthDuration (const bool isPositive, const YearProperty years, const MonthProperty months)
 
- 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 MonthProperty m_months
 
const YearProperty m_years
 

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:yearMonthDuration type.

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

Definition at line 69 of file qyearmonthduration_p.h.

Typedefs

◆ Ptr

Definition at line 72 of file qyearmonthduration_p.h.

Constructors and Destructors

◆ YearMonthDuration()

YearMonthDuration::YearMonthDuration ( const bool  isPositive,
const YearProperty  years,
const MonthProperty  months 
)
protected

Definition at line 51 of file qyearmonthduration.cpp.

Referenced by fromComponents(), and fromLexical().

53  : AbstractDuration(isPositiveP),
54  m_years(yearsP),
55  m_months(monthsP)
56 {
57  Q_ASSERT(monthsP < 32 && monthsP > -32);
58 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Functions

◆ days()

DayCountProperty YearMonthDuration::days ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 160 of file qyearmonthduration.cpp.

161 {
162  return 0;
163 }

◆ fromComponents()

YearMonthDuration::Ptr YearMonthDuration::fromComponents ( const bool  isPositive,
const YearProperty  years,
const MonthProperty  months 
)
static

Definition at line 84 of file qyearmonthduration.cpp.

Referenced by QPatternist::AbstractDurationToYearMonthDurationCaster::castFrom(), and fromValue().

87 {
89 }
YearMonthDuration(const bool isPositive, const YearProperty years, const MonthProperty months)
virtual MonthProperty months() const
virtual YearProperty years() const

◆ fromLexical()

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

Creates an instance from the lexical representation string.

Definition at line 60 of file qyearmonthduration.cpp.

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

61 {
62  static const CaptureTable captureTable(
63  /* The extra paranthesis is a build fix for GCC 3.3. */
65  "^\\s*" /* Any preceding whitespace. */
66  "(-)?" /* Sign, if any. */
67  "P" /* Delimiter. */
68  "(?:(\\d+)Y)?" /* The years part. */
69  "(?:(\\d+)M)?" /* The months part. */
70  "\\s*$" /* Any terminating whitespace. */))),
71  2, /* yearP. */
72  3 /* monthP. */);
73 
74  YearProperty years = 0;
76  bool isPos;
77 
78  const AtomicValue::Ptr err(create(captureTable, lexical, &isPos, &years,
79  &months, 0, 0, 0, 0, 0));
80 
81  return err ? err : YearMonthDuration::Ptr(new YearMonthDuration(isPos, years, months));
82 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
YearMonthDuration(const bool isPositive, const YearProperty years, const MonthProperty months)
qint8 MonthProperty
qint32 YearProperty
virtual MonthProperty months() const
virtual YearProperty years() 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)

◆ fromValue()

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

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

Implements QPatternist::AbstractDuration.

Definition at line 132 of file qyearmonthduration.cpp.

133 {
134  if(val == 0)
136  else
137  {
138  const Value absValue = qAbs(val);
140  absValue / 12,
141  absValue % 12));
142  }
143 }
static const DayTimeDuration::Ptr YearMonthDurationZero
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
static YearMonthDuration::Ptr fromComponents(const bool isPositive, const YearProperty years, const MonthProperty months)
qint64 Value
The amount in milli seconds.

◆ hours()

HourProperty YearMonthDuration::hours ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 165 of file qyearmonthduration.cpp.

166 {
167  return 0;
168 }

◆ minutes()

MinuteProperty YearMonthDuration::minutes ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 170 of file qyearmonthduration.cpp.

171 {
172  return 0;
173 }

◆ months()

MonthProperty YearMonthDuration::months ( ) const
virtual
Returns
the months component. Always positive.

Implements QPatternist::AbstractDuration.

Definition at line 155 of file qyearmonthduration.cpp.

Referenced by fromLexical().

156 {
157  return m_months;
158 }

◆ mseconds()

MSecondProperty YearMonthDuration::mseconds ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 180 of file qyearmonthduration.cpp.

181 {
182  return 0;
183 }

◆ seconds()

SecondProperty YearMonthDuration::seconds ( ) const
virtual
Returns
always 0.

Implements QPatternist::AbstractDuration.

Definition at line 175 of file qyearmonthduration.cpp.

176 {
177  return 0;
178 }

◆ stringValue()

QString YearMonthDuration::stringValue ( ) const
virtual

Implements QPatternist::AtomicValue.

Definition at line 91 of file qyearmonthduration.cpp.

92 {
93  QString retval;
94 
95  if(!m_isPositive)
96  retval.append(QLatin1Char('-'));
97 
98  retval.append(QLatin1Char('P'));
99 
100  /* When years == 0 and months == 0, we get "P0M", which
101  * is the correct canonical form. */
102  if(m_years)
103  {
104  retval.append(QString::number(m_years));
105  retval.append(QLatin1Char('Y'));
106 
107  if(m_months)
108  {
110  retval.append(QLatin1Char('M'));
111  }
112  }
113  else
114  {
115  if(m_months)
116  {
118  retval.append(QLatin1Char('M'));
119  }
120  else
121  return QLatin1String("P0M"); /* Ensure the canonical form. */
122  }
123 
124  return retval;
125 }
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString & append(QChar c)
Definition: qstring.cpp:1777
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ type()

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

Implements QPatternist::AtomicValue.

Definition at line 145 of file qyearmonthduration.cpp.

146 {
148 }
static const AtomicType::Ptr xsYearMonthDuration

◆ value()

AbstractDuration::Value YearMonthDuration::value ( ) const
virtual
Returns
the value of this xs:yearMonthDuration in months.
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 127 of file qyearmonthduration.cpp.

128 {
129  return (m_years * 12 + m_months) * (m_isPositive ? 1 : -1);
130 }

◆ years()

YearProperty YearMonthDuration::years ( ) const
virtual
Returns
the years component. Always positive.

Implements QPatternist::AbstractDuration.

Definition at line 150 of file qyearmonthduration.cpp.

Referenced by fromLexical().

151 {
152  return m_years;
153 }

Friends and Related Functions

◆ CommonValues

friend class CommonValues
friend

Definition at line 135 of file qyearmonthduration_p.h.

Properties

◆ m_months

const MonthProperty QPatternist::YearMonthDuration::m_months
private

Definition at line 143 of file qyearmonthduration_p.h.

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

◆ m_years

const YearProperty QPatternist::YearMonthDuration::m_years
private

Definition at line 142 of file qyearmonthduration_p.h.

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


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