-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSettings.h
More file actions
157 lines (136 loc) · 4.56 KB
/
Settings.h
File metadata and controls
157 lines (136 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
class Settings
{
private:
// Static members
static std::string DOT_FILE;
static std::string OUTPUT_IMAGE;
// Graph settings
static std::string GRAPH_LABEL;
static int LABEL_FONTSIZE;
// Node settings
static std::string NODE_SHAPE;
static std::string NODE_STYLE;
static std::string NODE_COLOR;
static std::string NODE_FONTCOLOR;
static int NODE_FONTSIZE;
// Edge settings
static std::string EDGE_COLOR;
public:
// Getters
static std::string getDotFile() { return DOT_FILE; }
static std::string getOutputImage() { return OUTPUT_IMAGE; }
static std::string getGraphLabel() { return GRAPH_LABEL; }
static int getGraphFontSize() { return LABEL_FONTSIZE; }
static std::string getNodeShape() { return NODE_SHAPE; }
static std::string getNodeStyle() { return NODE_STYLE; }
static std::string getNodeColor() { return NODE_COLOR; }
static std::string getNodeFontColor() { return NODE_FONTCOLOR; }
static int getNodeFontSize() { return NODE_FONTSIZE; }
static std::string getEdgeColor() { return EDGE_COLOR; }
// Setters
static void setDotFile(const std::string &dotFile) { DOT_FILE = dotFile; }
static void setOutputImage(const std::string &outputImage) { OUTPUT_IMAGE = outputImage; }
static void setGraphLabel(const std::string &label) { GRAPH_LABEL = label; }
static void setGraphFontSize(int fontSize) { LABEL_FONTSIZE = fontSize; }
static void setNodeShape(const std::string &shape) { NODE_SHAPE = shape; }
static void setNodeStyle(const std::string &style) { NODE_STYLE = style; }
static void setNodeColor(const std::string &color) { NODE_COLOR = color; }
static void setNodeFontColor(const std::string &fontColor) { NODE_FONTCOLOR = fontColor; }
static void setNodeFontSize(int fontSize) { NODE_FONTSIZE = fontSize; }
static void setEdgeColor(const std::string &color) { EDGE_COLOR = color; }
// Function to read settings from a file
static void getSettings(const std::string &filename)
{
std::ifstream file(filename);
if (!file.is_open())
{
std::cerr << "Could not open settings file: " << filename << std::endl;
std::cout << "Using default settings..." << std::endl;
std::cout << "Press [Enter] to continue...";
std::cin.get();
return;
}
std::string line;
while (std::getline(file, line))
{
std::stringstream ss(line);
std::string key, value;
if (std::getline(ss, key, '=') && std::getline(ss, value))
{
// Trim whitespace (if any)
key.erase(key.find_last_not_of(" \n\r\t") + 1);
value.erase(value.find_last_not_of(" \n\r\t") + 1);
// Set the appropriate setting based on the key
if (key == "DOT_FILE")
{
DOT_FILE = value;
}
else if (key == "OUTPUT_IMAGE")
{
OUTPUT_IMAGE = value;
}
else if (key == "GRAPH_LABEL")
{
GRAPH_LABEL = value;
}
else if (key == "LABEL_FONTSIZE")
{
LABEL_FONTSIZE = std::stoi(value);
}
else if (key == "NODE_SHAPE")
{
NODE_SHAPE = value;
}
else if (key == "NODE_STYLE")
{
NODE_STYLE = value;
}
else if (key == "NODE_COLOR")
{
NODE_COLOR = value;
}
else if (key == "NODE_FONTCOLOR")
{
NODE_FONTCOLOR = value;
}
else if (key == "NODE_FONTSIZE")
{
NODE_FONTSIZE = std::stoi(value);
}
else if (key == "EDGE_COLOR")
{
EDGE_COLOR = value;
}
}
}
file.close();
}
// Function to set and save settings to a file
static void setSettings(const std::string &filename)
{
std::ofstream settingsFile(filename);
if (settingsFile.is_open())
{
settingsFile << "DOT_FILE=" << DOT_FILE << "\n";
settingsFile << "OUTPUT_IMAGE=" << OUTPUT_IMAGE << "\n";
settingsFile << "GRAPH_LABEL=" << GRAPH_LABEL << "\n";
settingsFile << "LABEL_FONTSIZE=" << LABEL_FONTSIZE << "\n";
settingsFile << "NODE_SHAPE=" << NODE_SHAPE << "\n";
settingsFile << "NODE_STYLE=" << NODE_STYLE << "\n";
settingsFile << "NODE_COLOR=" << NODE_COLOR << "\n";
settingsFile << "NODE_FONTCOLOR=" << NODE_FONTCOLOR << "\n";
settingsFile << "NODE_FONTSIZE=" << NODE_FONTSIZE << "\n";
settingsFile << "EDGE_COLOR=" << EDGE_COLOR << "\n";
settingsFile.close();
}
else
{
std::cerr << "Error: Unable to open settings file for writing.\n";
}
}
};