/* $Id: output.h 5720 2010-09-09 05:42:48Z abehm $ Copyright (C) 2010 by The Regents of the University of California Redistribution of this file is permitted under the terms of the BSD license. Date: 01/30/2007 Author: Rares Vernica */ #ifndef _output_h_ #define _output_h_ #include #include #include #include #include #include #include #include #include "common/src/tr1_local.h" using namespace std; using namespace tr1; template void writeBin(const vector &data, const string &filenameData) { ofstream fileData(filenameData.c_str(), ios::out | ios::binary); if (!fileData) { cerr << "can't open output file \"" << filenameData << "\"" << endl; exit(EXIT_FAILURE); } cerr << "writing \"" << filenameData << "\"..."; cerr.flush(); for (typename vector::const_iterator dat = data.begin(); dat != data.end(); ++dat) fileData.write(reinterpret_cast(&*dat), sizeof(T)); fileData.close(); cerr << "OK" << endl; } void writeString(const vector &data, const string &filenameData); template ostream& operator<<(ostream& out, const vector &v) { out << '['; for(typename vector::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ']'; return out; } template ostream& operator<<(ostream& out, const multiset &v) { out << '('; for(typename multiset::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const set &v) { out << '('; for(typename set::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const unordered_set &v) { out << '('; for(typename unordered_set::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const map &v) { out << '('; for(typename map::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const multimap &v) { out << '('; for(typename multimap::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const unordered_map &v) { out << '('; for(typename unordered_map::const_iterator it = v.begin(); it != v.end(); it++) { if (it != v.begin()) { out << ", "; } out << *it; } out << ')'; return out; } template ostream& operator<<(ostream& out, const pair &p) { return out << '(' << p.first << ", " << p.second << ')'; } template void output(ostream& out, const T *const vect, unsigned size) { out << '['; for(unsigned i = 0; i < size; i++) { out << vect[i]; if (i < size - 1) out << ", "; } out << ']' << endl; } #endif