// JobIdList.cxx #include "dial_job/JobIdList.h" #include #include "dataset_util/XmlElement.h" #include "dataset_util/DtdRegistry.h" using std::string; using std::ostream; using dial::JobIdList; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Register the DTD. DtdRegistry::Status ISTAT = DtdRegistry::register_dtd("dial"); } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // DTD. const Text& JobIdList::dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); txt.append(""); } return txt; } //********************************************************************** // Member functions. //********************************************************************** // Default constructor. JobIdList::JobIdList() { } //********************************************************************** // Size constructor. JobIdList::JobIdList(size_t nele) : std::vector(nele) { } //********************************************************************** // XML constructor. JobIdList::JobIdList(const XmlElement& ele) { const XmlElement* pele = 0; if ( ele.name() == xml_name() ) { pele = &ele; } 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() == JobId::xml_name() ) { JobId id(child); assert( id.is_valid() ); push_back(id); } } } assert( size() == pele->children().size() ); } //********************************************************************** // Convert to XML. const XmlElement* JobIdList::xml(string label) const { XmlElement* pele = new XmlElement(xml_name()); pele->add_attribute("label", label); for ( const_iterator iid=begin(); iid!=end(); ++iid ) { pele->add_child(iid->xml()); } return pele; } //********************************************************************** // Free functions. //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const JobIdList& rhs) { JobIdList::size_type count = rhs.size(); lhs << "Job ID list has " << count; if ( count == 1 ) { lhs << " entry"; } else { lhs << " entries"; } if ( count > 0 ) lhs << ":"; for ( JobIdList::const_iterator ijid=rhs.begin(); ijid!=rhs.end(); ++ijid ) { lhs << "\n " << (*ijid).to_string(); } return lhs; } //**********************************************************************