Skip to content
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

Formatting/additions/etc #31

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ IndentWidth: 2
BasedOnStyle: 'google'
ColumnLimit: 100
SortIncludes: false
UseTab: Never
DerivePointerAlignment: false
PointerAlignment: Left
6 changes: 3 additions & 3 deletions .github/workflows/build_nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:

- name: "Build/Test" # contains slash so use quotes otherwise UB
run: |
wget https://github.com/mkn/mkn/releases/download/latest/mkn_nix
chmod +x mkn_nix
KLOG=3 ./mkn_nix clean build run -dtOp test -a "-std=c++17 -fPIC"
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_nix
chmod +x mkn
KLOG=3 ./mkn clean build run -dtOp test -a "-std=c++17 -fPIC"
6 changes: 3 additions & 3 deletions .github/workflows/build_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:

- name: "Build/Test" # contains slash so use quotes otherwise UB
run: |
wget https://github.com/mkn/mkn/releases/download/latest/mkn_osx
chmod +x mkn_osx
KLOG=3 ./mkn_osx clean build run -dtOp test -a "-std=c++17 -fPIC"
curl -Lo mkn https://github.com/mkn/mkn/releases/download/latest/mkn_osx
chmod +x mkn
KLOG=3 ./mkn clean build run -dtOp test -a "-std=c++17 -fPIC"
17 changes: 17 additions & 0 deletions .sublime-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"folders":
[
{
"path": "."
}
],
"settings":
{
"ClangFormat":
{
"binary": "clang-format",
"format_on_save": true,
"style": "file"
},
}
}
3 changes: 3 additions & 0 deletions .sublime-project.sublime-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"project": ".sublime-project"
}
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

19 changes: 0 additions & 19 deletions appveyor.yml

This file was deleted.

45 changes: 15 additions & 30 deletions inc/mkn/kul/all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <numeric>
#include <algorithm>

#include "mkn/kul/span.hpp"

namespace mkn {
namespace kul {

#define PRINT_LINE() std::cout << __LINE__ << std::endl

namespace func {
template <typename...>
using check = void;
}

template <typename T, typename data_fn = void, typename size_fn = void>
struct is_span_like : std::false_type {};

template <typename T>
struct is_span_like<T, func::check<decltype(std::declval<T>().data())>,
func::check<decltype(std::declval<T>().size())>> : std::true_type {};

template <typename T>
auto constexpr is_span_like_v = is_span_like<T>::value;

template <typename Container, typename Function>
void for_each(Container& container, Function && function) {
void for_each(Container& container, Function&& function) {
std::for_each(std::begin(container), std::end(container), function);
}
Comment on lines 44 to 47
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's less complicated as it has fewer parameters, and avoids needing to use begin/end, which is the point

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilipDeegan, thank you for your explanation. I understand your point about reducing complexity and the need to explicitly call std::begin and std::end. This indeed makes the code cleaner and easier to read. I appreciate your approach to improving code readability and simplicity.

Comment on lines 44 to 47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for_each function is a simple wrapper around std::for_each. This might be unnecessary as it doesn't add any new functionality or abstraction. Consider using std::for_each directly unless there's a specific reason for this wrapper.


template <typename Container, typename Function>
bool any_of(Container const& container, Function && function) {
bool any_of(Container const& container, Function&& function) {
return std::any_of(std::begin(container), std::end(container), function);
}
template <typename Container, typename Function>
bool any_of(Container && container, Function && function) {
bool any_of(Container&& container, Function&& function) {
return std::any_of(std::begin(container), std::end(container), function);
}
Comment on lines 49 to 56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The any_of function is overloaded for both lvalue and rvalue references. However, the rvalue reference version doesn't take advantage of move semantics and simply calls the lvalue reference version. This could lead to unnecessary copies. Consider modifying the rvalue reference version to use std::move.

Comment on lines +54 to 56
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The any_of function for rvalue references is recursive and will cause a stack overflow. It should call std::any_of instead of itself.

- return any_of(std::begin(container), std::end(container), function);
+ return std::any_of(std::begin(container), std::end(container), function);


template <typename Container, typename Function>
bool all_of(Container const& container, Function && function) {
bool all_of(Container const& container, Function&& function) {
return std::all_of(std::begin(container), std::end(container), function);
}
template <typename Container, typename Function>
bool all_of(Container && container, Function && function) {
bool all_of(Container&& container, Function&& function) {
return all_of(container, function);
}
Comment on lines +59 to 65
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the any_of function, the all_of function is overloaded for both lvalue and rvalue references. The rvalue reference version doesn't take advantage of move semantics and simply calls the lvalue reference version. This could lead to unnecessary copies. Consider modifying the rvalue reference version to use std::move.

Comment on lines +63 to 65
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The all_of function for rvalue references is recursive and will cause a stack overflow. It should call std::all_of instead of itself.

- return all_of(container, function);
+ return std::all_of(std::begin(container), std::end(container), function);


Expand All @@ -90,7 +75,7 @@ bool compare_to(T const& t, OP const& op, Args const&... args) {
return ((op(args, t)) && ...);
}
template <typename T, typename OP, typename... Args>
bool compare_to(T && t, OP && op, Args &&... args) {
bool compare_to(T&& t, OP&& op, Args&&... args) {
return compare_to(t, op, args...);
}
Comment on lines +78 to 80
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compare_to function for rvalue references is recursive and will cause a stack overflow. It should call the compare_to function that takes lvalue references instead.

- return compare_to(t, op, args...);
+ return compare_to(static_cast<T const&>(t), op, args...);


Expand All @@ -100,7 +85,7 @@ bool compare_to(T const& t, OP const& op, std::tuple<TupleElements...> const& tu
return std::apply([&](auto const&... args) { return compare_to(t, op, args...); }, tuple);
}
template <typename T, typename OP, typename... TupleElements>
bool compare_to(T && t, OP && op, std::tuple<TupleElements...> && tuple) {
bool compare_to(T&& t, OP&& op, std::tuple<TupleElements...>&& tuple) {
return compare_to(t, op, tuple);
}
Comment on lines +88 to 90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compare_to function for rvalue references is recursive and will cause a stack overflow. It should call the compare_to function that takes lvalue references instead.

- return compare_to(t, op, tuple);
+ return compare_to(static_cast<T const&>(t), op, tuple);


Expand All @@ -114,7 +99,7 @@ class All {
return are(t, std::equal_to<T>{});
}
template <typename T>
bool operator==(T && t) {
bool operator==(T&& t) {
return are(t, std::equal_to<T>{});
}

Expand All @@ -123,7 +108,7 @@ class All {
return are(t, std::not_equal_to<T>{});
}
template <typename T>
bool operator!=(T && t) {
bool operator!=(T&& t) {
return are(t, std::not_equal_to<T>{});
}

Expand All @@ -132,7 +117,7 @@ class All {
return are(t, std::greater<T>{});
}
template <typename T>
bool operator>(T && t) {
bool operator>(T&& t) {
return are(t, std::greater<T>{});
}

Expand All @@ -141,7 +126,7 @@ class All {
return are(t, std::less<T>{});
}
template <typename T>
bool operator<(T && t) {
bool operator<(T&& t) {
return are(t, std::less<T>{});
}

Expand All @@ -150,7 +135,7 @@ class All {
return are(t, std::greater_equal<T>{});
}
template <typename T>
bool operator>=(T && t) {
bool operator>=(T&& t) {
return are(t, std::greater_equal<T>{});
}

Expand All @@ -159,7 +144,7 @@ class All {
return are(t, std::less_equal<T>{});
}
template <typename T>
bool operator<=(T && t) {
bool operator<=(T&& t) {
return are(t, std::less_equal<T>{});
}
Comment on lines 144 to 149
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operator overloads for ==, !=, >, <, >=, and <= are duplicated for lvalue and rvalue references. However, the rvalue reference versions don't take advantage of move semantics and simply call the lvalue reference versions. This could lead to unnecessary copies. Consider modifying the rvalue reference versions to use std::move.

Comment on lines +147 to 149
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison operators (==, !=, >, <, >=, <=) for rvalue references are recursive and will cause a stack overflow. They should call the corresponding operators that take lvalue references instead.

- return are(t, std::equal_to<T>{});
+ return are(static_cast<T const&>(t), std::equal_to<T>{});

Repeat this change for all the comparison operators.


Expand Down
8 changes: 3 additions & 5 deletions inc/mkn/kul/alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace mkn::kul {
template <typename T, std::int32_t alignment = 32>
class AlignedAllocator {
using This = AlignedAllocator<T, alignment>;

public:
using pointer = T*;
using reference = T&;
Expand Down Expand Up @@ -71,13 +72,10 @@ class AlignedAllocator {
deallocate(p);
}


bool operator!=(This const& that) const {
return !(*this == that);
}
bool operator!=(This const& that) const { return !(*this == that); }

bool operator==(This const& /*that*/) const {
return true; // stateless
return true; // stateless
}
};

Expand Down
39 changes: 22 additions & 17 deletions inc/mkn/kul/asio/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace log {

class Exception : public mkn::kul::Exception {
public:
Exception(char const *f, uint16_t const &l, std::string const &s) : mkn::kul::Exception(f, l, s) {}
Exception(char const* f, uint16_t const& l, std::string const& s)
: mkn::kul::Exception(f, l, s) {}
};
} // namespace log

Expand All @@ -51,20 +52,20 @@ class Logger : public mkn::kul::Logger {

private:
mkn::kul::ChroncurrentThreadPool<> ctp;
std::function<void(std::string const &)> defE, defO;
std::function<void(std::string const&)> defE, defO;

public:
Logger()
: ctp(1, 1),
defE([&](std::string const &s) { mkn::kul::Logger::err(s); }),
defO([&](std::string const &s) { mkn::kul::Logger::out(s); }) {}
void err(std::string const &s) override {
defE([&](std::string const& s) { mkn::kul::Logger::err(s); }),
defO([&](std::string const& s) { mkn::kul::Logger::out(s); }) {}
void err(std::string const& s) override {
if (e)
ctp.async(std::bind(e, s));
else
ctp.async(std::bind(defE, s));
}
void out(std::string const &s) override {
void out(std::string const& s) override {
if (o)
ctp.async(std::bind(o, s));
else
Expand All @@ -77,7 +78,7 @@ class LogMan : public mkn::kul::ALogMan {
LogMan() : ALogMan(new mkn::kul::asio::Logger()) {}

public:
static LogMan &INSTANCE() {
static LogMan& INSTANCE() {
static LogMan instance;
return instance;
};
Expand All @@ -86,40 +87,44 @@ class LogMan : public mkn::kul::ALogMan {
class Message {
protected:
std::stringstream ss;
const mkn::kul::log::mode &m;
const mkn::kul::log::mode& m;

Message(const mkn::kul::log::mode &_m) : m(_m) {}
Message(const mkn::kul::log::mode& _m) : m(_m) {}

public:
template <class T>
Message &operator<<(const T &s) {
Message& operator<<(const T& s) {
ss << s;
return *this;
}
};
class LogMessage : public Message {
public:
~LogMessage() { LogMan::INSTANCE().log(f, fn, l, m, ss.str()); }
LogMessage(char const *_f, char const *_fn, uint16_t const &_l, const mkn::kul::log::mode &_m)
LogMessage(char const* _f, char const* _fn, uint16_t const& _l, const mkn::kul::log::mode& _m)
: Message(_m), f(_f), fn(_fn), l(_l) {}

private:
char const *f, *fn;
uint16_t const &l;
uint16_t const& l;
};
struct OutMessage : public Message {
OutMessage(const mkn::kul::log::mode &_m = mkn::kul::log::mode::NON) : Message(_m) {}
OutMessage(const mkn::kul::log::mode& _m = mkn::kul::log::mode::NON) : Message(_m) {}
~OutMessage() { LogMan::INSTANCE().out(m, ss.str()); }
};
struct ErrMessage : public Message {
ErrMessage() : Message(mkn::kul::log::mode::ERR) {}
~ErrMessage() { LogMan::INSTANCE().err(ss.str()); }
};

#define KASIO_LOG_INF mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::INF)
#define KASIO_LOG_ERR mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::ERR)
#define KASIO_LOG_DBG mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::DBG)
#define KASIO_LOG_TRC mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::TRC)
#define KASIO_LOG_INF \
mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::INF)
#define KASIO_LOG_ERR \
mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::ERR)
#define KASIO_LOG_DBG \
mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::DBG)
#define KASIO_LOG_TRC \
mkn::kul::asio::LogMessage(__FILE__, __func__, __LINE__, mkn::kul::log::mode::TRC)
#define KASIO_LOG(sev) KLOG_##sev

#define KASIO_OUT_NON mkn::kul::asio::OutMessage()
Expand Down
2 changes: 1 addition & 1 deletion inc/mkn/kul/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace kul {
struct Assert {
template <typename T>
Assert(T t) {
(void) t;
(void)t;
#if !defined(NDEBUG)
if (!(t)) {
auto tid = mkn::kul::this_thread::id();
Expand Down
Loading