Skip to content

Commit

Permalink
clang-format all files
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Dec 14, 2024
1 parent 10d96af commit c84b89b
Show file tree
Hide file tree
Showing 312 changed files with 9,879 additions and 10,481 deletions.
26 changes: 14 additions & 12 deletions base/24bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ namespace base {

#ifdef LAF_LITTLE_ENDIAN

template<typename PTR, typename VALUE>
inline void write24bits(PTR* ptr, VALUE value) {
((uint8_t*)ptr)[0] = value;
((uint8_t*)ptr)[1] = value >> 8;
((uint8_t*)ptr)[2] = value >> 16;
}
template<typename PTR, typename VALUE>
inline void write24bits(PTR* ptr, VALUE value)
{
((uint8_t*)ptr)[0] = value;
((uint8_t*)ptr)[1] = value >> 8;
((uint8_t*)ptr)[2] = value >> 16;
}

#elif defined(LAF_BIG_ENDIAN)

template<typename PTR, typename VALUE>
inline void write24bits(PTR* ptr, VALUE value) {
((uint8_t*)ptr)[0] = value >> 16;
((uint8_t*)ptr)[1] = value >> 8;
((uint8_t*)ptr)[2] = value;
}
template<typename PTR, typename VALUE>
inline void write24bits(PTR* ptr, VALUE value)
{
((uint8_t*)ptr)[0] = value >> 16;
((uint8_t*)ptr)[1] = value >> 8;
((uint8_t*)ptr)[2] = value;
}

#endif

Expand Down
18 changes: 8 additions & 10 deletions base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,21 @@

#undef ABS
#undef SGN
#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
#define SGN(x) (((x) >= 0) ? 1 : -1)


#define ABS(x) (((x) >= 0) ? (x) : (-(x)))
#define SGN(x) (((x) >= 0) ? 1 : -1)

//////////////////////////////////////////////////////////////////////
// Overloaded new/delete operators to detect memory-leaks

#if defined __cplusplus && defined LAF_MEMLEAK

#include <new>
#include <new>

#ifdef _NOEXCEPT
#define LAF_NOEXCEPT _NOEXCEPT
#else
#define LAF_NOEXCEPT
#endif
#ifdef _NOEXCEPT
#define LAF_NOEXCEPT _NOEXCEPT
#else
#define LAF_NOEXCEPT
#endif

void* operator new(std::size_t size);
void* operator new[](std::size_t size);
Expand Down
23 changes: 10 additions & 13 deletions base/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif

#include "base/base64.h"
Expand Down Expand Up @@ -56,15 +56,15 @@ static inline int base64Inv(int asciiChar)

void encode_base64(const char* input, size_t n, std::string& output)
{
const size_t size = 4*int(std::ceil(n/3.0)); // Estimate encoded string size
const size_t size = 4 * int(std::ceil(n / 3.0)); // Estimate encoded string size
output.resize(size);

auto outIt = output.begin();
auto outEnd = output.end();
uint8_t next = 0;
size_t i = 0;
size_t j = 0;
for (; i<n; ++i, ++input) {
for (; i < n; ++i, ++input) {
auto inputValue = *input;
switch (j) {
case 0:
Expand Down Expand Up @@ -95,39 +95,36 @@ void encode_base64(const char* input, size_t n, std::string& output)
*outIt = base64Char(next);
++outIt;
}
for (; outIt!=outEnd; ++outIt)
*outIt = '='; // Padding
for (; outIt != outEnd; ++outIt)
*outIt = '='; // Padding
}
}

void decode_base64(const char* input, size_t n, buffer& output)
{
size_t size = 3*int(std::ceil(n/4.0)); // Estimate decoded buffer size
size_t size = 3 * int(std::ceil(n / 4.0)); // Estimate decoded buffer size
output.resize(size);

auto outIt = output.begin();
size_t i = 0;
for (; i+3<n; i+=4, input+=4) {
*outIt = (((base64Inv(input[0]) ) << 2) |
((base64Inv(input[1]) & 0b110000) >> 4));
for (; i + 3 < n; i += 4, input += 4) {
*outIt = (((base64Inv(input[0])) << 2) | ((base64Inv(input[1]) & 0b110000) >> 4));
++outIt;

if (input[2] == '=') {
size -= 2;
break;
}

*outIt = (((base64Inv(input[1]) & 0b001111) << 4) |
((base64Inv(input[2]) & 0b111100) >> 2));
*outIt = (((base64Inv(input[1]) & 0b001111) << 4) | ((base64Inv(input[2]) & 0b111100) >> 2));
++outIt;

if (input[3] == '=') {
--size;
break;
}

*outIt = (((base64Inv(input[2]) & 0b000011) << 6) |
((base64Inv(input[3]) )));
*outIt = (((base64Inv(input[2]) & 0b000011) << 6) | ((base64Inv(input[3]))));
++outIt;
}

Expand Down
21 changes: 14 additions & 7 deletions base/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,53 @@ namespace base {
void encode_base64(const char* input, size_t n, std::string& output);
void decode_base64(const char* input, size_t n, buffer& output);

inline void encode_base64(const buffer& input, std::string& output) {
inline void encode_base64(const buffer& input, std::string& output)
{
if (!input.empty())
encode_base64((const char*)&input[0], input.size(), output);
}

inline std::string encode_base64(const buffer& input) {
inline std::string encode_base64(const buffer& input)
{
std::string output;
if (!input.empty())
encode_base64((const char*)&input[0], input.size(), output);
return output;
}

inline std::string encode_base64(const std::string& input) {
inline std::string encode_base64(const std::string& input)
{
std::string output;
if (!input.empty())
encode_base64((const char*)input.c_str(), input.size(), output);
return output;
}

inline void decode_base64(const std::string& input, buffer& output) {
inline void decode_base64(const std::string& input, buffer& output)
{
if (!input.empty())
decode_base64(input.c_str(), input.size(), output);
}

inline buffer decode_base64(const std::string& input) {
inline buffer decode_base64(const std::string& input)
{
buffer output;
if (!input.empty())
decode_base64(input.c_str(), input.size(), output);
return output;
}

inline std::string decode_base64s(const std::string& input) {
inline std::string decode_base64s(const std::string& input)
{
if (input.empty())
return std::string();
buffer tmp;
decode_base64(input.c_str(), input.size(), tmp);
return std::string((const char*)&tmp[0], tmp.size());
}

inline buffer decode_base64(const buffer& input) {
inline buffer decode_base64(const buffer& input)
{
buffer output;
if (!input.empty())
decode_base64((const char*)&input[0], input.size(), output);
Expand Down
12 changes: 6 additions & 6 deletions base/base64_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace base;
TEST(Base64, Encode)
{
EXPECT_EQ("", encode_base64(buffer()));
EXPECT_EQ("Cg==", encode_base64(buffer{'\n'}));
EXPECT_EQ("YQ==", encode_base64(buffer{'a'}));
EXPECT_EQ("YWJjZGU=", encode_base64(buffer{'a', 'b', 'c', 'd', 'e'}));
EXPECT_EQ("Cg==", encode_base64(buffer{ '\n' }));
EXPECT_EQ("YQ==", encode_base64(buffer{ 'a' }));
EXPECT_EQ("YWJjZGU=", encode_base64(buffer{ 'a', 'b', 'c', 'd', 'e' }));
EXPECT_EQ("YWJjZGU=", encode_base64("abcde"));
EXPECT_EQ("YWJj", encode_base64("abc"));
EXPECT_EQ("5pel5pys6Kqe", encode_base64("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E")); // "日本語"
Expand All @@ -26,9 +26,9 @@ TEST(Base64, Encode)
TEST(Base64, Decode)
{
EXPECT_EQ(buffer(), decode_base64(""));
EXPECT_EQ(buffer{'\n'}, decode_base64("Cg=="));
EXPECT_EQ(buffer{'a'}, decode_base64("YQ=="));
EXPECT_EQ(buffer({'a', 'b', 'c', 'd', 'e'}), decode_base64("YWJjZGU="));
EXPECT_EQ(buffer{ '\n' }, decode_base64("Cg=="));
EXPECT_EQ(buffer{ 'a' }, decode_base64("YQ=="));
EXPECT_EQ(buffer({ 'a', 'b', 'c', 'd', 'e' }), decode_base64("YWJjZGU="));
EXPECT_EQ("abcde", decode_base64s("YWJjZGU="));
EXPECT_EQ("abc", decode_base64s("YWJj"));
EXPECT_EQ("\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E", decode_base64s("5pel5pys6Kqe")); // "日本語"
Expand Down
24 changes: 7 additions & 17 deletions base/cfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#include "config.h"
#endif

#include <cstdio>
Expand Down Expand Up @@ -84,14 +84,9 @@ long long fgetq(FILE* file)
return EOF;

// Little endian.
return (((long long)b8 << 56) |
((long long)b7 << 48) |
((long long)b6 << 40) |
((long long)b5 << 32) |
((long long)b4 << 24) |
((long long)b3 << 16) |
((long long)b2 << 8) |
(long long)b1);
return (((long long)b8 << 56) | ((long long)b7 << 48) | ((long long)b6 << 40) |
((long long)b5 << 32) | ((long long)b4 << 24) | ((long long)b3 << 16) |
((long long)b2 << 8) | (long long)b1);
}

// Reads a 32-bit single-precision floating point number using
Expand Down Expand Up @@ -148,14 +143,9 @@ double fgetd(FILE* file)
return EOF;

// Little endian.
long long v = (((long long)b8 << 56) |
((long long)b7 << 48) |
((long long)b6 << 40) |
((long long)b5 << 32) |
((long long)b4 << 24) |
((long long)b3 << 16) |
((long long)b2 << 8) |
(long long)b1);
long long v = (((long long)b8 << 56) | ((long long)b7 << 48) | ((long long)b6 << 40) |
((long long)b5 << 32) | ((long long)b4 << 24) | ((long long)b3 << 16) |
((long long)b2 << 8) | (long long)b1);
return *reinterpret_cast<double*>(&v);
}

Expand Down
20 changes: 10 additions & 10 deletions base/cfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

namespace base {

int fgetw(FILE* file);
long fgetl(FILE* file);
long long fgetq(FILE* file);
float fgetf(FILE* file);
double fgetd(FILE* file);
int fputw(int w, FILE* file);
int fputl(long l, FILE* file);
int fputq(long long l, FILE* file);
int fputf(float l, FILE* file);
int fputd(double l, FILE* file);
int fgetw(FILE* file);
long fgetl(FILE* file);
long long fgetq(FILE* file);
float fgetf(FILE* file);
double fgetd(FILE* file);
int fputw(int w, FILE* file);
int fputl(long l, FILE* file);
int fputq(long long l, FILE* file);
int fputf(float l, FILE* file);
int fputd(double l, FILE* file);

} // namespace base

Expand Down
78 changes: 41 additions & 37 deletions base/chrono.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
// LAF Base Library
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "base/chrono.h"

#if LAF_WINDOWS
#include "base/chrono_win32.h"
#else
#include "base/chrono_unix.h"
#endif

namespace base {

Chrono::Chrono() : m_impl(new ChronoImpl) {
}

Chrono::~Chrono() {
delete m_impl;
}

void Chrono::reset() {
m_impl->reset();
}

double Chrono::elapsed() const {
return m_impl->elapsed();
}

} // namespace base
// LAF Base Library
// Copyright (c) 2021 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "base/chrono.h"

#if LAF_WINDOWS
#include "base/chrono_win32.h"
#else
#include "base/chrono_unix.h"
#endif

namespace base {

Chrono::Chrono() : m_impl(new ChronoImpl)
{
}

Chrono::~Chrono()
{
delete m_impl;
}

void Chrono::reset()
{
m_impl->reset();
}

double Chrono::elapsed() const
{
return m_impl->elapsed();
}

} // namespace base
Loading

0 comments on commit c84b89b

Please sign in to comment.