///////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2010-2011 Wolfgang Kowarschick // // Dieses Werk darf unter den Bedingungen der Creative Common Lizenz by-nc 3.0 de // (http://creativecommons.org/licenses/by-nc/3.0/de/) // vervielfaeltigt, verbreitet, publiziert und modifiziert werden. ///////////////////////////////////////////////////////////////////////////////// package as3.extent { import as3.assert.Assert; import as3.identifier.I_ID; import flash.utils.Dictionary; /** * @autor Wolfgang Kowarschick * @category class * @langversion 3.0 */ public class ExtentBase { ///////////////////////////////////////////////////////////////////////////// // Static members ///////////////////////////////////////////////////////////////////////////// private static const sc_elements: Dictionary = new Dictionary(); public static function dictionary(p_class: Class): Dictionary { var l_dictionary: Dictionary = sc_elements[p_class]; Assert.notEquals(l_dictionary, null, null, "extent of " + p_class + " does not exist" ); return l_dictionary; } ///////////////////////////////////////////////////////////////////////////// // Private methods ///////////////////////////////////////////////////////////////////////////// private function m_get_dictionary(p_element: I_Element): Dictionary { var l_element_class: Class = Object(p_element).constructor; var l_dictionary: Dictionary = sc_elements[l_element_class]; if (l_dictionary == null) { l_dictionary = new Dictionary(); sc_elements[l_element_class] = l_dictionary; }; return l_dictionary; } private function m_key(p_id: Object, p_element: I_Element = null): Object { return (p_id == null && p_element is I_ID) ? (p_element as I_ID).id : (p_id is I_ID) ? (p_id as I_ID).id : p_id; } ///////////////////////////////////////////////////////////////////////////// // Public methods ///////////////////////////////////////////////////////////////////////////// public function add(p_element: I_Element, p_id: Object = null): void { var l_elements: Dictionary = m_get_dictionary(p_element); var l_key: Object = m_key(p_id, p_element); Assert.equals(l_elements[l_key], null, this, "element '" + l_key + "' already exists" ); l_elements[l_key] = p_element; } public function remove(p_element: I_Element, p_id: Object = null): void { var l_elements: Dictionary = m_get_dictionary(p_element); var l_key: Object = m_key(p_id, p_element); delete l_elements[l_key]; } ///////////////////////////////////////////////////////////////////////////// // End of class ///////////////////////////////////////////////////////////////////////////// } } ///////////////////////////////////////////////////////////////////////////////// // End of file /////////////////////////////////////////////////////////////////////////////////