/*********************************************************************
 * This file is part of the cpplibs suite.
 *
 * Copyright (C) 2001 Topi Mäenpää
 * All rights reserved.
 *
 * This program is free software. You can redistribute and/or modify
 * it under the terms of the free software licence found in the
 * accompanying file "COPYING". The licence terms must always be
 * redistributed with this source file. The above copyright notice
 * must be reproduced in all modified and unmodified copies of this
 * source file.
 *
 * $Revision: 1.9 $
 *********************************************************************/

#ifndef _IO_H
#define _IO_H

#include "../Exception.h"

#define inRead(in,ptr,size) do { in.read((char*)(ptr),size); if (!in) throw util::io::IOException("Input stream corrupted"); } while(0)
#define inIgnore(in,size) do { in.ignore(size); if (!in) throw util::io::IOException("Input stream corrupted"); } while(0)
#define inGetLine(in,ptr,size) do { in.getline((char*)(ptr),size); if (!in) throw util::io::IOException("Input stream corrupted"); } while(0)

#define outWrite(out,ptr,size) do { out.write((char*)(ptr),size); if (!out) throw util::io::IOException("Cannot write to output stream"); } while(0)

namespace util { namespace io {
	/**
	 * An exception for failed I/O events.
	 **/
	class IOException : public util::Exception
	{
	public:
		IOException(std::string message) : util::Exception(message) {}
	};

	/**
	 * An exception that is thrown when an end-of-file is encountered.
	 **/
	class EOFException : public IOException
	{
	public:
		EOFException(std::string message) : IOException(message) {}
	};
}}

#endif
