/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NIOHANDLE__
#define	__NIOHANDLE__


		#include "filesystem/io_base.h"
		#include "memory/nweak_ptr.h"


namespace GS {
	namespace IO {

//
class	Handle
{
		WeakPtr <Base> io_sys;

public:

		NPLACEMENT_NEW(Filesystem)

virtual	size_t			GetSize();

virtual	size_t			Rewind();
virtual	bool			IsEOF();

virtual	size_t			Tell();
virtual	size_t			Seek(ptrdiff_t, Base::SeekRef = Base::SeekCurrent);

virtual	size_t			Read(void *, size_t);
virtual	size_t			Write(const void *, size_t);

template <class T> Handle &operator << (const T &v)
		{
			io_sys->Write(this, &v, sizeof(T));
			return *this;
		}
template <class T> Handle &operator >> (T &v)
		{
			io_sys->Read(this, &v, sizeof(T));
			return *this;
		}
		Handle			&operator << (const char *);
		Handle			&operator << (char *);

template <class T> bool	Write(const T &v)
		{	return asbool(io_sys->Write(this, &v, sizeof(T)));	}
template <class T> T	Read()
		{
			T v;
			io_sys->Read(this, &v, sizeof(T));
			return v;
		}

		Base			*GetIOSystem() const
		{	return io_sys.c_ptr();	}

		Handle(Base *);
virtual	~Handle();
};

	}	// IO
}	// GS


#endif	// __NIOHANDLE__
