Solid::Predicate

Search for usage in LXR

#include <Solid/Predicate>

Public Types

enum  ComparisonOperator { Equals , Mask }
 
enum  Type { PropertyCheck , Conjunction , Disjunction , InterfaceCheck }
 

Public Member Functions

 Predicate ()
 
 Predicate (const DeviceInterface::Type &ifaceType)
 
 Predicate (const DeviceInterface::Type &ifaceType, const QString &property, const QVariant &value, ComparisonOperator compOperator=Equals)
 
 Predicate (const Predicate &other)
 
 Predicate (const QString &ifaceName)
 
 Predicate (const QString &ifaceName, const QString &property, const QVariant &value, ComparisonOperator compOperator=Equals)
 
 ~Predicate ()
 
ComparisonOperator comparisonOperator () const
 
Predicate firstOperand () const
 
DeviceInterface::Type interfaceType () const
 
bool isValid () const
 
bool matches (const Device &device) const
 
QVariant matchingValue () const
 
Predicate operator& (const Predicate &other)
 
Predicateoperator&= (const Predicate &other)
 
Predicateoperator= (const Predicate &other)
 
Predicate operator| (const Predicate &other)
 
Predicateoperator|= (const Predicate &other)
 
QString propertyName () const
 
Predicate secondOperand () const
 
QString toString () const
 
Type type () const
 
QSet< DeviceInterface::TypeusedTypes () const
 

Static Public Member Functions

static Predicate fromString (const QString &predicate)
 

Detailed Description

This class implements predicates for devices.

A predicate is a logical condition that a given device can match or not. It's a constraint about the value a property must have in a given device interface, or any combination (conjunction, disjunction) of such constraints.

A predicate can be:

  • a single comparison, or
  • a conjunction ("AND") of exactly two predicates, or
  • a disjunction ("OR") of exactly two predicates.

Since these can be nested, it is possible to express "a StorageVolume that is not ignored AND that StorageVolume contains a FileSystem AND that StorageVolume is removable". Since conjunctions use exactly two predicates (and this expression has three), square brackets are used to group the nested predicates when writing them out in full:

[ [ StorageVolume.ignored == false AND StorageVolume.usage == 'FileSystem' ]
AND StorageVolume.removable == true ]
This device interface is available on volume devices.

Predicates can be constructed programmatically by creating single comparisons with the Predicate constructor, and then building conjunctions with operator& and disjunctions with operator|.

Predicates can be constructed from a string by calling fromString() which parses the given string and returns a predicate. If there are any errors in parsing the string, an empty predicate is returned; use isValid() to detect whether that is the case.

The string language is described exactly in predicate_parser.y, but boils down to:

  • a single comparison is written as <interface>.<property> == <value>
  • a single bitmask check is written as <interface>.<property> & <value>
  • a conjunction is written as [ <predicate> AND <predicate> ]
  • a disjunction is written as [ <predicate> OR <predicate> ]

Note the mandatory use of [ and ] around conjunctions and disjunctions.

Member Enumeration Documentation

◆ ComparisonOperator

The comparison operator which can be used for matching within the predicate.

  • Equals, the property and the value will match for strict equality
  • Mask, the property and the value will match if the bitmasking is not null

Definition at line 75 of file predicate.h.

◆ Type

The predicate type which controls how the predicate is handled.

  • PropertyCheck, the predicate contains a comparison that needs to be matched using a ComparisonOperator
  • Conjunction, the two contained predicates need to be true for this predicate to be true
  • Disjunction, either of the two contained predicates may be true for this predicate to be true
  • InterfaceCheck, the device type is compared

Definition at line 85 of file predicate.h.

Constructor & Destructor Documentation

◆ Predicate() [1/6]

Solid::Predicate::Predicate ( )

Constructs an invalid predicate.

Definition at line 41 of file predicate.cpp.

◆ Predicate() [2/6]

Solid::Predicate::Predicate ( const Predicate & other)

Copy constructor.

Parameters
otherthe predicate to copy

Definition at line 46 of file predicate.cpp.

◆ Predicate() [3/6]

Solid::Predicate::Predicate ( const DeviceInterface::Type & ifaceType,
const QString & property,
const QVariant & value,
ComparisonOperator compOperator = Equals )

Constructs a predicate matching the value of a property in a given device interface.

Parameters
ifaceTypethe device interface type the device must have
propertythe property name of the device interface
valuethe value the property must have to make the device match
compOperatorthe operator to apply between the property and the value when matching

Definition at line 52 of file predicate.cpp.

◆ Predicate() [4/6]

Solid::Predicate::Predicate ( const QString & ifaceName,
const QString & property,
const QVariant & value,
ComparisonOperator compOperator = Equals )

Constructs a predicate matching the value of a property in a given device interface.

Parameters
ifaceNamethe name of the device interface the device must have
propertythe property name of the device interface
valuethe value the property must have to make the device match
compOperatorthe operator to apply between the property and the value when matching

Definition at line 62 of file predicate.cpp.

◆ Predicate() [5/6]

Solid::Predicate::Predicate ( const DeviceInterface::Type & ifaceType)
explicit

Constructs a predicate matching devices being of a particular device interface.

Parameters
ifaceTypethe device interface the device must have

Definition at line 76 of file predicate.cpp.

◆ Predicate() [6/6]

Solid::Predicate::Predicate ( const QString & ifaceName)
explicit

Constructs a predicate matching devices being of a particular device interface.

Parameters
ifaceNamethe name of the device interface the device must have

Definition at line 84 of file predicate.cpp.

◆ ~Predicate()

Solid::Predicate::~Predicate ( )

Destroys a Predicate object.

Definition at line 96 of file predicate.cpp.

Member Function Documentation

◆ comparisonOperator()

Solid::Predicate::ComparisonOperator Solid::Predicate::comparisonOperator ( ) const

Retrieves the comparison operator used to compare a property's value.

Since
4.4
Note
This is only valid for Conjunction and Disjunction types
Returns
the comparison operator used

Definition at line 334 of file predicate.cpp.

◆ firstOperand()

Solid::Predicate Solid::Predicate::firstOperand ( ) const

A smaller, inner predicate which is the first to appear and is compared with the second one.

Since
4.4
Note
This is only valid for Conjunction and Disjunction types
Returns
The predicate used for the first operand

Definition at line 339 of file predicate.cpp.

◆ fromString()

Solid::Predicate Solid::Predicate::fromString ( const QString & predicate)
static

Converts a string to a predicate.

Parameters
predicatethe string to convert
Returns
a new valid predicate if the given string is syntactically correct, Predicate() otherwise

Definition at line 40 of file predicateparse.cpp.

◆ interfaceType()

Solid::DeviceInterface::Type Solid::Predicate::interfaceType ( ) const

Retrieves the interface type.

Note
This is only valid for InterfaceCheck and PropertyCheck types
Since
4.4
Returns
a device interface type used by the predicate

Definition at line 319 of file predicate.cpp.

◆ isValid()

bool Solid::Predicate::isValid ( ) const

Indicates if the predicate is valid.

Predicate() is the only invalid predicate.

Returns
true if the predicate is valid, false otherwise

Definition at line 164 of file predicate.cpp.

◆ matches()

bool Solid::Predicate::matches ( const Device & device) const

Checks if a device matches the predicate.

Parameters
devicethe device to match against the predicate
Returns
true if the given device matches the predicate, false otherwise

Definition at line 169 of file predicate.cpp.

◆ matchingValue()

QVariant Solid::Predicate::matchingValue ( ) const

Retrieves the value used when comparing a devices property to see if it matches the predicate.

Note
This is only valid for the PropertyCheck type
Since
4.4
Returns
the value used

Definition at line 329 of file predicate.cpp.

◆ operator&()

Solid::Predicate Solid::Predicate::operator& ( const Predicate & other)

'And' operator.

Parameters
otherthe second operand
Returns
a new 'and' predicate having 'this' and 'other' as operands

Definition at line 128 of file predicate.cpp.

◆ operator&=()

Solid::Predicate & Solid::Predicate::operator&= ( const Predicate & other)

'AndEquals' operator.

Parameters
otherthe second operand
Returns
assigns to 'this' a new 'and' predicate having 'this' and 'other' as operands

Definition at line 140 of file predicate.cpp.

◆ operator=()

Solid::Predicate & Solid::Predicate::operator= ( const Predicate & other)

Assignment operator.

Parameters
otherthe predicate to assign
Returns
this predicate after having assigned 'other' to it

Definition at line 106 of file predicate.cpp.

◆ operator|()

Solid::Predicate Solid::Predicate::operator| ( const Predicate & other)

'Or' operator.

Parameters
otherthe second operand
Returns
a new 'or' predicate having 'this' and 'other' as operands

Definition at line 146 of file predicate.cpp.

◆ operator|=()

Solid::Predicate & Solid::Predicate::operator|= ( const Predicate & other)

'OrEquals' operator.

Parameters
otherthe second operand
Returns
assigns to 'this' a new 'or' predicate having 'this' and 'other' as operands

Definition at line 158 of file predicate.cpp.

◆ propertyName()

QString Solid::Predicate::propertyName ( ) const

Retrieves the property name used when retrieving the value to compare against.

Note
This is only valid for the PropertyCheck type
Since
4.4
Returns
a property name

Definition at line 324 of file predicate.cpp.

◆ secondOperand()

Solid::Predicate Solid::Predicate::secondOperand ( ) const

A smaller, inner predicate which is the second to appear and is compared with the first one.

Since
4.4
Note
This is only valid for Conjunction and Disjunction types
Returns
The predicate used for the second operand

Definition at line 347 of file predicate.cpp.

◆ toString()

QString Solid::Predicate::toString ( ) const

Converts the predicate to its string form.

Returns
a string representation of the predicate

Definition at line 255 of file predicate.cpp.

◆ type()

Solid::Predicate::Type Solid::Predicate::type ( ) const

Retrieves the predicate type, used to determine how to handle the predicate.

Since
4.4
Returns
the predicate type

Definition at line 314 of file predicate.cpp.

◆ usedTypes()

QSet< Solid::DeviceInterface::Type > Solid::Predicate::usedTypes ( ) const

Retrieves the device interface types used in this predicate.

Returns
all the device interface types used in this predicate

Definition at line 234 of file predicate.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.