You are here

Overriding the methods of the base class streambuf that are called when output should be written

The methods sync and overflow are called from the base class when the output buffer will be written to the console device, e.g. upon calling flush. The overriden methods of sync and overflow call WriteToConsole and WriteCharToConsole which do the real job.
int OG_constreambuf::sync()
{
  WriteToConsole();
  return(0);
}

int OG_constreambuf::overflow(int c)
{
  WriteToConsole();

  if (c != EOF)
    if (pbase() == epptr())
      WriteCharToConsole(c);
    else
      sputc(c);

  return 0;
}

The destructor and the method DeleteConsole are trivial.

OG_constreambuf::~OG_constreambuf()
{
  sync();

  if (pReserve)
    delete pReserve;
  DeleteConsole();
}

void OG_constreambuf::DeleteConsole()
{
  CloseHandle(hConsoleOut);

  FreeConsole();
}