// Content.h #ifndef dset__Content_H #define dset__Content_H // David Adams // October 2004 // // Class to describe the content of a dataset. Each content object // holds a list of content blocks. // // The content may be in one of two states: compact or noncompact. In // In the former case, the content blocks have been merged to the // greatest possible extent. In the latter, the extent of the merging // is unknown. // // XML representation: // // Content // compact = true (or false) // ContentBlock // ... // ... #include #include #include #include "dataset_util/Text.h" #include "dataset_base/ContentBlock.h" class XmlElement; namespace dset { class Content { public: // typedefs typedef ContentBlock::Name Name; typedef std::vector BlockList; private: // data BlockList m_blks; int m_error; bool m_compact; public: // static functions // XML name. static const char* xml_name() { return "Content"; } // DTD. static const Text& dtd(); public: // Constructors and destructor. // Default constructor for empty content. // If error is nonzero, the content is invalid. explicit Content(int error =0); // Single block constructor without events. Content(Name type, Name name, const ContentIdList& cids); // Single block constructor with events. Content(Name type, Name name, const ContentIdList& cids, const EventIdList& eids); // Constructor from XML. explicit Content(const XmlElement& ele); public: // Non-const methods. // Append a content block. // No comparison with existing blocks is done. // Fails if the input block is invalid. // ANY -> NONCOMPACT. int push_back(const ContentBlock& blk); // Append content (all content blocks). int push_back(const Content& con); // Merge all the content blocks in order. // If already compact, no action is taken. // ANY -> COMPACT. int compact(); // Merge a content block into the current list. // The block is merged into the first one that matches and // then the new block is merged iteratively. // If none match, it is appended. // NONCOMPACT -> NONCOMPACT. // COMPACT -> COMPACT. int merge(const ContentBlock& blk); // Merge content (all content blocks). int merge(const Content& con); public: // Const methods. // Return if the content is valid. bool is_valid() const; // Error flag. int error() const; // Return if the content is fully merged. // If true, the merge operation will have no effect. // If false, merge may change the list of blocks. bool is_compact() const; // Return the blocks. const BlockList& blocks() const; // Return the number of blocks. BlockList::size_type size() const; // Return the first block. const ContentBlock& front() const; // Return if there is event content. bool has_event_content() const; // Return if there is non-event content. bool has_nonevent_content() const; // Return the event part of the content. Content event_content() const; // Return the non-event part of the content. Content nonevent_content() const; // Is empty if is valid and blocks are all empty. bool is_empty() const; // Size of managed memory in bytes. size_t memsize() const; // XML representation. const XmlElement* xml() const; // Output stream. std::ostream& ostr(std::ostream&, std::string indent) const; }; // Equality. bool operator==(const dset::Content& lhs, const dset::Content& rhs); // Inequality. bool operator!=(const dset::Content& lhs, const dset::Content& rhs); }; // end namespace dset // Output stream. std::ostream& operator<<(std::ostream& lhs, const dset::Content& rhs); #endif