first commit
This commit is contained in:
66
include/platform/filesystem/io_alias.h
Normal file
66
include/platform/filesystem/io_alias.h
Normal file
@ -0,0 +1,66 @@
|
||||
/* -----------------------------------------------------------------------------
|
||||
GSFramework
|
||||
Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
|
||||
----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
#ifndef __NIOALIAS__
|
||||
#define __NIOALIAS__
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nstring/nstring.h"
|
||||
#include "container/nmap.h"
|
||||
|
||||
|
||||
namespace GS {
|
||||
namespace IO {
|
||||
class Handle;
|
||||
|
||||
/*!
|
||||
@short Alias proxy I/O.
|
||||
A simple proxy I/O to provide filename aliasing to another I/O system.
|
||||
@author Emmanuel Julien (ejulien@nworks.fr)
|
||||
*/
|
||||
class Alias : public Base
|
||||
{
|
||||
SharedPtr <Base> iofs;
|
||||
|
||||
public:
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
Map <String, String> alias_map;
|
||||
|
||||
String ResolveAlias(const char *path) const
|
||||
{
|
||||
Pair <String, String> *alias = alias_map.Get(path);
|
||||
return alias ? alias->value : path;
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
virtual Handle *Open(const char *path, Mode mode = IORead)
|
||||
{ return iofs->Open(ResolveAlias(path), mode); }
|
||||
virtual void Close(Handle *h)
|
||||
{ iofs->Close(h); }
|
||||
|
||||
virtual bool Delete(const char *path)
|
||||
{ return iofs->Delete(ResolveAlias(path)); }
|
||||
|
||||
virtual size_t Tell(Handle *h)
|
||||
{ return iofs->Tell(h); }
|
||||
virtual size_t Seek(Handle *h, ptrdiff_t offset, SeekRef seek_ref = SeekCurrent)
|
||||
{ return iofs->Seek(h, offset, seek_ref); }
|
||||
|
||||
virtual size_t Read(Handle *h, void *p, size_t size)
|
||||
{ return iofs->Read(h, p, size); }
|
||||
virtual size_t Write(Handle *h, const void *p, size_t size)
|
||||
{ return iofs->Write(h, p, size); }
|
||||
|
||||
Alias(Base *io) : iofs(io) {}
|
||||
};
|
||||
|
||||
} // IO
|
||||
} // GS
|
||||
|
||||
|
||||
#endif // __NIOALIAS__
|
||||
Reference in New Issue
Block a user