Qt 4.8
Public Functions | Static Private Functions | Properties | List of all members
qLess< Item::List > Class Template Reference

Functor used by Qt's qSort() and qStableSort(). Used for FLWOR's order by expression. More...

Public Functions

bool operator() (const Item &item1, const Item &item2) const
 
 qLess (const OrderBy::OrderSpec::Vector &orderspecs, const DynamicContext::Ptr &context)
 

Static Private Functions

static bool isNaN (const Item &i)
 

Properties

const DynamicContext::Ptrm_context
 
const OrderBy::OrderSpec::Vectorm_orderSpecs
 

Detailed Description

template<>
class qLess< Item::List >

Functor used by Qt's qSort() and qStableSort(). Used for FLWOR's order by expression.

This must be in the global namespace, since it is specializing qLess(), which is in the global namespace. Hence it can't be in QPatternist.

Definition at line 85 of file qorderby.cpp.

Constructors and Destructors

◆ qLess()

qLess< Item::List >::qLess ( const OrderBy::OrderSpec::Vector orderspecs,
const DynamicContext::Ptr context 
)
inline

Definition at line 96 of file qorderby.cpp.

97  : m_orderSpecs(orderspecs)
98  , m_context(context)
99  {
101  Q_ASSERT(context);
102  }
const DynamicContext::Ptr & m_context
Definition: qorderby.cpp:165
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
const OrderBy::OrderSpec::Vector & m_orderSpecs
Definition: qorderby.cpp:164

Functions

◆ isNaN()

static bool qLess< Item::List >::isNaN ( const Item i)
inlinestaticprivate

Definition at line 89 of file qorderby.cpp.

90  {
91  return BuiltinTypes::xsDouble->xdtTypeMatches(i.type()) &&
92  i.as<Numeric>()->isNaN();
93  }
QExplicitlySharedDataPointer< ItemType > type() const
Returns the ItemType this Item is of.
Definition: qitem_p.h:365
Base class for all numeric values.
xsAnyAtomicType xsDouble
virtual bool isNaN() const =0
TCastTarget * as() const
Definition: qitem_p.h:278

◆ operator()()

bool qLess< Item::List >::operator() ( const Item item1,
const Item item2 
) const
inline

Definition at line 104 of file qorderby.cpp.

105  {
106  const SortTuple *const s1 = item1.as<SortTuple>();
107  const SortTuple *const s2 = item2.as<SortTuple>();
108 
109  const Item::Vector &sortKeys1 = s1->sortKeys();
110  const Item::Vector &sortKeys2 = s2->sortKeys();
111  const int len = sortKeys1.count();
112  Q_ASSERT(sortKeys1.count() == sortKeys2.count());
113 
114  for(int i = 0; i < len; ++i)
115  {
116  const Item &i1 = sortKeys1.at(i);
117  const Item &i2 = sortKeys2.at(i);
118  const OrderBy::OrderSpec &orderSpec = m_orderSpecs.at(i);
119 
120  if(!i1)
121  {
122  if(i2 && !isNaN(i2))
123  {
124  /* We got ((), item()). */
125  return orderSpec.orderingEmptySequence == StaticContext::Least ? orderSpec.direction == OrderBy::OrderSpec::Ascending
126  : orderSpec.direction != OrderBy::OrderSpec::Ascending;
127  }
128  else
129  return false;
130  }
131 
132  if(!i2)
133  {
134  if(i1 && !isNaN(i1))
135  /* We got (item(), ()). */
136  return orderSpec.orderingEmptySequence == StaticContext::Greatest ? orderSpec.direction == OrderBy::OrderSpec::Ascending
137  : orderSpec.direction != OrderBy::OrderSpec::Ascending;
138  else
139  return false;
140  }
141 
142  Q_ASSERT(orderSpec.direction == OrderBy::OrderSpec::Ascending ||
143  orderSpec.direction == OrderBy::OrderSpec::Descending);
144  const AtomicComparator::ComparisonResult result = orderSpec.detailedFlexibleCompare(i1, i2, m_context);
145 
146  switch(result)
147  {
149  return orderSpec.direction == OrderBy::OrderSpec::Ascending;
150  case AtomicComparator::GreaterThan:
151  return orderSpec.direction != OrderBy::OrderSpec::Ascending;
153  continue;
154  case AtomicComparator::Incomparable:
155  Q_ASSERT_X(false, Q_FUNC_INFO, "This code path assume values are always comparable.");
156  }
157  }
158 
159  return false;
160  }
static bool isNaN(const Item &i)
Definition: qorderby.cpp:89
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
const DynamicContext::Ptr & m_context
Definition: qorderby.cpp:165
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
StaticContext::OrderingEmptySequence orderingEmptySequence
Definition: qorderby_p.h:137
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
Represents a value and its sort keys in FLOWR&#39;s order by clause.
Definition: qsorttuple_p.h:81
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
const Item::Vector & sortKeys() const
Definition: qsorttuple_p.h:128
AtomicComparator::ComparisonResult detailedFlexibleCompare(const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
like flexibleCompare(), but returns the result as an AtomicComparator::Operator instead of bool...
TCastTarget * as() const
Definition: qitem_p.h:278
const OrderBy::OrderSpec::Vector & m_orderSpecs
Definition: qorderby.cpp:164
bool(* LessThan)(const QPair< QListWidgetItem *, int > &, const QPair< QListWidgetItem *, int > &)
Definition: qlistwidget.cpp:53
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Properties

◆ m_context

const DynamicContext::Ptr& qLess< Item::List >::m_context
private

Definition at line 165 of file qorderby.cpp.

◆ m_orderSpecs

const OrderBy::OrderSpec::Vector& qLess< Item::List >::m_orderSpecs
private

Definition at line 164 of file qorderby.cpp.


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