TypeStruct* CDeviceTypeDirectory::addType(const TypeStruct& otherTypeStruct,int entityNumber) { TypeStruct* typeStruct = m_deviceTypeList.addType(otherTypeStruct,entityNumber); // if more than one type has the same name, the last added type is in the map getDeviceTypeMap().add(typeStruct->getName(),typeStruct); return typeStruct; }
void CDeviceTypeDirectory::reallocateMap() const { delete m_deviceTypeMap; int size = max(100,(int)(1.3 * m_deviceTypeList.GetCount())); m_deviceTypeMap = new CDeviceTypeArrayWithMap(size,false); for (POSITION pos = m_deviceTypeList.GetHeadPosition();pos != NULL;) { TypeStruct* typeStruct = m_deviceTypeList.GetNext(pos); m_deviceTypeMap->add(typeStruct->getName(),typeStruct); } }
// does not copy the CTypePinList TypeStruct::TypeStruct(const TypeStruct& other,int entityNumber) : m_parentList(other.m_parentList) , m_attributes(NULL) , m_blockNumber(other.getBlockNumber()) , m_entityNumber(entityNumber) , m_name(other.getName()) , m_typePinList(*this) { if (m_entityNumber < 0) { m_entityNumber = getCamCadData().allocateEntityNumber(); } if (other.getAttributes() != NULL) { attributes() = *(other.getAttributes()); } }
void CDeviceTypeDirectory::deleteAt(POSITION pos) { TypeStruct* listTypeStruct = getAt(pos); if (m_deviceTypeMap != NULL) { TypeStruct* mapTypeStruct = getDeviceTypeMap().getAt(listTypeStruct->getName()); // If the map contains a different TypeStruct, no need to deallocate map. // If the map contains this TypeStruct, deallocate it so that when it is rebuilt, another TypeStruct with the same name // will be put into the map. if (mapTypeStruct == listTypeStruct) { deallocateMap(); } } m_deviceTypeList.deleteAt(pos); }
TypeStruct* CDeviceTypeList::findType(const CString& name) const { TypeStruct* typeStruct = NULL; for (POSITION pos = m_typeList.GetHeadPosition();;) { if (pos == NULL) { typeStruct = NULL; break; } typeStruct = m_typeList.GetNext(pos); if (typeStruct->getName().Compare(name) == 0) { break; } } return typeStruct; }