Skip to content

Commit

Permalink
?
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDeegan committed May 1, 2022
1 parent ae3d01d commit d2cf18c
Show file tree
Hide file tree
Showing 48 changed files with 689 additions and 147 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64

- name: "Build/Test" # contains slash so use quotes otherwise UB
shell: cmd
env:
MKN_CL_PREFERRED: 1
run: | # /bin/link interferes with cl/link.exe
bash -c "rm /bin/link"
bash -c "curl -Lo mkn.exe https://github.com/PhilipDeegan/mkn/releases/download/latest/mkn.exe"
call "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
bash -c 'KLOG=3 ./mkn clean build run -dtKOp test -a "-EHsc -std:c++17"'
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-8",
"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"
}
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);
}

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);
}

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);
}

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...);
}

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);
}

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>{});
}

Expand Down
15 changes: 10 additions & 5 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 Down Expand Up @@ -116,10 +117,14 @@ struct ErrMessage : public Message {
~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
7 changes: 7 additions & 0 deletions inc/mkn/kul/assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef _MKN_KUL_ASSERT_HPP_
#define _MKN_KUL_ASSERT_HPP_

#include <cstdlib>

#include "mkn/kul/signal.hpp"

namespace mkn {
Expand All @@ -48,6 +50,11 @@ struct Assert {
#endif
}
};

void abort_if(bool b) {
if (b) std::abort();
}

} // namespace kul
} // namespace mkn

Expand Down
3 changes: 2 additions & 1 deletion inc/mkn/kul/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ inline const std::string receive(std::string const &t = "") {

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) {}
};

class ArgNotFoundException : public Exception {
Expand Down
8 changes: 4 additions & 4 deletions inc/mkn/kul/dbg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ class StackTrace {
#endif // KUL_DBG_FUNC_ENTER

#ifndef KUL_DBG_FUNC_ON_ENTER
#define KUL_DBG_FUNC_ON_ENTER \
#define KUL_DBG_FUNC_ON_ENTER \
KOUT(TRC) << mkn::kul::LogMan::INSTANCE().str(m_fi, m_fu, m_li, mkn::kul::log::mode::TRC, "", \
"[%M]: %T - %D : %F:%L fn(%N)") \
"[%M]: %T - %D : %F:%L fn(%N)") \
<< " - ENTERED";
#endif // KUL_DBG_FUNC_ON_ENTER

#ifndef KUL_DBG_FUNC_ON_EXIT
#define KUL_DBG_FUNC_ON_EXIT \
#define KUL_DBG_FUNC_ON_EXIT \
KOUT(TRC) << mkn::kul::LogMan::INSTANCE().str(m_fi, m_fu, m_li, mkn::kul::log::mode::TRC, "", \
"[%M]: %T - %D : %F:%L fn(%N)") \
"[%M]: %T - %D : %F:%L fn(%N)") \
<< " - Function time: " << (mkn::kul::Now::MICROS() - m_start) << " μs";
#endif // KUL_DBG_FUNC_ON_EXIT

Expand Down
2 changes: 0 additions & 2 deletions inc/mkn/kul/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ class Exit : public Exception {
} // namespace kul
} // namespace mkn



#define KEXCEPT(e, m) throw e(__FILE__, __LINE__, m)
#define KEXCEPTSTR(e) throw e(__FILE__, __LINE__, "")
#define KEXCEPTION(m) throw Exception(__FILE__, __LINE__, m)
Expand Down
66 changes: 56 additions & 10 deletions inc/mkn/kul/for.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace mkn {
namespace kul {

template<typename T = std::size_t>
template <typename T = std::size_t>
struct Apply {
template<size_t i>
constexpr auto operator()(){ return std::integral_constant<T, i>{}; }
template <size_t i>
constexpr auto operator()() {
return std::integral_constant<T, i>{};
}
};

template <typename Apply, size_t... Is>
Expand All @@ -55,17 +57,61 @@ constexpr auto apply_N(Apply&& f) {

template <size_t N, typename Fn>
constexpr void for_N(Fn&& fn) {
/*
for_N<2>([](auto ic) {
constexpr auto i = ic();
// ...
});
*/
/*
for_N<2>([](auto ic) {
constexpr auto i = ic();
// ...
});
*/

std::apply([&](auto... ics) { (fn(ics), ...); }, apply_N<N>(Apply{}));
}

std::apply([&](auto ... ics) { (fn(ics), ...);}, apply_N<N>(Apply{}));
template <typename F>
auto generate(F&& f, std::size_t from, std::size_t to) {
using value_type = std::decay_t<std::result_of_t<F&(std::size_t const&)>>;
std::vector<value_type> v;
std::size_t count = to - from;
if (count > 0) v.reserve(count);
for (std::size_t i = from; i < to; ++i) v.emplace_back(f(i));
return v;
}

template <typename F>
auto generate(F&& f, std::size_t count) {
return generate(std::forward<F>(f), 0, count);
}

template <typename F, typename Container>
auto generate(F&& f, Container& container) {
using T = typename Container::value_type;
using value_type = std::decay_t<std::result_of_t<F&(T&)>>;
std::vector<value_type> v1;
if (container.size() > 0) v1.reserve(container.size());
for (auto& v : container) v1.emplace_back(f(v));
return v1;
}

template <std::size_t Idx, typename F, typename Type, std::size_t Size>
auto constexpr generate_array__(F& f, std::array<Type, Size>& arr) {
return f(arr[Idx]);
}

template <typename Type, std::size_t Size, typename F, std::size_t... Is>
auto constexpr generate_array_(F& f, std::array<Type, Size>& arr,
std::integer_sequence<std::size_t, Is...>) {
return std::array{generate_array__<Is>(f, arr)...};
}

template <typename F, typename Type, std::size_t Size>
auto constexpr generate(F&& f, std::array<Type, Size>& arr) {
return generate_array_(f, arr, std::make_integer_sequence<std::size_t, Size>{});
}

template <typename F, typename Container>
auto generate(F&& f, Container&& v) {
return generate(std::forward<F>(f), v);
}

} // namespace kul
} // namespace mkn
Expand Down
9 changes: 4 additions & 5 deletions inc/mkn/kul/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ enum mode { OFF = -1, NON = 0, INF, ERR, DBG, OTH, TRC };

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 Down Expand Up @@ -183,9 +184,7 @@ class Message {
std::stringstream ss;
const log::mode &m;

Message(const log::mode &_m) : m(_m) {
ss.precision(22);
}
Message(const log::mode &_m) : m(_m) { ss.precision(22); }

public:
template <class T>
Expand Down Expand Up @@ -276,6 +275,6 @@ class DBoMessage : public Message {

#define KERR mkn::kul::ErrMessage()

#endif //!defined(_MKN_KUL_DISABLE_KLOG_DEF_)
#endif //! defined(_MKN_KUL_DISABLE_KLOG_DEF_)

#endif /* _MKN_KUL_LOG_HPP_ */
Loading

0 comments on commit d2cf18c

Please sign in to comment.