view src/OutputDataWriter.cpp @ 56:4394c9490716 tip

minor changes
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Mon, 24 Dec 2012 18:58:39 +0000
parents e359b9bad811
children
line wrap: on
line source
/*
 *  outputDataWriter.cpp
 *  MultipleAudioMathcher
 *
 *  Created by Andrew on 25/04/2012.
 *  Copyright 2012 QMUL. All rights reserved.
 *
 */

#include "OutputDataWriter.h"

OutputDataWriter::OutputDataWriter(){
	filepath = "../../../data/output.txt";
	//openFile();
}

OutputDataWriter::~OutputDataWriter(){
	closeFile();
}

void OutputDataWriter::writeOutput(const int& liveTime, const int& rehearsalTime, const int& playedRehearsalTime){
	
	if (outputFile.is_open()){
		outputFile << liveTime/1000.0 << "\t" << rehearsalTime/1000.0 << "\t" << playedRehearsalTime/1000.0 << endl;
	}
}

void OutputDataWriter::writeValue(const double& valueOne, const double& valueTwo){
	
	if (outputFile.is_open()){
		outputFile << valueOne << "\t" << valueTwo << endl;
		printf("write value %f %f\n", valueOne, valueTwo);
	} else{
		printf("trying to write value but file closed\n");
	}
}


void OutputDataWriter::openFile(std::string pathname){
//	closeFile();
	filepath = pathname;
	printf("opening file '%s'\n", pathname.c_str());
	openFile();
}

void OutputDataWriter::openFile(){
	if (!outputFile.is_open()){
		outputFile.open(filepath.c_str());
		//printf("opening file %s\n", filepath.c_str());
	}else{
		printf("file already open! %s\n", filepath.c_str());
	}
}

void OutputDataWriter::closeFile(){
	if (outputFile.is_open()){
		outputFile.close();
		printf("closing file '%s'\n", filepath.c_str());
	}else {
	printf("but file is not open to be closed\n");
	}
}