Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
endif()

if(MSVC)
add_compile_options(/W4 /clang:-Wno-character-conversion /clang:-Wno-error=character-conversion)
add_compile_options(/W4)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(/clang:-Wno-character-conversion /clang:-Wno-error=character-conversion)
else()
endif()
else()
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"generator": "Visual Studio 18 2026",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl"
Expand Down
5 changes: 5 additions & 0 deletions Source/CTF/ctf/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include "Algorithm.h"

namespace CTF {
template <typename T>
CTF_CONSTEXPR T Abs(T x) {
return (x < 0) ? -x : x;
}

template <typename T>
CTF_CONSTEXPR T Min(T a, T b) {
return b < a ? b : a;
Expand Down
5 changes: 3 additions & 2 deletions Source/CTF/ctf/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
#define ALGORITHM_H
#pragma once



namespace CTF {

template <typename T>
CTF_API CTF_CONSTEXPR T Abs(T x);

template <typename T>
CTF_API CTF_CONSTEXPR T Max(T a, T b);

Expand Down
2 changes: 1 addition & 1 deletion Source/CTF/ctf/BasicString.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace CTF {
* @brief Just a simple basic string class.
*/
template <typename T>
class BasicString {
class CTF_API BasicString {
public:
/**
* @brief Initializes an empty string.
Expand Down
8 changes: 8 additions & 0 deletions Source/CTF/ctf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ set(SOURCES
"Logging/LogListener.cpp"
"Logging/LogListener.h"

# mathematics
"Math/Logarithms.h"
"Math/Power.h"
"Math/Rounding.h"
"Math/Trigonometry.h"

# string
#"String.inl"
"BasicString.h"
Expand Down Expand Up @@ -107,6 +113,8 @@ set(SOURCES
"PipeStream.h"

# memory management
"LinearArena.cpp"
"LinearArena.h"
"Memory.cpp"
"Memory.h"
"RefCounted.cpp"
Expand Down
30 changes: 15 additions & 15 deletions Source/CTF/ctf/Collections/Hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@

namespace CTF::Collections {

template <typename T> int Hash<T>::operator()(const T &key) const {
const unsigned char *data = reinterpret_cast<const unsigned char *>(&key);
int Hash = 0;
for (int i = 0; i < sizeof(T); ++i)
Hash = Hash * 131 + data[i];
return Hash;
}
template <typename T> int Hash<T>::operator()(const T &key) const {
const unsigned char *data = reinterpret_cast<const unsigned char *>(&key);
int Hash = 0;
for (int i = 0; i < sizeof(T); ++i)
Hash = Hash * 131 + data[i];
return Hash;
}

int Hash<String>::operator()(const String &s) const {
int Hash = 5381;
const char *str = s.CStr();
int len = s.Length();
for (int i = 0; i < len; ++i)
Hash = ((Hash << 5) + Hash) + static_cast<unsigned char>(str[i]);
return Hash;
}
int Hash<String>::operator()(const String &s) const {
int Hash = 5381;
const char *str = s.CStr();
size_t len = s.Length();
for (int i = 0; i < len; ++i)
Hash = ((Hash << 5) + Hash) + static_cast<unsigned char>(str[i]);
return Hash;
}
} // namespace CTF::Collections
2 changes: 1 addition & 1 deletion Source/CTF/ctf/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace CTF {
return *this;
}

if (fscanf(fp_, "%511s", buffer) == 1) {
if (fscanf(fp_, "%511s", buffer, (unsigned)sizeof(buffer)) == 1) {
out = buffer;
state_ = StreamState::Good;
} else {
Expand Down
1 change: 0 additions & 1 deletion Source/CTF/ctf/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define FILESTREAM_H
#pragma once


#include "Stream.h"
#include "stdio.h"
#include <stdexcept>
Expand Down
57 changes: 57 additions & 0 deletions Source/CTF/ctf/LinearArena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Cereon Template Framework, a C++ 23 standard template library.
* Copyright (c) 2026 The Aridity Team, all rights reserved.
*
* This file is part of the Cereon Template Framework project.
*
* Cereon Template Framework is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either
* version 3 of the License, or any later version.
*
* Cereon Template Framework 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cereon Template Framework. If not, see <https://www.gnu.org/licenses/>.
*/

#include "CTF.h"
#include "Memory.h"
#include "LinearArena.h"

namespace CTF
{

LinearArena::LinearArena( size_t size )
{
m_buffer = (char *) Memory::Alloc( size );
m_capacity = size;
m_offset = 0;
}

LinearArena::~LinearArena()
{
Memory::Free( m_buffer );
}

void *LinearArena::Alloc( size_t size )
{
size_t alignedSize = ( size + 7 ) & ~7ULL;

if ( m_offset + alignedSize > m_capacity )
return nullptr;

void *ptr = m_buffer + m_offset;
m_offset += alignedSize;
return ptr;
}

void LinearArena::Reset()
{
m_offset = 0;
}

}
45 changes: 45 additions & 0 deletions Source/CTF/ctf/LinearArena.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Cereon Template Framework, a C++ 23 standard template library.
* Copyright (c) 2026 The Aridity Team, all rights reserved.
*
* This file is part of the Cereon Template Framework project.
*
* Cereon Template Framework is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either
* version 3 of the License, or any later version.
*
* Cereon Template Framework 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cereon Template Framework. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef CTF_LINEARARENA_H
#define CTF_LINEARARENA_H
#pragma once

namespace CTF
{

class CTF_API LinearArena
{
public:
LinearArena( size_t size );
~LinearArena();

void *Alloc( size_t size );
void Reset();

private:
char *m_buffer;
size_t m_capacity;
size_t m_offset;
};

}

#endif // !CTF_LINEARARENA_H
77 changes: 77 additions & 0 deletions Source/CTF/ctf/Math/Logarithms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Cereon Template Framework, a C++ 23 standard template library.
* Copyright (c) 2026 The Aridity Team, all rights reserved.
*
* This file is part of the Cereon Template Framework project.
*
* Cereon Template Framework is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either
* version 3 of the License, or any later version.
*
* Cereon Template Framework 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cereon Template Framework. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef MATH_LOGARITHMS_H
#define MATH_LOGARITHMS_H
#pragma once

#include <concepts>

namespace CTF::Math {
CTF_CONSTEXPR double Log2 = 0.693147180559945309417;

template <std::floating_point T>
CTF_CONSTEXPR T Exp(T x) {
int k = static_cast<int>(x / Log2);
T r = x - k * Log2;

T term = 1;
T sum = 1;

for (int n = 1; n < 30; ++n) {
term *= r / n;
sum += term;
if (std::abs(term) < 1e-15) break;
}

return std::ldexp(sum, k);
}

template <std::floating_point T>
CTF_CONSTEXPR T Log(T x) {
int k;
T m = std::frexp(x, &k); // x = m * 2^k, m in [0.5, 1)

if (m < T(0.70710678118)) { // ~1/sqrt(2)
m *= 2;
k -= 1;
}

T y = (m - 1) / (m + 1);
T y2 = y * y;

T sum = 0;
T term = y;

for (int i = 1; i < 50; i += 2) {
sum += term / i;
term *= y2;
}

return 2 * sum + k * Log2;
}

template <typename T>
CTF_CONSTEXPR T Log(T x, T b) {
return Log(x) / Log(b);
}
}

#endif // !MATH_LOGARITHMS_H
38 changes: 38 additions & 0 deletions Source/CTF/ctf/Math/Power.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Cereon Template Framework, a C++ 23 standard template library.
* Copyright (c) 2026 The Aridity Team, all rights reserved.
*
* This file is part of the Cereon Template Framework project.
*
* Cereon Template Framework is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either
* version 3 of the License, or any later version.
*
* Cereon Template Framework 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Cereon Template Framework. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef MATH_POWER_H
#define MATH_POWER_H
#pragma once

#include <concepts>
#include "Algorithm.h"

namespace CTF::Math {
template <std::floating_point T>
CTF_CONSTEXPR T Pow(T b, T ex) {
T result = 1.0;
T absEx = Abs(ex);
for (int i = 0; i < absEx; i++) result *= b;
return (ex < 0) ? 1.0 / result : result;
}
}

#endif // !MATH_POWER_H
Loading
Loading