From 8f8a1f75590d5cd1e98922817f7c0ed797558138 Mon Sep 17 00:00:00 2001 From: ThirtySomething Date: Sat, 1 Apr 2023 12:56:15 +0200 Subject: [PATCH 1/2] NEW: Add version to factory - Enable version to be streamed from/to outputfile - Add fixed version number to project --- smcore/about.cpp | 2 +- smcore/factory.cpp | 21 +++++++++++++++++---- smcore/factory.h | 21 ++++++++++++++++++++- smcore/license.cpp | 1 + smcore/options.cpp | 1 + smcore/options.h | 3 ++- smcore/project.cpp | 7 ++++--- smcore/project.h | 10 ++++++++-- smcore/smcore.cpp | 1 + smcore/smstring.cpp | 1 + smcore/version.cpp | 20 +++++++++++++++++++- smcore/version.h | 27 +++++++++++++++++++++++++-- 12 files changed, 100 insertions(+), 15 deletions(-) diff --git a/smcore/about.cpp b/smcore/about.cpp index 59a0d39..13ace98 100644 --- a/smcore/about.cpp +++ b/smcore/about.cpp @@ -35,8 +35,8 @@ Version [InsertBuildInformationHere] SourceMonitor Team http://www.github.com/SourceMonitor © SourceMonitor Team)~~~~"; - return aboutText; } + //****************************************************************************** } } diff --git a/smcore/factory.cpp b/smcore/factory.cpp index 0077157..ef7cd6b 100644 --- a/smcore/factory.cpp +++ b/smcore/factory.cpp @@ -22,6 +22,8 @@ #include "factory.h" +#include + namespace smos { namespace smcore @@ -29,12 +31,23 @@ namespace smos //****************************************************************************** Options *Factory::getOptions(smos::smcore::SMString optionsfile) { - static Options *smOptions = nullptr; - if (nullptr == smOptions) + static std::map programOptions; + if (programOptions.find(optionsfile) == programOptions.end()) { - smOptions = new Options(optionsfile); + programOptions.insert(std::make_pair(optionsfile, new Options(optionsfile))); } - return smOptions; + return programOptions[optionsfile]; } + //****************************************************************************** + Version *Factory::getVersion(void) + { + static Version *smVersion = nullptr; + if (nullptr == smVersion) + { + smVersion = new Version(); + } + return smVersion; + } + //****************************************************************************** } } diff --git a/smcore/factory.h b/smcore/factory.h index c20512a..c4ab079 100644 --- a/smcore/factory.h +++ b/smcore/factory.h @@ -22,18 +22,37 @@ #pragma once -#include "options.h" #include + +#include "options.h" #include "smstring.h" +#include "version.h" namespace smos { namespace smcore { + /** + * @brief Factory class to retrieve specific objects from + */ class Factory { public: + /** + * @brief Get the options object + * + * @param optionsfile Name of options file + * + * @return Options* Pointer to options object + */ static Options *getOptions(smos::smcore::SMString optionsfile); + + /** + * @brief Get the version object + * + * @return Version* Pointer to version object + */ + static Version *getVersion(void); }; } } diff --git a/smcore/license.cpp b/smcore/license.cpp index d8dbf28..ada1c68 100644 --- a/smcore/license.cpp +++ b/smcore/license.cpp @@ -55,5 +55,6 @@ DEALINGS IN THE SOFTWARE. )~~~~"; return licenseText; } + //****************************************************************************** } } diff --git a/smcore/options.cpp b/smcore/options.cpp index dc56671..c01c854 100644 --- a/smcore/options.cpp +++ b/smcore/options.cpp @@ -54,5 +54,6 @@ namespace smos { this->m_logfileName = logfileName; } + //****************************************************************************** } } diff --git a/smcore/options.h b/smcore/options.h index 4e38b27..fe7ee8b 100644 --- a/smcore/options.h +++ b/smcore/options.h @@ -25,9 +25,10 @@ #pragma once -#include "smstring.h" #include +#include "smstring.h" + namespace smos { namespace smcore diff --git a/smcore/project.cpp b/smcore/project.cpp index ea16b1e..83ef0e6 100644 --- a/smcore/project.cpp +++ b/smcore/project.cpp @@ -21,6 +21,7 @@ //****************************************************************************** #include "project.h" + #include namespace smos @@ -28,7 +29,7 @@ namespace smos namespace smcore { //****************************************************************************** - Project::Project(void) + Project::Project(void) : m_ClassVersion(0) { } //****************************************************************************** @@ -73,13 +74,13 @@ namespace smos //****************************************************************************** std::ostream &operator<<(std::ostream &os, const Project &obj) { - os << obj.m_ProjectName << std::endl; + os << obj.m_ClassVersion << obj.m_ProjectName; return os; } //****************************************************************************** std::istream &operator>>(std::istream &is, Project &obj) { - is >> obj.m_ProjectName; + is >> obj.m_ClassVersion >> obj.m_ProjectName; return is; } //****************************************************************************** diff --git a/smcore/project.h b/smcore/project.h index 8b935c4..81d0781 100644 --- a/smcore/project.h +++ b/smcore/project.h @@ -22,11 +22,12 @@ #pragma once -#include +#include #include +#include -#include "smstring.h" #include "error.h" +#include "smstring.h" namespace smos { @@ -101,6 +102,11 @@ namespace smos friend std::istream &operator>>(std::istream &is, Project &obj); private: + /** + * @brief Number of current class version for versioning + */ + uint16_t m_ClassVersion; + /** * @brief Name of project */ diff --git a/smcore/smcore.cpp b/smcore/smcore.cpp index 8831439..8f4b9cc 100644 --- a/smcore/smcore.cpp +++ b/smcore/smcore.cpp @@ -30,5 +30,6 @@ namespace smos SMCore::SMCore(void) { } + //****************************************************************************** } } diff --git a/smcore/smstring.cpp b/smcore/smstring.cpp index 7d70e99..01b2d28 100644 --- a/smcore/smstring.cpp +++ b/smcore/smstring.cpp @@ -26,5 +26,6 @@ namespace smos { namespace smcore { + //****************************************************************************** } } diff --git a/smcore/version.cpp b/smcore/version.cpp index 066e2d5..eb3e25b 100644 --- a/smcore/version.cpp +++ b/smcore/version.cpp @@ -21,6 +21,7 @@ //****************************************************************************** #include "version.h" + #include namespace smos @@ -81,11 +82,28 @@ namespace smos return result; } //****************************************************************************** - void Version::SetVersion(const short &major, const short &minor, const short &revision) + void Version::SetVersion(const short major, const short minor, const short revision) { this->m_major = major; this->m_minor = minor; this->m_revision = revision; } + //****************************************************************************** + std::ostream &operator<<(std::ostream &os, const Version &obj) + { + os << obj.m_major; + os << obj.m_minor; + os << obj.m_revision; + return os; + } + //****************************************************************************** + std::istream &operator>>(std::istream &is, Version &obj) + { + is >> obj.m_major; + is >> obj.m_minor; + is >> obj.m_revision; + return is; + } + //****************************************************************************** } } diff --git a/smcore/version.h b/smcore/version.h index 16ae231..532e199 100644 --- a/smcore/version.h +++ b/smcore/version.h @@ -22,8 +22,11 @@ #pragma once -#include "smstring.h" #include +#include +#include + +#include "smstring.h" namespace smos { @@ -87,7 +90,27 @@ namespace smos * @param minor Minor version information * @param revision Revision version informationi */ - void SetVersion(const short &major, const short &minor, const short &revision); + void SetVersion(const short major, const short minor, const short revision); + + /** + * @brief Enable writing to stream + * + * @param os Outputstream to write to + * @param obj Version object to write to stream + * + * @return std::ostream& + */ + friend std::ostream &operator<<(std::ostream &os, const Version &obj); + + /** + * @brief Enable reading from stream + * + * @param is Inputstream to read from + * @param obj Version object to read from stream + * + * @return std::istream& + */ + friend std::istream &operator>>(std::istream &is, Version &obj); private: /** From ef82a6c154b2316578337910e20d2669c2112135 Mon Sep 17 00:00:00 2001 From: ThirtySomething Date: Sun, 2 Apr 2023 12:04:04 +0200 Subject: [PATCH 2/2] FIX: Make version numbers more portable. - Minor improvement of factory class --- smcore/factory.cpp | 11 ++++------- smcore/version.cpp | 2 +- smcore/version.h | 9 +++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/smcore/factory.cpp b/smcore/factory.cpp index ef7cd6b..2d4f466 100644 --- a/smcore/factory.cpp +++ b/smcore/factory.cpp @@ -23,6 +23,7 @@ #include "factory.h" #include +#include namespace smos { @@ -31,7 +32,7 @@ namespace smos //****************************************************************************** Options *Factory::getOptions(smos::smcore::SMString optionsfile) { - static std::map programOptions; + static std::unordered_map programOptions; if (programOptions.find(optionsfile) == programOptions.end()) { programOptions.insert(std::make_pair(optionsfile, new Options(optionsfile))); @@ -41,12 +42,8 @@ namespace smos //****************************************************************************** Version *Factory::getVersion(void) { - static Version *smVersion = nullptr; - if (nullptr == smVersion) - { - smVersion = new Version(); - } - return smVersion; + static Version smVersion; + return &smVersion; } //****************************************************************************** } diff --git a/smcore/version.cpp b/smcore/version.cpp index eb3e25b..8cc8957 100644 --- a/smcore/version.cpp +++ b/smcore/version.cpp @@ -82,7 +82,7 @@ namespace smos return result; } //****************************************************************************** - void Version::SetVersion(const short major, const short minor, const short revision) + void Version::SetVersion(const uint16_t major, const uint16_t minor, const uint16_t revision) { this->m_major = major; this->m_minor = minor; diff --git a/smcore/version.h b/smcore/version.h index 532e199..437d206 100644 --- a/smcore/version.h +++ b/smcore/version.h @@ -22,6 +22,7 @@ #pragma once +#include #include #include #include @@ -90,7 +91,7 @@ namespace smos * @param minor Minor version information * @param revision Revision version informationi */ - void SetVersion(const short major, const short minor, const short revision); + void SetVersion(const uint16_t major, const uint16_t minor, const uint16_t revision); /** * @brief Enable writing to stream @@ -116,15 +117,15 @@ namespace smos /** * @brief Major version number */ - short m_major; + uint16_t m_major; /** * @brief Minor version number */ - short m_minor; + uint16_t m_minor; /** * @brief Revision version number */ - short m_revision; + uint16_t m_revision; }; } }