// ContentId.h #ifndef ContentId_H #define ContentId_H // David Adams // June 2002 // // Content identifier. // // XML format is // // ContentId // name = MyClass // key = mykey // // The key is optional. #include #include #include "dataset_util/Text.h" class XmlElement; class ContentId { public: // typedefs typedef unsigned int Index; typedef unsigned int size_type; // Unique class index. unsigned int m_idx; // Persistent class name. std::string m_name; // String key. // Distinguishes EDO's of the same type (class index). std::string _key; public: // static functions // Register a class. static ContentId private_register_id(int idx, const char* name); public: // static functions // Return the XML name for this class. static const char* xml_name() { return "ContentId"; } // XML DTD. static const Text& dtd(); public: // functions // Initialize the class. // This should be called before any content ID's are accessed // during C++ initialization. It will be called automatically // before any calls from main(). // Return is the number of calls that have been made. static int initialize(); // Register a class. // These are temporary values and must be < 1000. // Permanent values are larger. // A valid identifier is returned if successful. // Existing indices and names must match. static ContentId register_id(int idx, const char* name); // Return the number of content ID's. static size_type size(); // Display the table of content ID's. static void display(std::ostream& strm); public: // functions // Default constructor. ContentId(); // Constructor from index. // Index must already be registered. // Indices 101-106 are registered for test purposes. explicit ContentId(Index idx, std::string key =""); // Constructor from class name. // Name must already be registered. explicit ContentId(std::string name, std::string key =""); // Construct from an XMlElement. explicit ContentId(const XmlElement& pele); // Validity. bool is_valid() const; // Index. Index index() const; // Name. std::string name() const; const char* cname() const; // Key. std::string key() const; const char* ckey() const; // Convert to an XmlElement. const XmlElement* xml() const; }; // Ordering. bool operator<(const ContentId& lhs, const ContentId& rhs); // Equality. bool operator==(const ContentId& lhs, const ContentId& rhs); // Output stream. std::ostream& operator<<(std::ostream& lhs, const ContentId& rhs); #endif