output.hh revision 5749
11388SN/A/* 21388SN/A * Copyright (c) 2005 The Regents of The University of Michigan 31388SN/A * All rights reserved. 41388SN/A * 51388SN/A * Redistribution and use in source and binary forms, with or without 61388SN/A * modification, are permitted provided that the following conditions are 71388SN/A * met: redistributions of source code must retain the above copyright 81388SN/A * notice, this list of conditions and the following disclaimer; 91388SN/A * redistributions in binary form must reproduce the above copyright 101388SN/A * notice, this list of conditions and the following disclaimer in the 111388SN/A * documentation and/or other materials provided with the distribution; 121388SN/A * neither the name of the copyright holders nor the names of its 131388SN/A * contributors may be used to endorse or promote products derived from 141388SN/A * this software without specific prior written permission. 151388SN/A * 161388SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171388SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181388SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191388SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201388SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211388SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221388SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231388SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241388SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251388SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261388SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 291388SN/A */ 301388SN/A 311388SN/A#ifndef __BASE_OUTPUT_HH__ 321388SN/A#define __BASE_OUTPUT_HH__ 331388SN/A 345749Scws3k@cs.virginia.edu#include <ios> 351388SN/A#include <map> 361388SN/A#include <string> 371388SN/A 381388SN/Aclass OutputDirectory 391388SN/A{ 401388SN/A private: 411388SN/A typedef std::map<std::string, std::ostream *> map_t; 421388SN/A 431388SN/A map_t files; 441388SN/A std::string dir; 451388SN/A 465749Scws3k@cs.virginia.edu std::string resolve(const std::string &name) const; 475749Scws3k@cs.virginia.edu 485749Scws3k@cs.virginia.edu protected: 495749Scws3k@cs.virginia.edu std::ostream *checkForStdio(const std::string &name) const; 505749Scws3k@cs.virginia.edu std::ostream *openFile(const std::string &filename, 515749Scws3k@cs.virginia.edu std::ios_base::openmode mode = std::ios::trunc) const; 525402Ssaidi@eecs.umich.edu 531388SN/A public: 541388SN/A OutputDirectory(); 551388SN/A ~OutputDirectory(); 561388SN/A 571388SN/A void setDirectory(const std::string &dir); 585749Scws3k@cs.virginia.edu const std::string &directory() const; 591388SN/A 604840Ssaidi@eecs.umich.edu std::ostream *create(const std::string &name, bool binary = false); 611388SN/A std::ostream *find(const std::string &name); 621388SN/A 631388SN/A static bool isFile(const std::ostream *os); 641388SN/A static inline bool isFile(const std::ostream &os) { return isFile(&os); } 651388SN/A}; 661388SN/A 671388SN/Aextern OutputDirectory simout; 681388SN/A 691388SN/A#endif // __BASE_OUTPUT_HH__ 70