-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.h
More file actions
149 lines (124 loc) · 4.83 KB
/
Copy pathutilities.h
File metadata and controls
149 lines (124 loc) · 4.83 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
/******************************************************************************
* Filename: utilities.h
* Project: AMCSET
* Author: Nathaniel Thomas
* Date Created: March 12, 2024
* Date Modified: April 30, 2024
* File Version: 1.0
* Group: Dr. Shao's RMSLCF Group
*
* Description:
* This file contains useful utilities and constants used by the
* main function in the AMCSET program
*
*
* Revision History
* 1.0:
* - File created
* See main.cpp for other revision history
*****************************************************************************/
#ifndef UTILITIES_H
#define UTILITIES_H
// Library includes
#include <cstdlib>
#include <cstddef>
#include <iostream>
// Local includes
#include "AMCSET_classes.h"
// Define a struct to store settings
struct Arguments {
std::string filename;
bool time;
bool displaySettings;
bool progress;
};
// Define a custom exception that carries an exit status
class ExitException : public std::exception {
public:
ExitException(int status);
int status;
};
class InputFields;
// This class is for handler USER IO, output file data is handled by the Simulation::writeData() function
class IOHandler {
private:
// Private constructor to prevent external instantiation
IOHandler(
std::shared_ptr<InputFields> input,
std::istream& inputStream,
std::ostream& outputStream,
std::ostream& errorStream);
// Static instance pointer for a single IOHandler instance
static std::shared_ptr<IOHandler> instance;
// Constants
const std::string_view inputNotInitializedMessage = "InputFields input has not been initialized.";
const std::string_view helpMessage =
R"(AMCSET Version 1.0
Author: Nathaniel Thomas
Contact: nathaniel@swbell.net
Release date: March 12, 2024
This is a program for simulating ion and electron bombardment in materials.
Usage: ./AMCSET [options][paths...]
Options
-f --filename <filename> Read settings for AMCSET from <filename>. [Default="settings.txt"]
-t --time Record execution time and output to standard output.
-s --settings Display an example settings file.
-d --display Output the active settings to the standard output.
-h --help Display this help message.
-p --progress Display the progress of the simulation while it is running to the standard output.
)";
std::string settingsMessage;
// Private Members
std::shared_ptr<InputFields> input;
std::istream& inputStream;
std::ostream& outputStream;
std::ostream& errorStream;
Arguments arguments;
bool argumentsSet = false;
public:
// Instantiators
static std::shared_ptr<IOHandler> getInstance();
static std::shared_ptr<IOHandler> getInstance(
std::shared_ptr<InputFields> input,
std::istream& inputStream = std::cin,
std::ostream& outputStream = std::cout,
std::ostream& errorStream = std::cerr);
// Getters
std::shared_ptr<InputFields> getInput() const;
Arguments& getArguments();
std::istream& getInputStream() const;
std::ostream& getOutputStream() const;
std::ostream& getErrorStream() const;
// Setters
void setInput(std::shared_ptr<InputFields> input);
// No setters for reference members, as they cannot be rebound.
// Functions
void parseCommandLine(const int argc, const char* argv[]); // Add scope resolution operator
bool promptContinue();
void clearLine();
void checkHardwareThreads();
void checkDisplayOption(); // Add scope resolution operator
void writeSettingsToFile(const std::string& settingsFilename);
bool parseSetting(const std::string& line, std::string& name, std::string& value);
bool stringToBool(const std::string& str);
void handleFileOpenError(const std::string& filename);
void readSettingsFromFile();
void handleNoOutputDirectory(const std::filesystem::path& outputPath);
void handleOutputFileOpenError(
OutputType outputType,
std::filesystem::path outputPath,
std::string filename,
int bombardmentID);
bool areArgumentsSet() const;
// Templated function
template<typename T>
IOHandler& operator<<(const T& message) {
errorStream << message;
return *this;
}
IOHandler& operator<<(std::ostream& (*func)(std::ostream&)) {
func(errorStream);
return *this;
}
};
#endif