# HG changeset patch # User Thinker K.F. Li # Date 1308112186 -28800 # Node ID 0b9ac7cef6e5262f2e2e91120b156e9564236e8c # Parent 2f9e7f03dbf7350b502f661b3735808df9a38802 Add documentation for structpath.py diff -r 2f9e7f03dbf7 -r 0b9ac7cef6e5 paraspace/structpath.py --- 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