Skip to content

Commit 6f41c37

Browse files
committed
merging dev branch into main, GUI project not release-ready just yet
2 parents afad237 + 4f7c885 commit 6f41c37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1883
-510
lines changed

XMapLib.sln

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,74 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31911.196
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32014.148
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMapLib", "XMapLib\XMapLib.vcxproj", "{772A82CF-95EA-45B9-BF7E-28927F887F72}"
77
EndProject
88
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMapLibTest", "XMapLibTest\XMapLibTest.vcxproj", "{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}"
99
EndProject
10+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XMapLibDLL", "XMapLibDLL\XMapLibDLL.vcxproj", "{719FF759-0AEB-4234-BFCF-3D45D8B27661}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XMapLibSharp", "XMapLibSharp\XMapLibSharp.csproj", "{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}"
13+
EndProject
1014
Global
1115
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
1217
Debug|x64 = Debug|x64
1318
Debug|x86 = Debug|x86
19+
Release|Any CPU = Release|Any CPU
1420
Release|x64 = Release|x64
1521
Release|x86 = Release|x86
1622
EndGlobalSection
1723
GlobalSection(ProjectConfigurationPlatforms) = postSolution
24+
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|Any CPU.ActiveCfg = Debug|x64
25+
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|Any CPU.Build.0 = Debug|x64
1826
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|x64.ActiveCfg = Debug|x64
1927
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|x64.Build.0 = Debug|x64
2028
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|x86.ActiveCfg = Debug|Win32
2129
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Debug|x86.Build.0 = Debug|Win32
30+
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|Any CPU.ActiveCfg = Release|x64
31+
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|Any CPU.Build.0 = Release|x64
2232
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|x64.ActiveCfg = Release|x64
2333
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|x64.Build.0 = Release|x64
2434
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|x86.ActiveCfg = Release|Win32
2535
{772A82CF-95EA-45B9-BF7E-28927F887F72}.Release|x86.Build.0 = Release|Win32
36+
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|Any CPU.ActiveCfg = Debug|x64
37+
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|Any CPU.Build.0 = Debug|x64
2638
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|x64.ActiveCfg = Debug|x64
2739
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|x64.Build.0 = Debug|x64
2840
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|x86.ActiveCfg = Debug|Win32
2941
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Debug|x86.Build.0 = Debug|Win32
42+
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|Any CPU.ActiveCfg = Release|x64
43+
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|Any CPU.Build.0 = Release|x64
3044
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|x64.ActiveCfg = Release|x64
3145
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|x64.Build.0 = Release|x64
3246
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|x86.ActiveCfg = Release|Win32
3347
{62F4B852-60D8-455B-AE3A-AC6DF69ED03F}.Release|x86.Build.0 = Release|Win32
48+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|Any CPU.ActiveCfg = Debug|x64
49+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|Any CPU.Build.0 = Debug|x64
50+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|x64.ActiveCfg = Debug|x64
51+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|x64.Build.0 = Debug|x64
52+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|x86.ActiveCfg = Debug|Win32
53+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Debug|x86.Build.0 = Debug|Win32
54+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|Any CPU.ActiveCfg = Release|x64
55+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|Any CPU.Build.0 = Release|x64
56+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|x64.ActiveCfg = Release|x64
57+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|x64.Build.0 = Release|x64
58+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|x86.ActiveCfg = Release|Win32
59+
{719FF759-0AEB-4234-BFCF-3D45D8B27661}.Release|x86.Build.0 = Release|Win32
60+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|x64.ActiveCfg = Debug|Any CPU
63+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|x64.Build.0 = Debug|Any CPU
64+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|x86.ActiveCfg = Debug|Any CPU
65+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Debug|x86.Build.0 = Debug|Any CPU
66+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
67+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|Any CPU.Build.0 = Release|Any CPU
68+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|x64.ActiveCfg = Release|Any CPU
69+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|x64.Build.0 = Release|Any CPU
70+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|x86.ActiveCfg = Release|Any CPU
71+
{A42592DA-0FEC-4F35-98A6-4E13CAEAC0D0}.Release|x86.Build.0 = Release|Any CPU
3472
EndGlobalSection
3573
GlobalSection(SolutionProperties) = preSolution
3674
HideSolutionNode = FALSE

XMapLib/Arithmetic.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
#include <cmath>
33
namespace sds::Utilities
44
{
5-
constexpr double ToDub(const auto something)
5+
template<class T>
6+
concept is_number_v = std::is_integral_v<T> || std::is_floating_point_v<T>;
7+
constexpr double ToDub(const is_number_v auto something) noexcept
68
{
79
return static_cast<double>(something);
810
}
9-
constexpr float ToFloat(const auto something)
11+
constexpr float ToFloat(const is_number_v auto something) noexcept
1012
{
1113
return static_cast<float>(something);
1214
}
13-
constexpr int ToInt(const auto something)
15+
constexpr int ToInt(const is_number_v auto something) noexcept
1416
{
1517
return static_cast<int>(something);
1618
}
17-
constexpr bool IsNormalF(const auto val)
19+
constexpr bool IsNormalF(const is_number_v auto val) noexcept
1820
{
1921
return std::isnormal(static_cast<float>(val));
20-
};
22+
}
2123
}

XMapLib/CPPLambdaBase.h

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#pragma once
2+
#include <thread>
3+
#include <mutex>
4+
#include <functional>
5+
6+
namespace sds
7+
{
8+
/// <summary>
9+
/// Convenience class, contains using typedefs for first two args of the
10+
/// user-supplied lambda function.
11+
/// </summary>
12+
struct LambdaArgs
13+
{
14+
using LambdaArg1 = std::atomic<bool>;
15+
using LambdaArg2 = std::mutex;
16+
};
17+
/// <summary>
18+
/// Lambda function runner base, has start() stop() isrunning() member functions.
19+
/// Runs a lambda on it's own thread.
20+
/// Template type "InternalData" must be default constructable!
21+
/// Instantiation requires a lambda of a certain form: function{void(atomic{bool}&, mutex&, InternalData&)}
22+
/// </summary>
23+
template <class InternalData>
24+
class CPPLambdaBase
25+
{
26+
public:
27+
using LambdaType = std::function<void(std::atomic<bool>&, std::mutex&, InternalData&)>;
28+
using ScopedLockType = std::lock_guard<std::mutex>;
29+
30+
CPPLambdaBase(LambdaType lambdaToRun) : m_lambda(std::move(lambdaToRun)) { }
31+
CPPLambdaBase(const CPPLambdaBase& other) = delete;
32+
CPPLambdaBase(CPPLambdaBase&& other) = delete;
33+
CPPLambdaBase& operator=(const CPPLambdaBase& other) = delete;
34+
CPPLambdaBase& operator=(CPPLambdaBase&& other) = delete;
35+
~CPPLambdaBase()
36+
{
37+
StopThread();
38+
}
39+
protected:
40+
LambdaType m_lambda;
41+
InternalData m_local_state{}; // default constructed type InternalData
42+
std::atomic<bool> m_is_stop_requested = false;
43+
std::unique_ptr<std::thread> m_local_thread;
44+
std::mutex m_state_mutex;
45+
public:
46+
/// <summary>
47+
/// Starts running a new thread for the lambda.
48+
/// </summary>
49+
/// <returns>true on success, false on failure.</returns>
50+
bool StartThread() noexcept
51+
{
52+
if (m_local_thread != nullptr)
53+
{
54+
return false;
55+
}
56+
m_is_stop_requested = false;
57+
m_local_thread = std::make_unique<std::thread>(m_lambda, std::ref(m_is_stop_requested), std::ref(m_state_mutex), std::ref(m_local_state));
58+
return m_local_thread->joinable();
59+
}
60+
bool IsRunning() const noexcept
61+
{
62+
if (m_local_thread != nullptr)
63+
{
64+
return m_local_thread->joinable();
65+
}
66+
return false;
67+
}
68+
/// <summary>
69+
/// Non-blocking way to stop a running thread.
70+
/// </summary>
71+
void RequestStop() noexcept
72+
{
73+
if (this->m_local_thread != nullptr)
74+
{
75+
this->m_is_stop_requested = true;
76+
}
77+
}
78+
/// <summary>
79+
/// Blocking way to stop a running thread, joins to current thread and waits.
80+
/// </summary>
81+
void StopThread() noexcept
82+
{
83+
//Get this setting out of the way.
84+
this->m_is_stop_requested = true;
85+
//If there is a thread obj..
86+
if (this->m_local_thread != nullptr)
87+
{
88+
if (this->m_local_thread->joinable())
89+
{
90+
//join to wait for thread to stop, then reset to a nullptr.
91+
this->m_local_thread->join();
92+
this->m_local_thread.reset();
93+
}
94+
else
95+
{
96+
//if it is not joinable, set to nullptr
97+
this->m_local_thread.reset();
98+
}
99+
}
100+
}
101+
};
102+
}

XMapLib/CPPLambdaRunner.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
#include "CPPLambdaBase.h"
3+
namespace sds
4+
{
5+
/// <summary>
6+
/// class for modifying data concurrently
7+
/// Instantiate with the type you would like to have mutex protected access to
8+
/// within a lambda on it's own thread.
9+
/// Template type "InternalData" must be default constructable!
10+
/// Instantiation requires a lambda of a certain form: function{void(atomic{bool}&, mutex&, InternalData&)}
11+
/// </summary>
12+
template <class InternalData>
13+
class CPPLambdaRunner : public CPPLambdaBase<InternalData>
14+
{
15+
public:
16+
using LambdaType = typename CPPLambdaBase<InternalData>::LambdaType;
17+
using ScopedLockType = typename CPPLambdaBase<InternalData>::ScopedLockType;
18+
19+
CPPLambdaRunner(LambdaType lambdaToRun) : CPPLambdaBase<InternalData>((lambdaToRun)) { }
20+
/// <summary>
21+
/// Utility function to update the InternalData with mutex locking thread safety.
22+
/// </summary>
23+
/// <param name="state">InternalData obj to be copied to the internal one.</param>
24+
void UpdateState(const InternalData& state)
25+
{
26+
ScopedLockType tempLock(this->m_state_mutex);
27+
this->m_local_state = state;
28+
}
29+
/// <summary>
30+
/// Returns a copy of the internal InternalData obj with mutex locking thread safety.
31+
/// </summary>
32+
InternalData GetCurrentState()
33+
{
34+
ScopedLockType tempLock(this->m_state_mutex);
35+
return this->m_local_state;
36+
}
37+
};
38+
}

XMapLib/CPPLambdaVectorRunner.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
#include "CPPLambdaRunner.h"
3+
4+
namespace sds
5+
{
6+
/// <summary>
7+
/// class for modifying data concurrently
8+
/// Instantiate with the type you would like to have mutex protected access to
9+
/// within a lambda on it's own thread.
10+
/// Template type "InternalData" must be default constructable!
11+
/// Instantiation requires a lambda of a certain form: function{void(atomic{bool}&, mutex&, InternalData&)}
12+
/// </summary>
13+
template <class InternalData>
14+
class CPPLambdaVectorRunner : public CPPLambdaBase<InternalData>
15+
{
16+
public:
17+
using LambdaType = typename CPPLambdaBase<InternalData>::LambdaType;
18+
using ScopedLockType = typename CPPLambdaBase<InternalData>::ScopedLockType;
19+
20+
CPPLambdaVectorRunner(LambdaType lambdaToRun) : CPPLambdaBase<InternalData>((lambdaToRun)) { }
21+
void AddState(const InternalData& state)
22+
{
23+
ScopedLockType tempLock(this->m_state_mutex);
24+
this->m_local_state.push_back(state);
25+
}
26+
auto GetAndClearCurrentStates()
27+
{
28+
ScopedLockType tempLock(this->m_state_mutex);
29+
auto temp = this->m_local_state;
30+
this->m_local_state.clear();
31+
return temp;
32+
}
33+
};
34+
}

0 commit comments

Comments
 (0)