Module Ordered
A module for adding getNext(), getPrevious() members to a type that is in some way
orderable, in optional groups.
For instance, variables in a file may be ordered by their line number and grouped by their file.
To use this module, extend the class Ordered<T>::Type or Ordered<T>::GroupBy<G>::Type,
where T is the type you want to order (for instance, a variable) and G is the optional type
you want to group by (for instance, a file name). You must also implement the member predicate
int getOrder() (items will be ordered by the result of this predicate) and if relevant, the
member G getGroup().
The member getOrder() must not have duplicate values for two items within the same group to
ensure correctness.
Example grouped usage:
class OrderedVar extends Ordered<Variable>::GroupBy<File>::Type {
override int getOrder() { result = this.getLocation().getStartLine() }
override File getGroup() { result = this.getFile() }
}
// Selects all variables in a file, along with the previous and next.
from OrderedVar v
select v.getName(), v.getPrevious().getName(), v.getNext().getName()
Example ungrouped usage:
class OrderedFib extends Ordered<int>::Type {
OrderedFib() { this in fibonacciNumbers() }
override int getOrder() { result = this }
}
from OrderedFib f
select f, f.getPrevious(), f.getNext()
Import path
import qtil.list.OrderedClasses
| Type | Abstract class which should be extended to create a type which is ordered and not grouped. |
Modules
| GroupBy | A module for adding |