// DatasetIdList.cxx #include "dataset_id/DatasetIdList.h" #include #include "dataset_util/XmlElement.h" #include "dataset_util/DtdRegistry.h" using std::string; using std::ostream; using std::endl; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Maximum # dataset ID's to print. unsigned int MAX_PRINT_DATASET_ID = 20; // Register the DTD. DtdRegistry::Status ISTAT = DtdRegistry::register_dtd("dataset"); } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // DTD. const Text& DatasetIdList::dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); } return txt; } //********************************************************************** // Member functions. //********************************************************************** // Default constructor. DatasetIdList::DatasetIdList() { } //********************************************************************** // XML constructor. DatasetIdList::DatasetIdList(const XmlElement& ele, bool try_children) { const XmlElement* pele = 0; if ( ele.name() == xml_name() ) { pele = &ele; } else if ( try_children ) { const XmlElement::ElementList& children = ele.children(xml_name()); if ( children.size() == 1 ) { pele = children.front(); } } if ( pele != 0 ) { assert( pele->name() == xml_name() ); for ( XmlElement::ElementList::const_iterator iele=pele->children().begin(); iele!=pele->children().end(); ++iele ) { const XmlElement& child = **iele; if ( child.name() == DatasetId::xml_name() ) { DatasetId id(child); assert( id.is_valid() ); insert(id); } } assert( size() == pele->children().size() ); } } //********************************************************************** // Convert to XML. const XmlElement* DatasetIdList::xml() const { XmlElement* pele = new XmlElement(xml_name()); for ( const_iterator iid=begin(); iid!=end(); ++iid ) { pele->add_child(iid->xml()); } return pele; } //********************************************************************** // Output stream with content. ostream& DatasetIdList:: ostr(ostream& lhs, string indent, string repurl) const { lhs << indent << "Dataset ID list has " << size() << " entr"; if ( size() == 1 ) { lhs << "y"; } else { lhs << "ies"; } if ( size() > 0 ) { lhs << ":"; } else { lhs << "."; } if ( size() <= MAX_PRINT_DATASET_ID ) { for ( DatasetIdList::const_iterator idid=begin(); idid!=end(); ++idid ) { string sid = idid->to_string(); lhs << endl; lhs << indent << " "; if ( repurl.size() ) { lhs << "" << sid << ""; } else { lhs << sid; } } } else { // First ID lhs << "\n" << indent << " First ID: "; string sid = begin()->to_string(); if ( repurl.size() ) { lhs << "" << sid << ""; } else { lhs << sid; } // Last ID lhs << "\n" << indent << " Last ID: "; sid = rbegin()->to_string(); if ( repurl.size() ) { lhs << "" << sid << ""; } else { lhs << sid; } } return lhs; } //********************************************************************** // Free functions. //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const DatasetIdList& rhs) { return rhs.ostr(lhs, ""); } //**********************************************************************