Skip to content

Commit

Permalink
#5927: Introduce auxiliary classes to deal with version-specific sett…
Browse files Browse the repository at this point in the history
…ings files.
  • Loading branch information
codereader committed Mar 31, 2022
1 parent c5deae2 commit 2b7db90
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 0 deletions.
42 changes: 42 additions & 0 deletions libs/settings/MajorMinorVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <string>

namespace settings
{

// Represents an application version tag with Major and Minor numbers
class MajorMinorVersion
{
private:
int _majorVersion;
int _minorVersion;

public:
MajorMinorVersion(const std::string& versionString)
{
// Extract the version from the given string
_majorVersion = 0;
_minorVersion = 0;
}

// Compare this version to the other one, returning true if this is instance is smaller
bool operator<(const MajorMinorVersion& other) const
{
if (_majorVersion < other._majorVersion)
{
return true;
}

// If major version matches, minor version decides
if (_majorVersion == other._majorVersion)
{
return _minorVersion < other._minorVersion;
}

// Major version is larger
return false;
}
};

}
37 changes: 37 additions & 0 deletions libs/settings/SettingsManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <string>
#include "version.h"
#include "imodule.h"

#include "MajorMinorVersion.h"

namespace settings
{

class SettingsManager
{
private:
const IApplicationContext& _context;
MajorMinorVersion _currentVersion;

public:
SettingsManager(const IApplicationContext& context) :
SettingsManager(context, RADIANT_VERSION)
{}

SettingsManager(const SettingsManager& other) = delete;
SettingsManager& operator=(const SettingsManager& other) = delete;

// Construct a settings manager instance with a specific version
// string in the format "Major.Minor.Micro[BuildSuffix]", or "2.14.0pre1".
// Mainly used for unit test purposes, regular code should use the default constructor.
SettingsManager(const IApplicationContext& context, const std::string& currentVersion) :
_context(context),
_currentVersion(currentVersion)
{}

// TODO
};

}
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_executable(drtest
SceneNode.cpp
SelectionAlgorithm.cpp
Selection.cpp
Settings.cpp
TextureManipulation.cpp
TextureTool.cpp
Transformation.cpp
Expand Down
13 changes: 13 additions & 0 deletions test/Settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "gtest/gtest.h"

#include "settings/MajorMinorVersion.h"

namespace test
{

TEST(MajorMinorVersion, ParseFromString)
{
// TODO
}

}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<ClCompile Include="..\..\..\test\SceneNode.cpp" />
<ClCompile Include="..\..\..\test\Selection.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
<ClCompile Include="..\..\..\test\Settings.cpp" />
<ClCompile Include="..\..\..\test\TextureManipulation.cpp" />
<ClCompile Include="..\..\..\test\TextureTool.cpp" />
<ClCompile Include="..\..\..\test\Transformation.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<ClCompile Include="..\..\..\test\ContinuousBuffer.cpp" />
<ClCompile Include="..\..\..\test\Particles.cpp" />
<ClCompile Include="..\..\..\test\GeometryStore.cpp" />
<ClCompile Include="..\..\..\test\Settings.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down
2 changes: 2 additions & 0 deletions tools/msvc/libs.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@
<ClInclude Include="..\..\libs\selection\SelectionVolume.h" />
<ClInclude Include="..\..\libs\selection\SingleItemSelector.h" />
<ClInclude Include="..\..\libs\SequentialTaskQueue.h" />
<ClInclude Include="..\..\libs\settings\MajorMinorVersion.h" />
<ClInclude Include="..\..\libs\settings\SettingsManager.h" />
<ClInclude Include="..\..\libs\shaderlib.h" />
<ClInclude Include="..\..\libs\stream\BinaryToTextInputStream.h" />
<ClInclude Include="..\..\libs\stream\BufferInputStream.h" />
Expand Down
9 changes: 9 additions & 0 deletions tools/msvc/libs.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@
<ClInclude Include="..\..\libs\render\Rectangle.h">
<Filter>render</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\settings\SettingsManager.h">
<Filter>settings</Filter>
</ClInclude>
<ClInclude Include="..\..\libs\settings\MajorMinorVersion.h">
<Filter>settings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="util">
Expand Down Expand Up @@ -427,5 +433,8 @@
<Filter Include="materials">
<UniqueIdentifier>{60865a71-2a02-47bd-b5e2-8e7ec339d27b}</UniqueIdentifier>
</Filter>
<Filter Include="settings">
<UniqueIdentifier>{a23072d3-ab2e-4596-ba32-e785ba12be3a}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

0 comments on commit 2b7db90

Please sign in to comment.