Created
February 24, 2013 14:50
-
-
Save iaintshine/6217d915ce6d6731d13f to your computer and use it in GitHub Desktop.
Cross platform shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
// | |
// Abstract interface | |
// | |
class IFile | |
{ | |
public: | |
virtual ~IFile() = 0; | |
virtual std::error_code read_async( std::int8_t*, std::size_t, std::function<void(std::error_code)> callback ) = 0; | |
virtual std::error_code close( ) = 0; | |
}; | |
// | |
// OS Implementation | |
// | |
class ConcreteFile : public IFile | |
{ | |
virtual std::error_code close( ); | |
}; | |
// | |
// Abstract Factory ( cross ) or Factor method | |
// | |
class FileManager | |
{ | |
IFile* Open( const path&, ios::ios_base::openmode, std::error_code& ) | |
{ | |
return new ConcreteFile( ... ); | |
} | |
}; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
enum os | |
{ | |
windows, | |
osx | |
}; | |
template | |
< | |
os osid | |
> | |
class File | |
{ | |
// | |
// If you want them stack allocated :P | |
// | |
File( File&& ); | |
std::error_code close( ); | |
}; | |
template<> | |
class File<windows> | |
{ | |
File( File&& ); | |
std::error_code close( ); | |
private: | |
HANDLE m_hFile; | |
}; | |
template<> | |
std::error_code File<windows>::close() | |
{ | |
// | |
// Do something | |
// | |
} | |
class FileManager | |
{ | |
File Open( const path&, iost::ios_base::openmode, std::error_code& ) | |
{ | |
#ifdef _WINDOWS | |
return File<windows>( ... ); | |
#end | |
} | |
} ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment