Interface Specification for Mapping


[Contents] [Prev] [Next]
Table of Contents

Overview

Mapping is a specification of a generalized interface to dictionary-like objects.

Currently the 2.0a12 ILU ISL language definition does not directly support dictionary objects. This Mapping interface is an attempt at supporting this type of object. Some semantics of dictionaries are lost here, but by using this definition, it is pretty easy to convert to and from Python dictionaries.

From a StringMap to a Python dictionary:

	d = {}
	for [k, v] in mapobj.GetItems():
	      d[k] = v

From a dictionary to a StringMap:

        mapobj.SetValues(d.items())

Types

This interface defines the following non-OBJECT types:
String
An alias for ilu.CString
Strings
An alias for SEQUENCE OF String
Key
An alias for String
Value
An alias for String
Keys
An alias for SEQUENCE OF Key
Values
An alias for SEQUENCE OF Value
KeyValuePair
An alias for ARRAY OF 2 String
KeyValuePairs
An alias for SEQUENCE OF KeyValuePair

Exceptions

This interface defines the following exceptions:

KeyError
The key is not in the mapping. In Python, be sure to specify Mapping.KeyError to avoid confusing it with the built-in KeyError.

WriteError
The mapping or value is read-only.

StringMap Objects

Mapping type interface to Python-like dictionaries.

GetKeys () : Keys
Return all the keys in the mapping.

GetValue (key : Key) : Value
Return the value associated with key in the mapping. Raise KeyError if the key is not in the mapping.

GetItems () : KeyValuePairs
Return all the key/value pairs in the mapping.

SetValue (key : Key, value : Value)
Replace or add a key/value mapping. Raise KeyError if the key is not in the mapping. Raise WriteError if the value or mapping is read-only.

DeleteKey (key : Key)
Delete a key/value mapping. Raise KeyError if the key is not in the mapping. Raise WriteError if the value or mapping is read-only.

Table of Contents

[Contents] [Prev] [Next]
Copyright © 1998 by the Corporation for National Research Initiatives.