Created
November 15, 2017 20:25
-
-
Save Platin21/271f1889229fd40ad79f01c601b907d1 to your computer and use it in GitHub Desktop.
Tried to build an Abstraction around files is only a pattern not more.
This file contains 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
#ifdef __CHAR_UNSIGNED__ | |
using UChar = unsigned char; | |
#else | |
using UChar = char; | |
#endif | |
using i64 = long long; | |
i64 CStrLenghtOf(UChar* text) | |
{ | |
i64 i = 0; | |
while(*text){ text += 1; i += 1; } | |
return i; | |
} | |
struct UStr | |
{ | |
UChar* text; | |
i64 bytelenght; | |
UStr(const char* txt) | |
: text((UChar*)txt), | |
bytelenght(CStrLenghtOf((UChar*)txt)) {}; | |
UStr(UChar* text,i64 withLenght) | |
: text((UChar*) text), | |
bytelenght(withLenght) {}; | |
UStr() | |
: text( (UChar*)""), | |
bytelenght(1) {}; | |
}; | |
bool reverseFind(UChar charackter,UStr& inUstr) | |
{ | |
i64 len = inUstr.bytelenght; | |
UChar* stringEnd = inUstr.text + inUstr.bytelenght; | |
while(*stringEnd != charackter) | |
{ | |
stringEnd -= 1; | |
len -= 1; | |
if(len == 0) return false; | |
} | |
return true; | |
} | |
bool reverseFind(UChar charackter,UChar beforeThisCharackter,UStr& inUstr) | |
{ | |
i64 len = inUstr.bytelenght; | |
UChar* stringEnd = inUstr.text + inUstr.bytelenght; | |
while(*stringEnd != charackter && *stringEnd != beforeThisCharackter) | |
{ | |
stringEnd -= 1; | |
len -= 1; | |
if(len == 0) return false; | |
} | |
return true; | |
} | |
struct Path | |
{ | |
UStr filePath; | |
bool valid; | |
Path(UStr ustr) | |
{ | |
filePath = ustr; | |
} | |
}; | |
class File | |
{ | |
private: | |
int handle; | |
public: | |
void open(UStr Path) | |
{ | |
if(*(Path.text+Path.bytelenght) != '/') | |
{ | |
if(reverseFind('.','/',Path)) | |
{ | |
handle = 3; | |
} | |
} | |
}; | |
void close() | |
{ | |
handle = 0; | |
}; | |
}; | |
int main() | |
{ | |
File f = {}; | |
f.open("/test/version/hallo.txt"); | |
f.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So much stuff wich i wouldn't use anymore.