merge remote
commit
ca97850b6f
|
@ -96,6 +96,7 @@ if(MSVC)
|
||||||
else()
|
else()
|
||||||
# perhaps we should warn on unused variables, but BLT will have lots of them.
|
# perhaps we should warn on unused variables, but BLT will have lots of them.
|
||||||
target_compile_options(BLT PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(BLT PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
|
target_link_options(BLT PUBLIC -rdynamic)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
message("BLT ${CMAKE_PROJECT_VERSION} Successfully included!")
|
message("BLT ${CMAKE_PROJECT_VERSION} Successfully included!")
|
||||||
|
|
|
@ -21,15 +21,107 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
|
||||||
|
#include <cxxabi.h>
|
||||||
|
#include <blt/compatibility.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace blt
|
namespace blt
|
||||||
{
|
{
|
||||||
|
static BLT_CPP20_CONSTEXPR inline std::string demangle(const std::string& str)
|
||||||
template<typename BEGIN, typename END>
|
|
||||||
class enumerate
|
|
||||||
{
|
{
|
||||||
private:
|
int status;
|
||||||
|
// only defined for GNU C++11?
|
||||||
|
char* demangled_name = abi::__cxa_demangle(str.c_str(), nullptr, nullptr, &status);
|
||||||
|
if (demangled_name == nullptr)
|
||||||
|
return str;
|
||||||
|
std::string ret_name = demangled_name;
|
||||||
|
std::free(demangled_name);
|
||||||
|
return ret_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
namespace blt
|
||||||
|
{
|
||||||
|
static BLT_CPP20_CONSTEXPR inline std::string demangle(const std::string& str)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace blt
|
||||||
|
{
|
||||||
|
template<typename TYPE_ITR>
|
||||||
|
class enumerator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class iterator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using iterator_category = std::input_iterator_tag;
|
||||||
|
using value_type = typename TYPE_ITR::value_type;
|
||||||
|
using difference_type = typename TYPE_ITR::difference_type;
|
||||||
|
using pointer = typename TYPE_ITR::pointer;
|
||||||
|
using reference = typename TYPE_ITR::reference;
|
||||||
|
private:
|
||||||
|
size_t index = 0;
|
||||||
|
TYPE_ITR current;
|
||||||
|
public:
|
||||||
|
explicit iterator(TYPE_ITR current): current(current)
|
||||||
|
{};
|
||||||
|
|
||||||
|
iterator& operator++()
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
++current;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator operator++(int)
|
||||||
|
{
|
||||||
|
iterator retval = *this;
|
||||||
|
++(*this);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(iterator other) const
|
||||||
|
{ return current == other.current; }
|
||||||
|
|
||||||
|
bool operator!=(iterator other) const
|
||||||
|
{ return !(*this == other); }
|
||||||
|
|
||||||
|
std::pair<size_t, const reference> operator*() const
|
||||||
|
{
|
||||||
|
return {index, *current};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit enumerator(TYPE_ITR begin, TYPE_ITR end): begin_(begin), end_(end)
|
||||||
|
{}
|
||||||
|
|
||||||
|
iterator begin()
|
||||||
|
{
|
||||||
|
return begin_;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator end()
|
||||||
|
{
|
||||||
|
return end_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
iterator begin_;
|
||||||
|
iterator end_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static inline enumerator<typename T::iterator> enumerate(T container)
|
||||||
|
{
|
||||||
|
return enumerator{container.begin(), container.end()};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__llvm__)
|
#if defined(__GNUC__) || defined(__llvm__)
|
||||||
#define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline))
|
#define BLT_ATTRIB_NO_INLINE __attribute__ ((noinline))
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* See LICENSE file for license detail
|
* See LICENSE file for license detail
|
||||||
*/
|
*/
|
||||||
#include <blt/std/assert.h>
|
#include <blt/std/assert.h>
|
||||||
|
#include <blt/std/utility.h>
|
||||||
#include <blt/std/logging.h>
|
#include <blt/std/logging.h>
|
||||||
#include <blt/std/string.h>
|
#include <blt/std/string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -14,7 +15,6 @@
|
||||||
|
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
|
@ -23,6 +23,7 @@
|
||||||
char** messages = backtrace_symbols(ptrs, size);
|
char** messages = backtrace_symbols(ptrs, size);
|
||||||
|
|
||||||
#define BLT_FREE_STACK_TRACE() free(messages);
|
#define BLT_FREE_STACK_TRACE() free(messages);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define BLT_STACK_TRACE(number) void();
|
#define BLT_STACK_TRACE(number) void();
|
||||||
#define BLT_FREE_STACK_TRACE() void();
|
#define BLT_FREE_STACK_TRACE() void();
|
||||||
|
@ -59,8 +60,6 @@ namespace blt {
|
||||||
BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line);
|
BLT_ERROR("The assertion '%s' has failed in file '%s:%d'", expression, path, line);
|
||||||
BLT_ERROR("Stack Trace:");
|
BLT_ERROR("Stack Trace:");
|
||||||
|
|
||||||
backtrace_symbols(ptrs, size);
|
|
||||||
|
|
||||||
printStacktrace(messages, size, path, line);
|
printStacktrace(messages, size, path, line);
|
||||||
|
|
||||||
BLT_FREE_STACK_TRACE();
|
BLT_FREE_STACK_TRACE();
|
||||||
|
@ -69,6 +68,8 @@ namespace blt {
|
||||||
|
|
||||||
void printStacktrace(char** messages, int size, const char* path, int line)
|
void printStacktrace(char** messages, int size, const char* path, int line)
|
||||||
{
|
{
|
||||||
|
if (messages == nullptr)
|
||||||
|
return;
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
for (int i = 1; i < size; i++){
|
for (int i = 1; i < size; i++){
|
||||||
int tabs = i - 1;
|
int tabs = i - 1;
|
||||||
|
@ -94,7 +95,7 @@ namespace blt {
|
||||||
loc += std::to_string(line);
|
loc += std::to_string(line);
|
||||||
loc += '\'';
|
loc += '\'';
|
||||||
} else
|
} else
|
||||||
loc = mes.substr(0, mes.find('+'));
|
loc = demangle(mes.substr(0, mes.find('+')));
|
||||||
|
|
||||||
if (!loc.empty())
|
if (!loc.empty())
|
||||||
buffer += " in ";
|
buffer += " in ";
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include "blt/std/assert.h"
|
||||||
|
|
||||||
std::optional<int> get()
|
std::optional<int> get()
|
||||||
{
|
{
|
||||||
|
@ -47,6 +48,24 @@ int testFunc(int a, int b)
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testEnumerate(const std::vector<std::string>& test)
|
||||||
|
{
|
||||||
|
for (auto pair : blt::enumerate(test))
|
||||||
|
{
|
||||||
|
std::cout << pair.first << ": " << pair.second << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void getfucked()
|
||||||
|
{
|
||||||
|
BLT_ASSERT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fuckered()
|
||||||
|
{
|
||||||
|
getfucked();
|
||||||
|
}
|
||||||
|
|
||||||
void blt::test::utility::run()
|
void blt::test::utility::run()
|
||||||
{
|
{
|
||||||
//std::vector<int> temp;
|
//std::vector<int> temp;
|
||||||
|
@ -68,6 +87,7 @@ void blt::test::utility::run()
|
||||||
tableTest.addRow({"Sleeping Together (Sexual)", "10,000"});
|
tableTest.addRow({"Sleeping Together (Sexual)", "10,000"});
|
||||||
tableTest.addRow({"Relationship (I would do anything for you)", "1,000,000,000,000"});
|
tableTest.addRow({"Relationship (I would do anything for you)", "1,000,000,000,000"});
|
||||||
|
|
||||||
|
testEnumerate(tableTest.createTable(true, true));
|
||||||
|
|
||||||
printLines(tableTest.createTable(true, true));
|
printLines(tableTest.createTable(true, true));
|
||||||
|
|
||||||
|
@ -204,4 +224,6 @@ void blt::test::utility::run()
|
||||||
tableQ4i2.addRow({"Exit (10)", "{a + b, a * b, a - b}", " -- "});
|
tableQ4i2.addRow({"Exit (10)", "{a + b, a * b, a - b}", " -- "});
|
||||||
|
|
||||||
printLines(tableQ4i2.createTable(true, true));
|
printLines(tableQ4i2.createTable(true, true));
|
||||||
|
|
||||||
|
fuckered();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue