// ContentBlock.h #ifndef dset__ContentBlock_H #define dset__ContentBlock_H // David Adams // October 2004 // // Class to describe a block of content for a dataset. Each block // has a dataset type, a name, a list of content ID's and an // optional list of event ID's. // // If the block has events (i.e. has a list of event ID's), then the // implication is that the data corresponding to the content ID's are // present for all event. // // The class provides a merge method that uses another content block // to extend the content. If the block has events, then either the // list of event ID's or content ID's may be extended. // // XML representation: // // ContentBlock // type = MyDataset // name = my_block // ContentIdList // ... // EventIdList (optional) // ... #include #include #include #include "dataset_util/Text.h" #include "dataset_id/ContentIdList.h" #include "dataset_id/EventIdList.h" class XmlElement; namespace dset { class ContentBlock { public: // typedefs typedef std::string Name; private: // data int m_error; Name m_type; Name m_name; ContentIdList m_cids; bool m_has_evids; EventIdList m_eids; bool m_has_explicit_evids; EventIdList::size_type m_event_count; public: // static functions // XML name. static const char* xml_name() { return "ContentBlock"; } // DTD. static const Text& dtd(); // Set the maximum number of event ranges to write to XML. // If this threshold is exceeeded, then the event ID's are // not included in the XML description. // Default is 1000. static void set_maximum_xml_ranges(EventIdList::size_type thr); // Return the maximum number of XML ranges. static EventIdList::size_type maximum_xml_ranges(); public: // functions // Default constructor. ContentBlock(); // Constructor without event ID's. ContentBlock(Name type, Name name, const ContentIdList& cids); // Constructor with event ID's. ContentBlock(Name type, Name name, const ContentIdList& cids, const EventIdList& eids); // Constructor from XML. explicit ContentBlock(const XmlElement& ele); public: // non-const methods. // Merge another content block into this. // If the conditions for can_merge are not met, the merge fails and // this block is left unchanged or becomes invalid. // Returns 0 for success. int merge(const ContentBlock& rhs); public: // const methods. // Validity. bool is_valid() const; // Error status. // Zero for no error. int error() const; // Return the dataset_type. Name dataset_type() const; // Return the name. Name name() const; // Return the content ID's. const ContentIdList& content_ids() const; // Return if there are event ID's. bool has_events() const; // Return if the event ID list is explicit. bool has_explicit_events() const; // Return the number of events. EventIdList::size_type event_count() const; // Return the event ID's. const EventIdList& event_ids() const; // Is the block empty (no content ID's) or has events but // no event ID's. bool is_empty() const; // Size of managed memory in bytes. size_t memsize() const; // XML representation. const XmlElement* xml() const; // Can a content blocks be merged into this? // They must have the same type, the same name and both have or // both not have events. // If they do not have events they must have nonoverlapping // content ID's. // If the have events then they must have either // 1. the same event ID's and nonoverlapping content ID's, or // 2. the same content ID's and nonoverlapping event ID's. // If they do have events, the events must be explicit. // Returns 0 for success. See code for maning of other values. int check_merge(const ContentBlock& rhs) const; // Output stream. std::ostream& ostr(std::ostream&, std::string indent) const; }; // Equality. bool operator==(const dset::ContentBlock& lhs, const dset::ContentBlock& rhs); // Inequality. bool operator!=(const dset::ContentBlock& lhs, const dset::ContentBlock& rhs); }; // end namespace dset // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::ContentBlock& rhs); #endif