Skip to content

Commit

Permalink
Data LIB
Browse files Browse the repository at this point in the history
  • Loading branch information
Kokomi000 committed Dec 21, 2023
1 parent 8fc6f9a commit 3d25500
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "Scripts.h"

//############################################## Data ##############################################//

Data::Data(const int FileSize, const std::string FileName, const std::string FilePath)
{
//Set Size
Size = FileSize;
Content = new std::string[Size];

//Create File Paths
Path = std::filesystem::current_path() / FilePath / FileName;

//Create File IF Not Exist
if(!std::filesystem::exists(Path)){
std::filesystem::create_directory(Path.parent_path());
std::fstream Create(Path, std::ios::out);
Create.close();
}

//Read File
std::fstream FileData(Path, std::ios::in);
std::string Line;
for(int Count = 0; Count < Size; Count++){
std::getline(FileData, Line);
Content[Count] = Line;
}
FileData.close();

}

void Data::Save(){
//Create Temp String
std::string Temp;
for(int Count = 0; Count < Size; Count++){
Temp += Content[Count] + "\n";
}
Temp += "\0";

//Save Data
std::fstream FileData(Path, std::ios::out);
FileData << Temp;
FileData.close();

}

void Data::Add(const int Slot, const std::string Element){
Content[Slot] = Element;
}

bool Data::Exist(){
std::fstream FileData(Path, std::ios::in);
std::string Check;
FileData >> Check;
FileData.close();
if(Check == "") return false;
return true;

}

Data::~Data(){
delete[] Content;
}
21 changes: 21 additions & 0 deletions Data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <filesystem>
#include <fstream>

//############################################## Data ##############################################//

class Data
{
public:
std::string* Content;
std::filesystem::path Path;
int Size = 0;

public:
Data(const int FileSize, const std::string FileName, const std::string FilePath = "Data/");
void Save();
void Add(const int Slot, const std::string Element);
bool Exist();
~Data();

};

0 comments on commit 3d25500

Please sign in to comment.