changeset 36:0b9ac7cef6e5

Add documentation for structpath.py
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 15 Jun 2011 12:29:46 +0800
parents 2f9e7f03dbf7
children ee8aeb299f10
files paraspace/structpath.py
diffstat 1 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/structpath.py	Wed Jun 15 12:03:23 2011 +0800
+++ b/paraspace/structpath.py	Wed Jun 15 12:29:46 2011 +0800
@@ -1,17 +1,36 @@
-##
+## \brief A xpath liked query language
+#
 # Implement a xpath liked query language.
 #
-# \section predicate Predicate
 # Structpath uses syntax of Python for predicate.  That means you must use
 # '==' instead of '='.
 #
+# You need to create a context before querying.
+# \code
+# ctx = parent_context(None)
+# ctx.root = car()
+# root = ctx.root
+#
+# root.wheels = [wheel(), wheel(), wheel(), wheel()]
+# root.handle = handle()
+#
+# ctx.all_classes = {'car': car, 'wheel': wheel, 'handle': handle}
+# ctx.class_instances = {
+#     'car': [root],
+#     'wheel': root.wheels,
+#     'handle': [root.handle]
+#     }
+#
+# objs = find_objs_path(ctx, '/car/wheels')
+# \endcode
+#
 class context(object):
     all_classes = None
     class_instances = None
     root = None
     objs = None
 
-    def __init__(self, objs, ctx=None):
+    def __init__(self, objs=None, ctx=None):
         if ctx:
             self.all_classes = ctx.all_classes
             self.class_instances = ctx.class_instances