#include <cassert>
#include <fstream>
using namespace std;

#include <message.h>

message* message::global = 0;


message& messageglobal()
{
  assert(message::global);
  return (*message::global);
}

messagefile::messagefile()
{
  assert(false);
}

ostream& messagefile::operator()()
{
  assert(os!=0);
  return *os;
}

messagefile::~messagefile()
{
  delete os;
  os = 0;
}

messagefile::messagefile
(
  stringc & filename,
  boolc killprevfile,
  boolc binary
)
{
  std::_Ios_Openmode i = std::ios::out|std::ios::app;

  // Can not append and truncate a file at the same time.
  if (killprevfile)
    i = std::ios::out | std::ios::trunc;

  // UNTESTED
  if (binary)
    i = i | std::ios::binary; 

  os = new fstream(filename.c_str(),i);
}

// TODO look at tokenizer
// TODO Looked at deriving from ostream - apparently a
//   buffer is needed so perahps derive from stringstream
//   See http://www.tacc.utexas.edu/services/userguides/pgi/pgC++_lib/stdlibug/cre_2288.htm


void messagelist::pre()
{
  ss.str("");
}

void messagelist::post()
{
  vi.push_back(ss.str());
}

ostream& messagelist::operator()() 
{ 
  return ss; 
}








