Skip to content

Cleanups #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ SET ( cppcore_src
SET ( cppcore_common_src
include/cppcore/Common/Hash.h
include/cppcore/Common/TStringBase.h
include/cppcore/Common/TSharedPtr.h
include/cppcore/Common/Variant.h
include/cppcore/Common/TBitField.h
include/cppcore/Common/TOptional.h
Expand Down Expand Up @@ -136,7 +135,6 @@ IF( CPPCORE_BUILD_UNITTESTS )
test/common/VariantTest.cpp
test/common/TBitFieldTest.cpp
test/common/TOptionalTest.cpp
test/common/TSharedPtrTest.cpp
)

SET( cppcore_container_test_src
Expand Down
30 changes: 21 additions & 9 deletions code/Random/RandomGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2014-2024 Kim Kulling
Copyright (c) 2014-2025 Kim Kulling

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand All @@ -28,21 +28,29 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace cppcore {

static const unsigned int N = 624;
static const unsigned int M = 397;
static constexpr unsigned int N = 624;
static constexpr unsigned int M = 397;

static void mersenne_twister_vector_init( unsigned int *seedPoints, size_t len ) {
assert( nullptr != seedPoints );
static bool mersenne_twister_vector_init( unsigned int *seedPoints, size_t len ) {
if (seedPoints == nullptr) {
return false;
}

const unsigned int mult = 1812433253ul;
unsigned int seed = 5489ul;
for (size_t i = 0; i < len; ++i) {
seedPoints[ i ] = seed;
seed = mult * (seed ^ (seed >> 30)) + (static_cast<unsigned int>(i) + 1);
}

return true;
}

static void mersenne_twister_vector_update(unsigned int* const p) {
static bool mersenne_twister_vector_update(unsigned int* const p) {
if (p == nullptr) {
return false;
}

static const unsigned int A[ 2 ] = { 0, 0x9908B0DF };
unsigned int i=0;
for (; i < N - M; i++) {
Expand All @@ -52,6 +60,8 @@ static void mersenne_twister_vector_update(unsigned int* const p) {
p[i] = p[i + (M - N)] ^ (((p[i] & 0x80000000) | (p[i + 1] & 0x7FFFFFFF)) >> 1) ^ A[p[i + 1] & 1];
}
p[N - 1] = p[M - 1] ^ (((p[N - 1] & 0x80000000) | (p[0] & 0x7FFFFFFF)) >> 1) ^ A[p[0] & 1];

return true;
}

unsigned int mersenne_twister() {
Expand All @@ -60,13 +70,15 @@ unsigned int mersenne_twister() {
// readout index
static int idx = N + 1;

bool ok = true;
if (static_cast<unsigned int>(idx) >= N) {
if (static_cast<unsigned int>(idx) > N) {
mersenne_twister_vector_init(vector, N);
ok |= mersenne_twister_vector_init(vector, N);
}
mersenne_twister_vector_update(vector);
ok |= mersenne_twister_vector_update(vector);
idx = 0;
}
assert(ok);
unsigned int e = vector[ idx++ ];

// Tempering
Expand All @@ -80,7 +92,7 @@ unsigned int mersenne_twister() {

RandomGenerator::RandomGenerator( GeneratorType type ) noexcept :
m_type( type ) {
::srand( static_cast<unsigned int>(time(nullptr)));
::srand(static_cast<unsigned int>(time(nullptr)));
}

int RandomGenerator::get( int lower, int upper ) {
Expand Down
2 changes: 1 addition & 1 deletion include/cppcore/Common/Hash.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2014-2024 Kim Kulling
Copyright (c) 2014-2025 Kim Kulling

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
163 changes: 0 additions & 163 deletions include/cppcore/Common/TSharedPtr.h

This file was deleted.

8 changes: 4 additions & 4 deletions include/cppcore/IO/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#pragma once

#ifdef WIN32
#include <Windows.h>
#ifdef _WIN32
# include <Windows.h>
#else
#include <sys/statvfs.h>
# include <sys/statvfs.h>
#endif

namespace cppcore {
Expand Down Expand Up @@ -75,7 +75,7 @@ inline void FileSystem::refresh() {
if (m_drive == nullptr) {
return;
}
#ifdef WIN32
#ifdef _WIN32
PULARGE_INTEGER freeByteAvailable = 0, totalNumberOfBytes = 0, totalNumberOfFreeBytes = 0;
BOOL result = ::GetDiskFreeSpaceEx(m_drive, freeByteAvailable, totalNumberOfBytes, totalNumberOfFreeBytes);
if (TRUE == result) {
Expand Down
61 changes: 0 additions & 61 deletions test/common/TSharedPtrTest.cpp

This file was deleted.