Get rid of Gryphn File API
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include <utils/types/gryphn_color.h>
|
#include <utils/types/gryphn_color.h>
|
||||||
#include <utils/types/gryphn_color_format.h>
|
#include <utils/types/gryphn_color_format.h>
|
||||||
#include <utils/types/gryphn_image_format.h>
|
#include <utils/types/gryphn_image_format.h>
|
||||||
#include <utils/files/gryphn_file.h>
|
#include <utils/gryphn_access_level.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
typedef uint32_t gnUInt;
|
typedef uint32_t gnUInt;
|
||||||
|
@@ -1,51 +0,0 @@
|
|||||||
#define GN_UTILS_CPP
|
|
||||||
#include "gryphn_file.h"
|
|
||||||
#include "fstream"
|
|
||||||
#include "iostream"
|
|
||||||
|
|
||||||
|
|
||||||
gnFile gnLoadFile(const gnString& path, gnFileType type) {
|
|
||||||
gnFile new_file = gnFile();
|
|
||||||
|
|
||||||
if (type == gnFileType::Text) {
|
|
||||||
std::ifstream file(gnToCString(path));
|
|
||||||
if (!file.is_open()) throw std::runtime_error("failed to open text file!"); // thats right I wont use std::vector but il use std::runtime_error my priorities are straight
|
|
||||||
// not as straight as me around ethan mooney, il see myself out now. (PS i actually did go to bed these will stop now)
|
|
||||||
|
|
||||||
std::string line;
|
|
||||||
while(std::getline(file, line)) {
|
|
||||||
gnListAdd(new_file.lines, gnCreateString(line.c_str()));
|
|
||||||
}
|
|
||||||
} else if (type == gnFileType::Binary) {
|
|
||||||
std::ifstream file(gnToCString(path), std::ios::ate | std::ios::binary);
|
|
||||||
|
|
||||||
if (!file.is_open()) throw std::runtime_error("failed to open file!");
|
|
||||||
|
|
||||||
size_t file_size = (size_t)file.tellg();
|
|
||||||
new_file.bytes = gnCreateList<gnChar>(file_size);
|
|
||||||
|
|
||||||
file.seekg(0);
|
|
||||||
file.read(gnListData(new_file.bytes), file_size);
|
|
||||||
|
|
||||||
file.close(); // straight from vulkan-tutorial.com, not as strai, imma stop myself now
|
|
||||||
}
|
|
||||||
new_file.path = path;
|
|
||||||
|
|
||||||
return new_file;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnString gnGetFileData(const gnFile& file) {
|
|
||||||
gnString file_data;
|
|
||||||
for (int i = 0; i < gnListLength(file.lines); i++) {
|
|
||||||
file_data += gnListGet(file.lines, i) + '\n';
|
|
||||||
}
|
|
||||||
return file_data;
|
|
||||||
} // why I dont just return the file as a list of lines, cuz thats the easy way this way revealed so many errors in my string class,
|
|
||||||
// dont you love it when you dont actually copy a string and then the data gets lost and you dont know why because your an idiot
|
|
||||||
// thats never happened to me...... yea so im an idiot shouve actually copied the bytes over not just haphazardly asigned them to a string.
|
|
||||||
|
|
||||||
gnString gnGetFilePath(const gnFile& file) {
|
|
||||||
return file.path;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnList<gnChar> gnGetFileBytes(const gnFile& file) { return file.bytes; }
|
|
@@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <utils/gryphn_access_level.h>
|
|
||||||
|
|
||||||
// TODO: this file API is shit
|
|
||||||
// have you ever wanted to write a file, well too bad cuz that shits a lot of work and im not doing allllll that
|
|
||||||
// also like im pretty sure something is fucked up in the reading of binary files, what, I dont know but something is
|
|
||||||
// other than that im pretty happy with it cuz like I still have zero fuckcking clue how it works
|
|
||||||
// the binary part that is
|
|
||||||
|
|
||||||
#include "../strings/gryphn_string.h"
|
|
||||||
#include "../lists/gryphn_list.h"
|
|
||||||
|
|
||||||
enum class gnFileType {
|
|
||||||
Text, Binary
|
|
||||||
};
|
|
||||||
|
|
||||||
struct gnFile {
|
|
||||||
ACCESS_LEVEL:
|
|
||||||
gnList<gnString> lines = gnCreateList<gnString>(); // if file type is string
|
|
||||||
gnList<gnChar> bytes = gnCreateList<gnChar>(); // if file type is binary
|
|
||||||
// ofc dumbass they should know what file type there loading
|
|
||||||
// wellllllll actually this is horrible cuz im storing the like 4 bytes it take for an empty list in every loaded file
|
|
||||||
// regardless of if there is actually any data in the list
|
|
||||||
// buttttt as code astetic once said "premature optimization is like totally the root of all evil bro *procedes to hit bong*"
|
|
||||||
// i think i remember that right, i need to fix this but templates are hard and im not
|
|
||||||
|
|
||||||
gnString path = gnCreateEmptyString();
|
|
||||||
gnFileType type = gnFileType::Text; // who loads binary files anyway *silence*, i do I guess thats why I wrote this
|
|
||||||
public:
|
|
||||||
gnFile() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
gnFile gnLoadFile(const gnString& path, gnFileType type = gnFileType::Text);
|
|
||||||
// gnFile gnCreateFile(const gnString& path);
|
|
||||||
// gnFile gnCreateFile();
|
|
||||||
// gnFile gnWriteFile(const gnFile& file);
|
|
||||||
// which fucking loser thought they were writing a file writing API
|
|
||||||
// ...... that was me, im lazy, its 10:30, 2.5 hours after I go to sleep, imma go to sleep.
|
|
||||||
|
|
||||||
gnString gnGetFilePath(const gnFile& file);
|
|
||||||
gnString gnGetFileData(const gnFile& file); // i should rename this
|
|
||||||
gnList<gnChar> gnGetFileBytes(const gnFile& file); // fuck object oriented code
|
|
||||||
// and fuck error detection the user can get the bytes of a text file if they want to cuz its slow to do error checking, its also smart but im slow
|
|
||||||
// so me and this project are one in the same
|
|
@@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
typedef int gnBool;
|
typedef int gnBool;
|
||||||
#define gnFalse 0;
|
#define gnFalse 0;
|
||||||
#define gnTrue 1;
|
#define gnTrue 1;
|
||||||
|
|
||||||
|
typedef size_t gnSize;
|
||||||
|
Reference in New Issue
Block a user