summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
authorjblum2009-02-01 03:37:13 +0000
committerjblum2009-02-01 03:37:13 +0000
commit80fb5db88469ed5c80246846a2086338af7caea4 (patch)
tree98801c9c83287406ecb133154024f10dd01a813e /grc
parent7725205613b4737bfbc50a2c29932f832ec3e705 (diff)
downloadgnuradio-80fb5db88469ed5c80246846a2086338af7caea4.tar.gz
gnuradio-80fb5db88469ed5c80246846a2086338af7caea4.tar.bz2
gnuradio-80fb5db88469ed5c80246846a2086338af7caea4.zip
insert for odict
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10368 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc')
-rw-r--r--grc/src/utils/__init__.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/grc/src/utils/__init__.py b/grc/src/utils/__init__.py
index 21af4a8be..73a2ed562 100644
--- a/grc/src/utils/__init__.py
+++ b/grc/src/utils/__init__.py
@@ -46,6 +46,32 @@ class odict(DictMixin):
copy_dict._keys = list(self._keys)
return copy_dict
+ def insert_after(self, pos_key, key, val):
+ """
+ Insert the new key, value entry after the entry given by the position key.
+ If the positional key is None, insert at the end.
+ @param pos_key the positional key
+ @param key the key for the new entry
+ @param val the value for the new entry
+ """
+ index = (pos_key is None) and len(self._keys) or self._keys.index(pos_key)
+ assert key not in self._keys
+ self._keys.insert(index+1, key)
+ self._data[key] = val
+
+ def insert_before(self, pos_key, key, val):
+ """
+ Insert the new key, value entry before the entry given by the position key.
+ If the positional key is None, insert at the begining.
+ @param pos_key the positional key
+ @param key the key for the new entry
+ @param val the value for the new entry
+ """
+ index = (pos_key is not None) and self._keys.index(pos_key) or 0
+ assert key not in self._keys
+ self._keys.insert(index, key)
+ self._data[key] = val
+
def exists_or_else(d, key, alt):
if d.has_key(key): return d[key]
else: return alt