4 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
9 #include "OutputFile.h"
11 #include "userparams.h"
16 OutputFile::OutputFile()
21 OutputFile::~OutputFile()
23 // If it is open, close it and say that a file has been created!!!!!
27 utilityObject->info("%s file created: [%s]\n", typeOfFileMsg.c_str(),
32 bool OutputFile::openFile(std::string* fileName, const std::string msg, const std::string* path,
33 const std::string ext, const std::string fileType)
35 if (fileName->empty())
37 *fileName = getOutputFileName(msg, *path, ext);
45 file.reset(new std::ofstream(fileName->c_str(), std::ofstream::trunc));
49 utilityObject->error("Cannot open output file [%s]\n", fileName->c_str());
53 typeOfFileMsg = fileType;
58 bool OutputFile::isOpen()
60 return file->is_open();
63 std::ofstream* OutputFile::getPtrToFile()
68 std::string OutputFile::getOutputFileName(const std::string prompt, std::string path,
69 const std::string fileExtension)
72 std::string _fileName; // Will return this name.
74 _fileName = path + fileExtension;
76 if(_fileName.compare(userParameters->getSeqName()) == 0)
78 cerr << "WARNING: Output file name is the same as input file.\n";
79 if (userParameters->getMenuFlag())
81 message = "\n\nEnter new name to avoid overwriting [" + _fileName + "]: ";
82 utilityObject->getStr(message, temp);
89 else if (userParameters->getMenuFlag())
92 message = prompt + " [" + _fileName + "]";
93 utilityObject->getStr(message, temp);