// EdoType.cxx #include "EdoType.h" #include #include #include using std::string; using std::map; using std::ostream; using std::setw; using std::setfill; using hes::Index; using hes::EdoType; #ifdef DEFECT_GCC_2_95 namespace std { typedef ios ios_base; } #endif //********************************************************************** // Local definitions. typedef map NameMap; namespace { NameMap NAMES; } //********************************************************************** // Static members. //********************************************************************** // Return the version. int EdoType::version() { return 1; } //********************************************************************** // Register a type name. int EdoType::register_type(EdoType typ, std::string name) { NameMap::const_iterator inam = NAMES.find(typ); if ( inam != NAMES.end() ) { if ( inam->second == name ) { return 0; } else { return 1; } } NAMES[typ] = name; } //********************************************************************** // Member functions. //********************************************************************** // Constructor. EdoType::EdoType(Index idx) : m_idx(idx) { } //********************************************************************** // Validity check. bool EdoType::is_valid() const { return m_idx != 0; } //********************************************************************** // Return the type name. string EdoType::name() const { NameMap::const_iterator inam = NAMES.find(*this); if ( inam == NAMES.end() ) { return ""; } return inam->second; } //********************************************************************** // Return the index. Index EdoType::index() const { return m_idx; } //********************************************************************** // Free functions. //********************************************************************** // Ordering. bool operator<(const EdoType& lhs, const EdoType& rhs) { return lhs.index() < rhs.index(); } //********************************************************************** // Equality. bool operator==(const EdoType& lhs, const EdoType& rhs) { return lhs.index() == rhs.index(); } //********************************************************************** // Inequality bool operator!=(const EdoType& lhs, const EdoType& rhs) { return ! (lhs.index() == rhs.index()); } //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const EdoType& rhs) { if ( ! rhs.is_valid() ) { lhs << "invalid type"; return lhs; } std::ios_base::fmtflags flags = lhs.flags(); char fillchar = lhs.fill(); string name = rhs.name(); if ( name == "" ) { lhs << hex << setw(8) << setfill('0') << rhs.index(); } else { lhs << name; } lhs.flags(flags); lhs.fill(fillchar); return lhs; } //**********************************************************************