2
* Copyright (C) 2010 MediaNet Inh.
4
* Author: Sunil Mohan Adapa <sunil@medhas.org>
6
* This file is part of Rygel.
8
* Rygel is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU Lesser General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* Rygel is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program; if not, write to the Free Software Foundation,
20
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
* Logical expressions in SPARQL query filter
26
public class Rygel.Tracker.LogicalFilter : Object, QueryFilter {
27
public enum Operator {
34
public QueryFilter operand1;
35
public QueryFilter operand2;
37
public LogicalFilter (Operator op,
39
QueryFilter? operand2 = null) {
41
this.operand1 = operand1;
42
this.operand2 = operand2;
46
* Creates a simplified version of this expressions if it involves boolean
49
public QueryFilter simplify () {
50
if (!(this.operand1 is BooleanFilter ||
51
this.operand2 is BooleanFilter)) {
55
if (this.op == Operator.NOT && this.operand1 is BooleanFilter) {
56
var bool_filter = this.operand1 as BooleanFilter;
58
bool_filter.value = !(bool_filter.value);
63
BooleanFilter bool_filter;
66
if (this.operand1 is BooleanFilter) {
67
bool_filter = this.operand1 as BooleanFilter;
68
operand = this.operand2;
70
bool_filter = this.operand2 as BooleanFilter;
71
operand = this.operand1;
74
if ((bool_filter.value && this.op == Operator.OR) ||
75
(!(bool_filter.value) && this.op == Operator.AND)) {
82
public string to_string () {
83
string str = "(" + this.operand1.to_string () + ")";
85
if (this.op == Operator.NOT) {
99
assert_not_reached ();
102
str += "(" + this.operand2.to_string () + ")";