Dictionary and EDictionary types

The EGL Dictionary type is a reference type that lets you create an instance that is composed of a set of keys and their related values. In Eclipse IDE for EGL Developers, the type definition for Dictionary is EDictionary.

EGL package name

eglx.lang

Example use
Here is a dictionary declaration:
myRef Dictionary 
{
   ID        = 5,
   lastName  = "Twain",
   firstName = "Mark"
};

When you include entries in the declaration, each key name is an EGL identifier that must be consistent with EGL naming conventions. When you add entries at run time, you have greater flexibility; see "Dynamic types and dynamic access."

The following assignments that add new key/value pairs to the dictionary:
myRef.age = 30;
myRef["Credit"] = 700;
If you attempt to assign a key that already exists, you override the existing key/value entry. The following assignment is valid and replaces "Twain" with "Clemens":
myRef.lastname = "Clemens";
You can also use assignments to retrieve data:
lastname STRING
age, credit INT;

lastname = myRef.lastname; 
age = myRef["age"];
credit = myRef.credit;

The value in a key/value entry is ANY type, so you can put different kinds of information into a single dictionary. You can put any value into a dictionary entry.

Adding a variable to a dictionary assigns a copy of the variable. Consider the following Record type:
Record ExampleRecord
   x int;
end

The next example places an ExampleRecord variable into the dictionary, then changes the value of the original variable:

testValue int;

myRecord ExampleRecord;

// sets a variable value and places
// a copy of the variable into the dictionary.
myRecord.x = 4; 
myRef Dictionary {
    theRecord = myRecord
};
	
// Places a new value in the original record.
myRecord.x = 700;

// Accesses the dictionary's copy of the record, 
// assigning 4 to testValue.
testValue = myRef.theRecord.x;
Assigning one dictionary to another replaces the target content with the source content and overrides the fields of the target dictionary. For example, the conditional statement in the following code is true:
  myRef Dictionary { age = 30 };
  newRef Dictionary { age = 50 };
  newRef = myRef;

  // resolves to true
  if (newRef.age == 30)
    ;
  end
Type detail
In the following detail, the Operation annotation indicates that the specified operation is available. For example, use “==” to compare two values. Two exceptions are the widen and narrow operations, which are invoked during data conversions; for example, when the as operator is used.
/**
 * An EDictionary, the class for EGL's dictionary type, stores named values.
 * The name of a value -- its key -- is used to access that value.  The keys are
 * strings and the values are of type Any.
 *
 * Two annotations are commonly used on dictionaries.  CaseSensitive tells the
 * dictionary if its keys are case-sensitive.  The default is false.  Ordering
 * determines how the getKeys and getValues functions populate the lists they 
 * return.  Its value comes from the OrderingKind enumeration.  byKey means the 
 * elements of those lists are in alphabetical order of the keys.  byInsertion
 * means the elements of those lists are in the order that keys were added to
 * the dictionary.  And none (the default) means the elements of those lists 
 * may be in any order whatsoever.
 *
 */
externalType EDictionary extends EAny type ClassType

	/**
	 * {@Operation ['} Returns the value with the given key.
	 * @throws DynamicAccessException  if there's no key with the given name.
	 */
static function $Lookup(dict EDictionary in, key EString in) 
       returns(EAny) {@Operation{"['"}};

	/**
	 * Default constructor
	 */
	constructor();

	/**
	 * Constructor used to set the value of case sensitivity and ordering
	 *
	 * @param caseSensitive  set if the dictionary is case sensitive
	 * @param ordering  set the order maintained in the dictionary.
	 */
	constructor(caseSensitive boolean in, ordering OrderingKind in);

	/**
	 * Tells if there's a value stored with the given key.
	 *
	 * @param key  the key.
	 * @return true if the key is in this dictionary.
	 */
	function containsKey(key EString in) returns(EBoolean);
	
	/**
	 * Returns a list containing all of the keys, in the order specified by
	 * the ordering annotation.
	 *
	 * @return the keys.
	 */
	function getKeys() returns(EString[]);
	
	/**
	 * Returns a list containing all of the values, in the order specified by
	 * the ordering annotation.
	 *
	 * @return the values.
	 */
	function getValues() returns(EAny[]);

	/**
	 * Puts all of the key-value pairs from one dictionary into this dictionary.
	 *
	 * @param other  the source of the new key-value pairs.
	 */
	function insertAll(other EDictionary in);

	/**
	 * Removes all of the key-value pairs from this dictionary.
	 */
	function removeAll();

	/**
	 * Removes the key-value pair which uses the specified key.
	 *
	 * @param key  the key.
	 * @throws DynamicAccessException  if there's no key-value pair with the given key.
	 */
	function removeElement(key EString in);
	
	/**
	 * Returns the number of key-value pairs in this dictionary.
	 *
	 * @return the size.
	 */
	function size() returns( EInt );

	/**
	 * Returns true if the dictionary is case sensitive.
	 *
	 * @return the case sensitivity.
	 */
	function getCaseSensitive() returns( EBoolean );

	/**
	 * Returns the order maintained in the dictionry.
	 *
	 * @return OrderingKind.
	 */
	function getOrdering() returns( OrderingKind );
end


/**
 * OrderingKind provides values for the Ordering annotation.  See the
 * documentation of EDictionary for more information.
 */
enumeration OrderingKind
   byKey = 1,
   byInsertion = 2,
   none = 3
end
Comments
Compatibility
Table 1. Compatibility
Target Issue
Java No issues.
JavaScript No issues.