Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64350 - trunk/tools/build/v2/util
From: ghost_at_[hidden]
Date: 2010-07-26 04:07:08


Author: vladimir_prus
Date: 2010-07-26 04:07:07 EDT (Mon, 26 Jul 2010)
New Revision: 64350
URL: http://svn.boost.org/trac/boost/changeset/64350

Log:
Add decorator for caching function results.

Text files modified:
   trunk/tools/build/v2/util/__init__.py | 21 +++++++++++++++++++++
   1 files changed, 21 insertions(+), 0 deletions(-)

Modified: trunk/tools/build/v2/util/__init__.py
==============================================================================
--- trunk/tools/build/v2/util/__init__.py (original)
+++ trunk/tools/build/v2/util/__init__.py 2010-07-26 04:07:07 EDT (Mon, 26 Jul 2010)
@@ -1,4 +1,5 @@
 
+# Decorator the specifies bjam-side prototype for a Python function
 def bjam_signature(s):
 
     def wrap(f):
@@ -6,3 +7,23 @@
         return f
 
     return wrap
+
+class cached(object):
+
+ def __init__(self, function):
+ self.function = function
+ self.cache = {}
+
+ def __call__(self, *args):
+ try:
+ return self.cache[args]
+ except KeyError:
+ v = self.function(*args)
+ self.cache[args] = v
+ return v
+
+def unquote(s):
+ if s and s[0] == '"' and s[-1] == '"':
+ return s[1:-1]
+ else:
+ return s


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk