[rygel] core: Expression classes in separate files



commit ec470bc1c167c57547f9aa33799833d80b0fd264
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Nov 4 17:51:56 2009 +0200

    core: Expression classes in separate files
    
    Put both expression classes in different files.

 src/rygel/Makefile.am                   |    2 +
 src/rygel/rygel-atomic-expression.vala  |   94 +++++++++++++++++++++++++++++
 src/rygel/rygel-logical-expression.vala |   52 ++++++++++++++++
 src/rygel/rygel-search-expression.vala  |  100 -------------------------------
 4 files changed, 148 insertions(+), 100 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index e857cca..4d84cc1 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -73,6 +73,8 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
 		    rygel-browse.vala \
 		    rygel-search.vala \
 		    rygel-search-expression.vala \
+		    rygel-atomic-expression.vala \
+		    rygel-logical-expression.vala \
 		    rygel-search-criteria-parser.vala \
 		    rygel-didl-lite-writer.vala \
 		    rygel-transcoder.vala \
diff --git a/src/rygel/rygel-atomic-expression.vala b/src/rygel/rygel-atomic-expression.vala
new file mode 100644
index 0000000..0f85c11
--- /dev/null
+++ b/src/rygel/rygel-atomic-expression.vala
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+
+// Represents a search expression that consists of two strings joined by a
+// relational operator.
+public class Rygel.AtomicExpression :
+             Rygel.SearchExpression<SearchCriteriaOp,string,string> {
+    public override bool satisfied_by (MediaObject media_object) {
+        switch (this.operand1) {
+        case "@id":
+            return this.compare_string (media_object.id);
+        case "@parentID":
+            return this.compare_string (media_object.parent.id);
+        case "@refID":
+            return false; // We don't have refIDs yet
+        case "upnp:class":
+            return this.compare_string (media_object.upnp_class);
+        case "dc:title":
+            return this.compare_string (media_object.title);
+        case "dc:creator":
+            if (!(media_object is MediaItem)) {
+                return false;
+            }
+
+            var item = media_object as MediaItem;
+            return this.compare_string (item.author);
+        default:
+            if (this.operand1.has_prefix ("res")) {
+                return this.compare_resource (media_object);
+            } else {
+                return false;
+            }
+        }
+    }
+
+    public override string to_string () {
+        return "%s %d %s".printf (this.operand1, this.op, this.operand2);
+    }
+
+    private bool compare_resource (MediaObject media_object) {
+        bool ret = false;
+
+        foreach (var uri in media_object.uris) {
+            if (this.operand1 == "res" && this.compare_string (uri)) {
+                ret = true;
+                break;
+            } else if (this.operand1 == "res protocolInfo") {
+                // FIXME: Implement
+            }
+        }
+
+        return ret;
+    }
+
+    private bool compare_string (string? str) {
+        switch (this.op) {
+        case SearchCriteriaOp.EXISTS:
+            if (this.operand2 == "true") {
+                return str != null;
+            } else {
+                return str == null;
+            }
+        case SearchCriteriaOp.EQ:
+            return this.operand2 == str;
+        case SearchCriteriaOp.CONTAINS:
+            return this.operand2.contains (str);
+        case SearchCriteriaOp.DERIVED_FROM:
+            return this.operand2.has_prefix (str);
+        default:
+            return false;
+        }
+    }
+}
diff --git a/src/rygel/rygel-logical-expression.vala b/src/rygel/rygel-logical-expression.vala
new file mode 100644
index 0000000..d02b15b
--- /dev/null
+++ b/src/rygel/rygel-logical-expression.vala
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+public enum Rygel.LogicalOperator {
+    AND,
+    OR
+}
+
+// Represents a search expression that consists of two search expressions joined
+// by a logical operator
+public class Rygel.LogicalExpression :
+             Rygel.SearchExpression<LogicalOperator,
+                                    SearchExpression,
+                                    SearchExpression> {
+    public override bool satisfied_by (MediaObject media_object) {
+        switch (this.op) {
+        case LogicalOperator.AND:
+            return this.operand1.satisfied_by (media_object) &&
+                   this.operand2.satisfied_by (media_object);
+        case LogicalOperator.OR:
+            return this.operand1.satisfied_by (media_object) ||
+                   this.operand2.satisfied_by (media_object);
+        default:
+            return false;
+        }
+    }
+
+    public override string to_string () {
+        return "(%s %d %s)".printf (this.operand1.to_string (),
+                                    this.op,
+                                    this.operand2.to_string ());
+    }
+}
diff --git a/src/rygel/rygel-search-expression.vala b/src/rygel/rygel-search-expression.vala
index 46da853..16e4f48 100644
--- a/src/rygel/rygel-search-expression.vala
+++ b/src/rygel/rygel-search-expression.vala
@@ -20,13 +20,6 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-using GUPnP;
-
-public enum Rygel.LogicalOperator {
-    AND,
-    OR
-}
-
 /**
  * Represents a SearchExpression tree.
  */
@@ -40,96 +33,3 @@ public abstract class Rygel.SearchExpression<G,H,I> {
 
     public abstract string to_string ();
 }
-
-public class Rygel.AtomicExpression :
-             Rygel.SearchExpression<SearchCriteriaOp,string,string> {
-    public override bool satisfied_by (MediaObject media_object) {
-        switch (this.operand1) {
-        case "@id":
-            return this.compare_string (media_object.id);
-        case "@parentID":
-            return this.compare_string (media_object.parent.id);
-        case "@refID":
-            return false; // We don't have refIDs yet
-        case "upnp:class":
-            return this.compare_string (media_object.upnp_class);
-        case "dc:title":
-            return this.compare_string (media_object.title);
-        case "dc:creator":
-            if (!(media_object is MediaItem)) {
-                return false;
-            }
-
-            var item = media_object as MediaItem;
-            return this.compare_string (item.author);
-        default:
-            if (this.operand1.has_prefix ("res")) {
-                return this.compare_resource (media_object);
-            } else {
-                return false;
-            }
-        }
-    }
-
-    public override string to_string () {
-        return "%s %d %s".printf (this.operand1, this.op, this.operand2);
-    }
-
-    private bool compare_resource (MediaObject media_object) {
-        bool ret = false;
-
-        foreach (var uri in media_object.uris) {
-            if (this.operand1 == "res" && this.compare_string (uri)) {
-                ret = true;
-                break;
-            } else if (this.operand1 == "res protocolInfo") {
-                // FIXME: Implement
-            }
-        }
-
-        return ret;
-    }
-
-    private bool compare_string (string? str) {
-        switch (this.op) {
-        case SearchCriteriaOp.EXISTS:
-            if (this.operand2 == "true") {
-                return str != null;
-            } else {
-                return str == null;
-            }
-        case SearchCriteriaOp.EQ:
-            return this.operand2 == str;
-        case SearchCriteriaOp.CONTAINS:
-            return this.operand2.contains (str);
-        case SearchCriteriaOp.DERIVED_FROM:
-            return this.operand2.has_prefix (str);
-        default:
-            return false;
-        }
-    }
-}
-
-public class Rygel.LogicalExpression :
-             Rygel.SearchExpression<LogicalOperator,
-                                    SearchExpression,
-                                    SearchExpression> {
-    public override bool satisfied_by (MediaObject media_object) {
-        switch (this.op) {
-        case LogicalOperator.AND:
-            return this.operand1.satisfied_by (media_object) &&
-                   this.operand2.satisfied_by (media_object);
-        case LogicalOperator.OR:
-            return this.operand1.satisfied_by (media_object) ||
-                   this.operand2.satisfied_by (media_object);
-        default:
-            return false;
-        }
-    }
-
-    public override string to_string () {
-        return "(%s %d %s)".printf (this.operand1.to_string (),
-                                    this.op,
-                                    this.operand2.to_string ());
-    }
-}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]