Skip to content

Commit 06959ac

Browse files
committed
Initial commit
0 parents  commit 06959ac

File tree

362 files changed

+42080
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

362 files changed

+42080
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
docs/~$wip.docx

Source/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/c++
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=c++
3+
4+
### C++ ###
5+
**/.vs/
6+
**/[Xx]64/
7+
8+
# Prerequisites
9+
**/*.d
10+
11+
# Compiled Object files
12+
**/*.slo
13+
**/*.lo
14+
**/*.o
15+
**/*.obj
16+
17+
# Precompiled Headers
18+
**/*.gch
19+
**/*.pch
20+
21+
# Compiled Dynamic libraries
22+
**/*.so
23+
**/*.dylib
24+
**/*.dll
25+
26+
# Fortran module files
27+
**/*.mod
28+
**/*.smod
29+
30+
# Compiled Static libraries
31+
**/*.lai
32+
**/*.la
33+
**/*.a
34+
**/*.lib
35+
36+
# Executables
37+
**/*.exe
38+
**/*.out
39+
**/*.app
40+
41+
# End of https://www.toptal.com/developers/gitignore/api/c++

Source/SnapshotLib/LibraryUtils.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Developed by Michael-Evangelos Diamantis Aug-2024
3+
* for SAE Athens CMN6302 - Major.
4+
* Source: https://github.com/MichaelEvangelosD/cmn6302_majorSAE
5+
*/
6+
#include "pch.h"
7+
8+
/*
9+
Returns the file count from inside the passed path.
10+
@param const std::string _path: A string containing the absolute path to a directory.
11+
@throw fs::filesystem_error: Passed _path does not exist.
12+
@return The file count from inside the passed _path.
13+
*/
14+
int getFileCount(const std::string _path) {
15+
int fileCount = 0;
16+
17+
if (!fs::exists(_path)) {
18+
throw fs::filesystem_error("Passed _path does not exist.", std::filesystem::directory_entry(), std::make_error_code(std::errc::no_such_file_or_directory));
19+
}
20+
21+
for (const auto& entry : fs::directory_iterator(_path)) {
22+
//Count only files
23+
if (entry.is_regular_file()) {
24+
fileCount++;
25+
}
26+
}
27+
28+
return fileCount;
29+
}
30+
31+
/*
32+
@return The current date in a DD_MM_YYYY format as a string.
33+
*/
34+
std::string getCurrentDate() {
35+
time_t now;
36+
time(&now);
37+
38+
struct tm current_time;
39+
localtime_s(&current_time, &now);
40+
41+
std::stringstream ss;
42+
ss << std::setfill('0') << std::setw(2) << current_time.tm_mday << "_"
43+
<< std::setw(2) << current_time.tm_mon + 1 << "_"
44+
<< current_time.tm_year + 1900;
45+
46+
return ss.str();
47+
}
48+
49+
/*
50+
@param const std::string& _format: The format to replace the values from.
51+
@param const std::string& date: The date value to replace the {date}.
52+
@param const int cnt: The count value to replace the {count}.
53+
@return Replaces the date and count from the passed format and returns it.
54+
e.g.: {date}_{count} - 02_03_2024_1
55+
*/
56+
std::string formatSaveString(const std::string& _format, const std::string& date, const int cnt) {
57+
std::string result = _format;
58+
std::size_t pos = result.find(_format);
59+
if (pos != std::string::npos) {
60+
result.replace(pos, _format.length(), date + "_" + std::to_string(cnt));
61+
}
62+
return result;
63+
}
64+
65+
/*
66+
Combines the passed strings with the corresponding system-relative path combination symbol.
67+
No checking takes place.
68+
@param const std::string _base: The base absolute path.
69+
@param const std::string _exte: The extension relative path.
70+
@return The combined path string.
71+
*/
72+
std::string combinePath(const std::string _base, const std::string _exte) {
73+
fs::path _comb = fs::path(_base) / fs::path(_exte);
74+
return _comb.string();
75+
}
76+
77+
/*
78+
Creates the passed directory if it does not exist.
79+
@param const std::string& path: The directory absolute path.
80+
*/
81+
void handleSaveDirectory(const std::string& path) {
82+
fs::path directoryPath(path);
83+
84+
if (!fs::exists(directoryPath)) {
85+
fs::create_directory(directoryPath);
86+
}
87+
}
88+
89+
/*
90+
@param const std::string& path: Absolute path to the file.
91+
@return True if the file exists, false otherwise.
92+
*/
93+
bool fileExists(const std::string& path) {
94+
fs::path directoryPath(path);
95+
96+
return fs::exists(directoryPath);
97+
}

Source/SnapshotLib/LibraryUtils.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Developed by Michael-Evangelos Diamantis Aug-2024
3+
* for SAE Athens CMN6302 - Major.
4+
* Source: https://github.com/MichaelEvangelosD/cmn6302_majorSAE
5+
*/
6+
#pragma once
7+
8+
#include "pch.h"
9+
10+
namespace fs = std::filesystem;
11+
12+
/*Method declaration*/
13+
int getFileCount(std::string _path);
14+
/*Method declaration*/
15+
std::string getCurrentDate();
16+
/*Method declaration*/
17+
std::string formatSaveString(const std::string& _format, const std::string& date, const int cnt);
18+
/*Method declaration*/
19+
std::string combinePath(const std::string _base, const std::string _exte);
20+
/*Method declaration*/
21+
void handleSaveDirectory(const std::string& path);
22+
/*Method declaration*/
23+
bool fileExists(const std::string& path);

0 commit comments

Comments
 (0)