From 56de7b8980af40f3166a75e057af955c71fa8de9 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Fri, 29 Nov 2024 08:28:18 +0800 Subject: [PATCH] Definition for SemVer utility class. --- include/n8/util/SemVer.hpp | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 include/n8/util/SemVer.hpp diff --git a/include/n8/util/SemVer.hpp b/include/n8/util/SemVer.hpp new file mode 100644 index 0000000..baf7501 --- /dev/null +++ b/include/n8/util/SemVer.hpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 - Nathanne Isip + * This file is part of N8. + * + * N8 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * N8 is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with N8. If not, see . + */ + +#ifndef N8_UTIL_SEMVER_HPP +#define N8_UTIL_SEMVER_HPP + +#include +#include + +namespace N8Util { + +class SemVer { +private: + int major; + int minor; + int patch; + std::optional preRelease; + std::optional buildMetadata; + +public: + SemVer( + int _major, + int _minor, + int _patch, + std::optional _preRelease = std::nullopt, + std::optional _buildMetadata = std::nullopt + ) : major(_major), + minor(_minor), + patch(_patch), + preRelease(_preRelease), + buildMetadata(_buildMetadata) {} + + int getMajor() const; + int getMinor() const; + int getPatch() const; + std::optional getPreRelease() const; + std::optional getBuildMetadata() const; + + void setMajor(int value); + void setMinor(int value); + void setPatch(int value); + void setPreRelease(const std::optional& value); + void setBuildMetadata(const std::optional& value); + + std::string toString() const; + + static std::optional parse(const std::string& version); + static bool validateSemVer(const std::string& version); +}; + +}; + +#endif