Skip to content

Commit 15e1cea

Browse files
committed
Fixed runtime type issue of newTime, added make file with debug and release options
1 parent 6d5df9c commit 15e1cea

File tree

7 files changed

+197
-4
lines changed

7 files changed

+197
-4
lines changed

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "(gdb) Launch",
5+
"type": "cppdbg",
6+
"request": "launch",
7+
"program": "${workspaceFolder}/tfold",
8+
"args": ["-n", "temp", "-t", "2", "-f", "m"],
9+
"stopAtEntry": false,
10+
"cwd": "${fileDirname}",
11+
"environment": [],
12+
"externalConsole": false,
13+
"MIMode": "gdb",
14+
"setupCommands": [
15+
{
16+
"description": "Enable pretty-printing for gdb",
17+
"text": "-enable-pretty-printing",
18+
"ignoreFailures": true
19+
},
20+
{
21+
"description": "Set Disassembly Flavor to Intel",
22+
"text": "-gdb-set disassembly-flavor intel",
23+
"ignoreFailures": true
24+
}
25+
]
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"files.associations": {
3+
"cctype": "cpp",
4+
"clocale": "cpp",
5+
"cmath": "cpp",
6+
"cstdarg": "cpp",
7+
"cstddef": "cpp",
8+
"cstdio": "cpp",
9+
"cstdlib": "cpp",
10+
"ctime": "cpp",
11+
"cwchar": "cpp",
12+
"cwctype": "cpp",
13+
"array": "cpp",
14+
"atomic": "cpp",
15+
"bit": "cpp",
16+
"*.tcc": "cpp",
17+
"chrono": "cpp",
18+
"codecvt": "cpp",
19+
"compare": "cpp",
20+
"concepts": "cpp",
21+
"cstdint": "cpp",
22+
"deque": "cpp",
23+
"list": "cpp",
24+
"string": "cpp",
25+
"unordered_map": "cpp",
26+
"vector": "cpp",
27+
"exception": "cpp",
28+
"algorithm": "cpp",
29+
"functional": "cpp",
30+
"iterator": "cpp",
31+
"memory": "cpp",
32+
"memory_resource": "cpp",
33+
"numeric": "cpp",
34+
"optional": "cpp",
35+
"random": "cpp",
36+
"ratio": "cpp",
37+
"string_view": "cpp",
38+
"system_error": "cpp",
39+
"tuple": "cpp",
40+
"type_traits": "cpp",
41+
"utility": "cpp",
42+
"initializer_list": "cpp",
43+
"iomanip": "cpp",
44+
"iosfwd": "cpp",
45+
"iostream": "cpp",
46+
"istream": "cpp",
47+
"limits": "cpp",
48+
"new": "cpp",
49+
"numbers": "cpp",
50+
"ostream": "cpp",
51+
"semaphore": "cpp",
52+
"sstream": "cpp",
53+
"stdexcept": "cpp",
54+
"stop_token": "cpp",
55+
"streambuf": "cpp",
56+
"thread": "cpp",
57+
"typeinfo": "cpp",
58+
"variant": "cpp"
59+
}
60+
}

.vscode/tasks.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"tasks": [
3+
{
4+
"type": "cppbuild",
5+
"label": "C/C++: g++ build active file",
6+
"command": "/usr/bin/g++",
7+
"args": [
8+
"-fdiagnostics-color=always",
9+
"-g",
10+
"${file}",
11+
"-o",
12+
"${fileDirname}/${fileBasenameNoExtension}"
13+
],
14+
"options": {
15+
"cwd": "${fileDirname}"
16+
},
17+
"problemMatcher": [
18+
"$gcc"
19+
],
20+
"group": {
21+
"kind": "build",
22+
"isDefault": true
23+
},
24+
"detail": "Task generated by Debugger."
25+
}
26+
],
27+
"version": "2.0.0"
28+
}

main

-69 KB
Binary file not shown.

main.cpp

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,78 @@
11
#include "src/TempFolder.hpp"
22
#include <chrono>
3-
#include <filesystem>
43
#include <thread>
4+
#include <vector>
5+
#include <algorithm>
6+
#include <cstdlib>
7+
#include <variant>
8+
#include <string>
9+
#include <type_traits>
10+
#include <iostream>
511

6-
int main() {
12+
class InputParser{
13+
public:
14+
InputParser (int &argc, char **argv){
15+
for (int i=1; i < argc; ++i)
16+
this->tokens.push_back(std::string(argv[i]));
17+
}
18+
/// @author iain
19+
const std::string& getCmdOption(const std::string &option) const{
20+
std::vector<std::string>::const_iterator itr;
21+
itr = std::find(this->tokens.begin(), this->tokens.end(), option);
22+
if (itr != this->tokens.end() && ++itr != this->tokens.end()){
23+
return *itr;
24+
}
25+
static const std::string empty_string("");
26+
return empty_string;
27+
}
28+
/// @author iain
29+
bool cmdOptionExists(const std::string &option) const{
30+
return std::find(this->tokens.begin(), this->tokens.end(), option)
31+
!= this->tokens.end();
32+
}
33+
private:
34+
std::vector <std::string> tokens;
35+
};
736

8-
TempFolder tf("temp", std::chrono::minutes(5));
9-
const std::filesystem::path filePath = "temp";
1037

38+
int main(int argc, char**argv) {
39+
bool gotTimeFormat = false;
40+
int time = 0;
41+
int v_index = -1;
42+
std::string filePath;
43+
std::variant<std::chrono::seconds,std::chrono::minutes,std::chrono::hours>newTime;
44+
45+
InputParser input(argc,argv);
46+
47+
if(input.cmdOptionExists("-n")){
48+
filePath = input.getCmdOption("-n");
49+
50+
}
51+
52+
if(input.cmdOptionExists("-t")){
53+
std::string s = input.getCmdOption("-t");
54+
time = std::atoi(s.c_str());
55+
}
56+
57+
if(input.cmdOptionExists("-f")){
58+
if(input.getCmdOption("-f") == "s"){
59+
newTime = std::chrono::seconds(time);
60+
}
61+
if(input.getCmdOption("-f") == "m"){
62+
newTime = std::chrono::minutes(time);
63+
}
64+
if(input.getCmdOption("-f") == "h"){
65+
newTime = std::chrono::hours(time);
66+
67+
}
68+
}
69+
70+
71+
TempFolder tf(filePath, std::holds_alternative<std::chrono::seconds>(newTime) ? std::get<0>(newTime) :
72+
std::holds_alternative<std::chrono::minutes>(newTime) ? std::get<1>(newTime) :
73+
std::get<2>(newTime)
74+
);
75+
1176
tf.openNewTempFolder();
1277
while (tf.getTimeLeft() > 0) {
1378

makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CXXFLAGS = -std=c++17
2+
CC = g++
3+
OBJS = main.cpp src/TempFolder.cpp
4+
5+
all: ${OBJS}
6+
${CC} ${OBJS} -o tfold ${CXXFLAGS}
7+
8+
debug: ${OBJS}
9+
${CC} ${OBJS} -o tfold ${CXXFLAGS} -g
10+
11+
clean:
12+
rm *.o tfold

tfold

110 KB
Binary file not shown.

0 commit comments

Comments
 (0)