// EdoIdContext.h #ifndef hes_EdoIdContext_H #define hes_EdoIdContext_H // David Adams // February 2002 // // An EdoId context is used to assign compact indices to a // collection of EdoId's. The context (the ID's and their // indexing) can be converted into a HES IndexVector which // can be written to a file and later read back to // restore the ID's and indexing. // // Indices are assigned starting with 1. // Zero is an invalid value. #include #include #include "Index.h" #include "IndexVector.h" namespace hes { class EdoId; class EdoIdContext { public: // static functions // Version. static Index version(); private: // data // Largest allowed index. Index m_max_allowed_index; // Number of assigned indices. Index m_size; // Index table. vector m_ids; public: // functions // Default constructor. // The largest allowed index is set to 511 (8 bits). EdoIdContext(); // Construct the context from an index vector. // The iterator is advanced past the description of the context. EdoIdContext(hes::IndexVector::const_iterator& iidv); // Return the largest allowed index. Index max_allowed_index() const; // Return the largest allowed index. // Set it to the the provided value if valid. // Valid means greater than zero and greater than or equal to the // largest assiged value. Index max_allowed_index(Index midx =0); // Return the largest assigned index. Index max_index() const; // Return the number of assigned indices. Index size() const; // Insert an ID with the specified index. // Fails if the ID or index are already assigned differently. // Returns the index if successful. // Returns zero for error. Index insert(EdoId id, Index idx); // Insert an ID at the first available index. // No action is taken if the ID is already present. // In either case the corresponding index is returned. // Zero is returned in case of error. Index insert(EdoId id); // Return the index for an EDO. Index index(EdoId id) const; // Return the EDO ID associated with a compact index. EdoId edo_id(Index idx) const; // Append a description of this table to an index vector. hes::IndexVector& write(hes::IndexVector& idv) const; }; } // end namespace // Output stream; std::ostream& operator<<(std::ostream& lhs, const hes::EdoIdContext& rhs); #endif