/// <summary> /// Creates a new feature ID that doesn't reference anything (and does not add it to the map model). /// </summary> /// <param name="id">The ID to create.</param> /// <returns>The created feature ID.</returns> internal FeatureId CreateId(uint id) { // Confirm that the specified ID falls within this range. if (id < (uint)Min || id > (uint)Max) { throw new Exception("IdPacket.CreateId - New ID is not in range!"); } // Confirm that the specified ID was previously reserved (if not, // see if it has already been created). int reserveIndex = FindReservedId(id); if (reserveIndex < 0) { string msg = String.Format("ID {0} d was not properly reserved.", id); throw new ApplicationException(msg); } // Confirm that the packet does not already refer to an active ID. int index = (int)id - Min; bool reuse = false; NativeId fid = m_Ids[index]; if (fid != null) { if (fid.IsInactive) { reuse = true; } else { throw new Exception("IdPacket.CreateId - ID slot has already been used."); } } // If we're not re-using an old ID, create one. if (!reuse) { string keystr; // The key string // Try to get a numeric key. uint keyval = m_Group.GetNumericKey(id); if (keyval != 0) { // If we got one, we still need to represent it as a string (for // the FeatureId constructor). However, we need to let the // constructor know that it's ok to convert it back to numeric! keystr = keyval.ToString(); } else { // Format the ID using the key format (+ possible check digit) keystr = m_Group.FormatId(id); } // Create the new ID fid = new NativeId(m_Group, id); m_Ids[index] = fid; } // Clear the reserve status m_ReservedIds.RemoveAt(reserveIndex); return(fid); }
/// <summary> /// The formatted version of the raw ID. /// </summary> /// <returns>The result of a call to <c>IdGroup.FormatId(RawId)</c></returns> public override string ToString() { return(m_Group.FormatId(m_Id)); }