// joycub V2 - an interpeter for the programming language Joy
// (c) 2004-2006 Sergey Zubkov 
// prototype.cc - prototype module to test out the new design considerations
static char RCSID[] ="$Id: file.cc,v 1.1 2006/02/27 18:50:34 cubbi Exp cubbi $";

#include <iostream>
#include <sstream>
#include "exceptions.h"
#include "file.h"

// global object counters (for memory debugging)
int file_type_count = 0;

JC_file::JC_file() {};

JC_file::JC_file(FILE* f) : content(f) { file_type_count++; };

JC_file::JC_file(const JC_file& j) {
	content = j.content;
	file_type_count++;
};

JC_file::~JC_file(void) {
	if(content!=stdin && content!=stdout && content!=stderr) fclose(content);
	file_type_count--;
};

std::string JC_file::to_string(void) const {
	if(content==stdin) return "stdin";
	else if(content==stdout) return "stdout";
	else if(content==stderr) return "stderr";
	else return "file:"+fileno(content);
}
