1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/**
* Author: Mark Larkin
*
* Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "OutputFile.h"
#include "utils.h"
#include "userparams.h"
namespace clustalw
{
OutputFile::OutputFile()
{
}
OutputFile::~OutputFile()
{
// If it is open, close it and say that a file has been created!!!!!
if(file.get())
{
file->close();
utilityObject->info("%s file created: [%s]\n", typeOfFileMsg.c_str(),
name.c_str());
}
}
bool OutputFile::openFile(std::string* fileName, const std::string msg, const std::string* path,
const std::string ext, const std::string fileType)
{
if (fileName->empty())
{
*fileName = getOutputFileName(msg, *path, ext);
if(fileName->empty())
{
return false;
}
}
file.reset(new std::ofstream(fileName->c_str(), std::ofstream::trunc));
if(!file->is_open())
{
utilityObject->error("Cannot open output file [%s]\n", fileName->c_str());
return false;
}
name = *fileName;
typeOfFileMsg = fileType;
return true;
}
bool OutputFile::isOpen()
{
return file->is_open();
}
std::ofstream* OutputFile::getPtrToFile()
{
return file.get();
}
std::string OutputFile::getOutputFileName(const std::string prompt, std::string path,
const std::string fileExtension)
{
std::string temp;
std::string _fileName; // Will return this name.
std::string message;
_fileName = path + fileExtension;
if(_fileName.compare(userParameters->getSeqName()) == 0)
{
cerr << "WARNING: Output file name is the same as input file.\n";
if (userParameters->getMenuFlag())
{
message = "\n\nEnter new name to avoid overwriting [" + _fileName + "]: ";
utilityObject->getStr(message, temp);
if(temp != "")
{
_fileName = temp;
}
}
}
else if (userParameters->getMenuFlag())
{
message = prompt + " [" + _fileName + "]";
utilityObject->getStr(message, temp);
if(temp != "")
{
_fileName = temp;
}
}
return _fileName;
}
}
|