// PlacementCategoryType.cxx #include"PlacementCategoryType.h" #include #include #include using std::set; using std::ostream; using hes::Name; using hes::EdoType; using hes::EdoKey; using hes::EdoTypeKey; using hes::PlacementCategoryType; typedef PlacementCategoryType::TypeKeyList TypeKeyList; typedef PlacementCategoryType::TypeList TypeList; //********************************************************************** // Constructor. PlacementCategoryType::PlacementCategoryType(Name name) : m_name(name), m_closed(false) { } //********************************************************************** // Add an allowed type-key; void PlacementCategoryType::insert(EdoTypeKey tk) { if ( is_valid() && (!is_closed()) && tk.is_valid() ) { m_typekeys.insert(tk); } } //********************************************************************** // Add an allowed type-key; void PlacementCategoryType::insert(EdoType type, EdoKey key) { insert(EdoTypeKey(type,key)); } //********************************************************************** // Add a type for which all keys are allowed. void PlacementCategoryType::insert(EdoType type) { if ( is_valid() && (!is_closed()) && type.is_valid() ) { m_types.insert(type); } } //********************************************************************** // Close this object. void PlacementCategoryType::close() { if ( (!is_valid()) || is_closed() ) { return; } // Remove any redundant type-keys. for ( TypeList::const_iterator ityp=m_types.begin(); ityp!=m_types.end(); ++ityp ) { TypeKeyList::iterator itk = m_typekeys.begin(); while ( itk != m_typekeys.end() ) { if ( itk->type() == *ityp ) { m_typekeys.erase(itk++); } else { ++itk; } } } m_closed = true; } //********************************************************************** // Is this object valid? bool PlacementCategoryType::is_valid() const { return m_name.is_valid(); } //********************************************************************** // Return the name. Name PlacementCategoryType::name() const { return m_name; } //********************************************************************** // Has this object been closed? bool PlacementCategoryType::is_closed() const { return m_closed; } //********************************************************************** // Is the specified type-key allowed? bool PlacementCategoryType::allows(EdoTypeKey tk) const { if ( (!is_valid()) || (!tk.is_valid()) ) { return false; } if ( m_types.find(tk.type()) != m_types.end() ) { return true; } if ( m_typekeys.find(tk) != m_typekeys.end() ) { return true; } return false; } //********************************************************************** // Is the specified type-key allowed? bool PlacementCategoryType::allows(EdoType type, EdoKey key) const { return allows(EdoTypeKey(type,key)); } //********************************************************************** // Return the allowed type-keys. const TypeKeyList& PlacementCategoryType::type_keys() const { return m_typekeys; } //********************************************************************** // Return types for which all keys are allowed. const TypeList& PlacementCategoryType::types() const { return m_types; } //********************************************************************** // Free functions. //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const PlacementCategoryType& rhs) { if ( ! rhs.is_valid() ) { lhs << "invalid placement category type"; return lhs; } lhs << "Placement category type " << rhs.name(); if ( ! rhs.is_closed() ) { lhs << " (not closed)"; } if ( rhs.types().size()==0 and rhs.type_keys().size() == 0 ) { lhs << " accepts all type-keys."; return lhs; } lhs << ":" ; const TypeList& types = rhs.types(); for ( TypeList::const_iterator ityp=types.begin(); ityp!=types.end(); ++ityp ) { lhs << "\n " << *ityp << " *"; } const TypeKeyList& tks = rhs.type_keys(); for ( TypeKeyList::const_iterator itk=tks.begin(); itk!=tks.end(); ++itk ) { lhs << "\n " << *itk; } return lhs; } //********************************************************************** // Equality. // For now we require exact equality, not just equivalence. bool operator==(const PlacementCategoryType& lhs, const PlacementCategoryType& rhs) { if ( &lhs == &rhs ) return true; if ( lhs.name() != rhs.name() ) return false; PlacementCategoryType::TypeKeyList tks1 = lhs.type_keys(); PlacementCategoryType::TypeKeyList tks2 = rhs.type_keys(); PlacementCategoryType::TypeList tys1 = lhs.types(); PlacementCategoryType::TypeList tys2 = rhs.types(); if ( tks1 != tks2 ) return false; if ( tys1 != tys2 ) return false; return true; } //********************************************************************** // Inequality. bool operator!=(const PlacementCategoryType& lhs, const PlacementCategoryType& rhs) { return ! (lhs == rhs); } //**********************************************************************