Qt 4.8
Public Functions | Protected Functions | List of all members
QPatternist::AdjustTimezone Class Referenceabstract

Base class for classes implementing functions changing the timezone on values. More...

#include <qtimezonefns_p.h>

Inheritance diagram for QPatternist::AdjustTimezone:
QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection QPatternist::AdjustDateTimeToTimezoneFN QPatternist::AdjustDateToTimezoneFN QPatternist::AdjustTimeToTimezoneFN

Public Functions

virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
- Public Functions inherited from QPatternist::FunctionCall
virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
virtual Expression::Properties properties () const
 
virtual void setSignature (const FunctionSignature::Ptr &sign)
 
virtual FunctionSignature::Ptr signature () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- Public Functions inherited from QPatternist::Expression
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- 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< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Protected Functions

virtual Item createValue (const QDateTime &dt) const =0
 
- Protected Functions inherited from QPatternist::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::FunctionCall
typedef QExplicitlySharedDataPointer< FunctionCallPtr
 
- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Base class for classes implementing functions changing the timezone on values.

It would be possible to implement this with the Curiously Recurring Template Pattern, in order to avoid the virtual call dispatching that is done via createValue(). However, these are not very hot code paths and evaluateSingleton() is quite large, which would lead to heavy code expansion.

See also
Curiously Recurring Template Pattern, Wikipedia, the free encyclopedia
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 86 of file qtimezonefns_p.h.

Functions

◆ createValue()

virtual Item QPatternist::AdjustTimezone::createValue ( const QDateTime dt) const
protectedpure virtual

◆ evaluateSingleton()

Item AdjustTimezone::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

The maximum zone offset, PT14H, in milli seconds.

Reimplemented from QPatternist::Expression.

Definition at line 56 of file qtimezonefns.cpp.

57 {
58  enum
59  {
63  MSecLimit = 14 * 60/*M*/ * 60/*S*/ * 1000/*ms*/
64  };
65 
66 
67  const Item arg(m_operands.first()->evaluateSingleton(context));
68  if(!arg)
69  return Item();
70 
71  QDateTime dt(arg.as<AbstractDateTime>()->toDateTime());
72  // TODO DT dt.setDateOnly(false);
73  Q_ASSERT(dt.isValid());
75 
76  if(m_operands.count() == 2)
78  else
79  tz = context->implicitTimezone();
80 
81  if(tz)
82  {
83  const MSecondCountProperty tzMSecs = tz->value();
84 
85  if(tzMSecs % (1000 * 60) != 0)
86  {
87  context->error(QtXmlPatterns::tr("A zone offset must be in the "
88  "range %1..%2 inclusive. %3 is "
89  "out of range.")
90  .arg(formatData("-PT14H"))
91  .arg(formatData("PT14H"))
92  .arg(formatData(tz->stringValue())),
94  return Item();
95  }
96  else if(tzMSecs > MSecLimit ||
97  tzMSecs < -MSecLimit)
98  {
99  context->error(QtXmlPatterns::tr("%1 is not a whole number of minutes.")
100  .arg(formatData(tz->stringValue())),
102  return Item();
103  }
104 
105  const SecondCountProperty tzSecs = tzMSecs / 1000;
106 
107  if(dt.timeSpec() == Qt::LocalTime) /* $arg has no time zone. */
108  {
109  /* "If $arg does not have a timezone component and $timezone is not
110  * the empty sequence, then the result is $arg with $timezone as
111  * the timezone component." */
112  //dt.setTimeSpec(QDateTime::Spec(QDateTime::OffsetFromUTC, tzSecs));
113  dt.setUtcOffset(tzSecs);
114  Q_ASSERT(dt.isValid());
115  return createValue(dt);
116  }
117  else
118  {
119  /* "If $arg has a timezone component and $timezone is not the empty sequence,
120  * then the result is an xs:dateTime value with a timezone component of
121  * $timezone that is equal to $arg." */
122  dt = dt.toUTC();
123  dt = dt.addSecs(tzSecs);
124  //dt.setTimeSpec(QDateTime::Spec(QDateTime::OffsetFromUTC, tzSecs));
125  dt.setUtcOffset(tzSecs);
126  Q_ASSERT(dt.isValid());
127  return createValue(dt);
128  }
129  }
130  else
131  { /* $timezone is the empty sequence. */
132  if(dt.timeSpec() == Qt::LocalTime) /* $arg has no time zone. */
133  {
134  /* "If $arg does not have a timezone component and $timezone is
135  * the empty sequence, then the result is $arg." */
136  return arg;
137  }
138  else
139  {
140  /* "If $arg has a timezone component and $timezone is the empty sequence,
141  * then the result is the localized value of $arg without its timezone component." */
142  dt.setTimeSpec(Qt::LocalTime);
143  return createValue(dt);
144  }
145  }
146 }
Base class for classes implementing values related to time, date or both.
virtual QExplicitlySharedDataPointer< DayTimeDuration > implicitTimezone() const =0
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const QDateTime & toDateTime() const
static QString formatData(const QString &data)
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
Implements the value instance of the xs:dayTimeDuration type.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual Item createValue(const QDateTime &dt) const =0
qint64 MSecondCountProperty
TCastTarget * as() const
Definition: qitem_p.h:278
qint32 SecondCountProperty
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

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