/// <summary> /// Rename an entity in a specific declarator /// </summary> /// <typeparam name="T">Type of the entity used in the declarator</typeparam> /// <param name="containerID">Identifier of the container in which rename the entity</param> /// <param name="lastName">Current name of the entity to rename</param> /// <param name="newName">Name to set to the entity</param> public void Rename(UInt32 containerID, string lastName, string newName) { CorePackage.Global.IDeclarator decl = GetDeclarator(containerID); CorePackage.Global.IDefinition def = decl.Find(lastName); decl.Rename(lastName, newName); def.Name = newName; //rename here because declarator do not edit Definition name }
/// <summary> /// Returns the id of an entity in the internal dicitonaries /// </summary> /// <param name="entity">Entity for which find the id</param> /// <returns>Id of the given entity</returns> public UInt32 GetEntityID(CorePackage.Global.IDefinition entity) { if (ids.ContainsKey(entity)) { return(ids[entity]); } throw new KeyNotFoundException("EntityFactory.getEntityID : No such id for the given entity"); }
/// <summary> /// Move an entity from a declarator to another /// </summary> /// <typeparam name="T">Type of the entity used in declarators</typeparam> /// <param name="fromID">Identifier of the declarator that contains the entity</param> /// <param name="toID">Identifier of the declarator to which move the entity</param> /// <param name="name">Name of the entity to move</param> public void Move(UInt32 fromID, UInt32 toID, string name) { CorePackage.Global.IDeclarator from = GetDeclarator(fromID); CorePackage.Global.IDeclarator to = GetDeclarator(toID); CorePackage.Global.AccessMode visibility = from.GetVisibilityOf(name); CorePackage.Global.IDefinition definition = from.Pop(name); to.Declare(definition, name, visibility); }
/// <summary> /// Removes an entity from the internal dictionaries /// </summary> /// <remarks> /// Throws a KeyNotFoundException if the entity hasn't been found /// Throws an InvalidOperationException if the given entity is a default added entity /// </remarks> /// <param name="entity">Entity to remove</param> public void RemoveEntity(CorePackage.Global.IDefinition entity) { if (!ids.ContainsKey(entity)) { throw new KeyNotFoundException("EntityFactory.remove : given definition uid hasn't been found"); } uint entity_id = ids[entity]; if (entity_id <= 5) { throw new InvalidOperationException("EntityFactory.remove : cannot remove base entities"); } Definitions.Remove(entity_id); ids.Remove(entity); }
/// <summary> /// Remove an entity from a specific container /// </summary> /// <typeparam name="T">Type of the entity used in the declarator</typeparam> /// <param name="containerID">Identifier of the container from which remove the entity</param> /// <param name="name">Name of the entity to remove</param> /// <returns>List of all removed entities' id</returns> public List <UInt32> Remove(UInt32 containerID, string name) { CorePackage.Global.IDefinition entity = GetDeclarator(containerID).Pop(name); List <UInt32> removed = new List <uint> { GetEntityID(entity) }; RemoveEntity(entity); Stack <CorePackage.Global.IDeclarator> toclear = new Stack <CorePackage.Global.IDeclarator>(); CorePackage.Global.IDeclarator decl = entity as CorePackage.Global.IDeclarator; if (decl != null) { toclear.Push(decl); } while (toclear.Count > 0) { CorePackage.Global.IDeclarator declarator = toclear.Pop(); foreach (CorePackage.Global.IDefinition curr in declarator.Clear()) { UInt32 id = GetEntityID(curr); removed.Add(id); RemoveEntity(id); decl = curr as CorePackage.Global.IDeclarator; if (decl != null) { toclear.Push(decl); } } } return(removed); }
/// <summary> /// Add an entity to the internal dictionnaries and increment current_id /// </summary> /// <param name="entity">Entity to add</param> public void AddEntity(CorePackage.Global.IDefinition entity) { Definitions[current_uid] = entity; ids[entity] = current_uid++; }