Skip to content

Commit

Permalink
Add Vector and Structure Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Kokomi000 committed Dec 23, 2023
1 parent bee998c commit ac39fc0
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 56 deletions.
199 changes: 155 additions & 44 deletions Data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,173 @@

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

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

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

//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();
//Create Dir IF Not Exist
if (!std::filesystem::exists(Path)) std::filesystem::create_directory(Path);

}

std::vector<std::filesystem::path> Array::List(){
std::vector<std::filesystem::path> Temp;
for (const auto& entry : std::filesystem::directory_iterator(Path)) Temp.push_back(entry.path());
return Temp;
}

//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;
void Array::Read(const std::string FileName){
//Create File IF Not Exist
if (!std::filesystem::exists(Path / FileName)) {
std::fstream Create(Path / FileName, std::ios::out);
Create.close();
}

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

}
FileData.close();

}
void Array::Save(const std::string FileName) {
//Create File IF Not Exist
if (!std::filesystem::exists(Path / FileName)) {
std::fstream Create(Path / FileName, std::ios::out);
Create.close();
}

//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 / FileName, std::ios::out);
FileData << Temp;
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 Array::Remove(const std::string FileName){
std::filesystem::remove(Path / FileName);
}

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

}

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

//############################################## Vector ##############################################//

Vector::Vector(const std::string FilePath, const int FileSize)
{
//Set Size
Content.reserve(FileSize);

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

//Create Dir IF Not Exist
if (!std::filesystem::exists(Path)) std::filesystem::create_directory(Path);

}

std::vector<std::filesystem::path> Vector::List(){
std::vector<std::filesystem::path> Temp;
for (const auto& entry : std::filesystem::directory_iterator(Path)) Temp.push_back(entry.path());
return Temp;
}

bool Data::Exist(){
std::fstream FileData(Path, std::ios::in);
std::string Check;
FileData >> Check;
FileData.close();
if(Check == "") return false;
return true;
void Vector::Read(const std::string FileName){
//Create File IF Not Exist
if (!std::filesystem::exists(Path / FileName)) {
std::fstream Create(Path / FileName, std::ios::out);
Create.close();
}

//Read File
std::fstream FileData(Path / FileName, std::ios::in);
std::string Line;
while (!FileData.eof()) {
std::getline(FileData, Line);
Content.emplace_back(Line);
}
FileData.close();

}

void Vector::Save(const std::string FileName) {
//Create File IF Not Exist
if (!std::filesystem::exists(Path / FileName)) {
std::fstream Create(Path / FileName, std::ios::out);
Create.close();
}

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

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

}

std::string Vector::Get(const int Slot){
if(Slot >= (Content.size() - 1)) return "";
return Content[Slot];
}

void Vector::Add(const std::string Element){
Content.emplace_back(Element);
}

void Vector::Change(const int Slot, const std::string Element){ //Need be Seted
Content[Slot] = Element;
}

void Vector::Clear(){
Content.clear();
}

void Vector::Remove(const std::string FileName){
std::filesystem::remove(Path / FileName);
}

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

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

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

class Data
namespace Data
{
public:
std::string* Content;
std::filesystem::path Path;
int Size = 0;
//############################################## Array Format ##############################################//
class Array {
public:
std::string* Content;
std::filesystem::path Path;
int Size = 0;

public:
Array(const std::string FilePath = "Data/", const int FileSize = 0);
std::vector<std::filesystem::path> List();
void Read(const std::string FileName);
void Save(const std::string FileName);
void Remove(const std::string FileName);
bool Exist(const std::string FileName);
~Array();
};

//############################################## Vector Format ##############################################//

class Vector {
public:
std::vector<std::string> Content;
std::filesystem::path Path;

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();
public:
Vector(const std::string FilePath = "Data/", const int FileSize = 0);
std::vector<std::filesystem::path> List();
void Read(const std::string FileName);
void Save(const std::string FileName);
std::string Get(const int Slot);
void Add(const std::string Element);
void Change(const int Slot, const std::string Element);
void Clear();
void Remove(const std::string FileName);
bool Exist(const std::string FileName);
};

};

0 comments on commit ac39fc0

Please sign in to comment.