refactor: extract core domain dof modules
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/Core/Types.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
enum class Severity { Info, Warning, Error };
|
||||
|
||||
struct SourceLocation {
|
||||
std::string file;
|
||||
LocalIndex line = 0;
|
||||
std::string keyword;
|
||||
};
|
||||
|
||||
struct Diagnostic {
|
||||
Severity severity = Severity::Error;
|
||||
std::string code;
|
||||
std::string message;
|
||||
SourceLocation source;
|
||||
};
|
||||
|
||||
inline bool hasError(const std::vector<Diagnostic>& diagnostics) {
|
||||
return std::any_of(diagnostics.begin(), diagnostics.end(), [](const Diagnostic& diagnostic) {
|
||||
return diagnostic.severity == Severity::Error;
|
||||
});
|
||||
}
|
||||
|
||||
inline bool containsDiagnostic(const std::vector<Diagnostic>& diagnostics, const std::string& code) {
|
||||
return std::any_of(diagnostics.begin(), diagnostics.end(), [&](const Diagnostic& diagnostic) {
|
||||
return diagnostic.code == code;
|
||||
});
|
||||
}
|
||||
|
||||
inline Diagnostic makeDiagnostic(Severity severity, std::string code, std::string message, std::string keyword,
|
||||
std::string file = "<domain>", LocalIndex line = 0) {
|
||||
return {severity, std::move(code), std::move(message), {std::move(file), line, std::move(keyword)}};
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,94 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/Core/Types.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
inline std::string trim(std::string text) {
|
||||
auto is_space = [](unsigned char c) { return std::isspace(c) != 0; };
|
||||
text.erase(text.begin(), std::find_if(text.begin(), text.end(), [&](unsigned char c) { return !is_space(c); }));
|
||||
text.erase(std::find_if(text.rbegin(), text.rend(), [&](unsigned char c) { return !is_space(c); }).base(), text.end());
|
||||
return text;
|
||||
}
|
||||
|
||||
inline std::string lower(std::string text) {
|
||||
std::transform(text.begin(), text.end(), text.begin(), [](unsigned char c) {
|
||||
return static_cast<char>(std::tolower(c));
|
||||
});
|
||||
return text;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> splitCsv(const std::string& line) {
|
||||
std::vector<std::string> fields;
|
||||
std::string field;
|
||||
std::istringstream stream(line);
|
||||
while (std::getline(stream, field, ',')) {
|
||||
fields.push_back(trim(field));
|
||||
}
|
||||
if (!line.empty() && line.back() == ',') {
|
||||
fields.emplace_back();
|
||||
}
|
||||
return fields;
|
||||
}
|
||||
|
||||
inline std::optional<Real> parseReal(std::string token) {
|
||||
token = trim(token);
|
||||
if (token.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
std::replace(token.begin(), token.end(), 'D', 'E');
|
||||
std::replace(token.begin(), token.end(), 'd', 'e');
|
||||
try {
|
||||
std::size_t used = 0;
|
||||
Real value = std::stod(token, &used);
|
||||
if (used != token.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return value;
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::optional<GlobalId> parseInt64(const std::string& token) {
|
||||
std::string value_text = trim(token);
|
||||
if (value_text.empty()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
try {
|
||||
std::size_t used = 0;
|
||||
long long value = std::stoll(value_text, &used);
|
||||
if (used != value_text.size()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<GlobalId>(value);
|
||||
} catch (...) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
inline void addUnique(std::vector<GlobalId>& values, GlobalId value) {
|
||||
if (std::find(values.begin(), values.end(), value) == values.end()) {
|
||||
values.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<GlobalId> generatedRange(GlobalId first, GlobalId last, GlobalId increment) {
|
||||
std::vector<GlobalId> values;
|
||||
if (increment <= 0) {
|
||||
return values;
|
||||
}
|
||||
for (GlobalId value = first; value <= last; value += increment) {
|
||||
values.push_back(value);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "fesa/Util/Diagnostics.hpp"
|
||||
#include "fesa/Util/String.hpp"
|
||||
#include "fesa/ModuleInfo.hpp"
|
||||
|
||||
namespace fesa::module {
|
||||
|
||||
Reference in New Issue
Block a user