ʻOhana
Population structure, admixture history, and selection using learning methods.
Public Types | Static Public Member Functions
jade::basic_assertion< TChar > Class Template Reference

A template for a class that asserts valid conditions. More...

#include <jade.assert.hpp>

+ Collaboration diagram for jade::basic_assertion< TChar >:

Public Types

typedef TChar char_type
 The character type. More...
 
typedef std::basic_string< char_typestring_type
 The string type. More...
 

Static Public Member Functions

static void validate (const bool is_true, char_type const *const expression, char_type const *const file, const int line)
 Validates an expression is true; if not, this method throws an exception. More...
 

Detailed Description

template<typename TChar>
class jade::basic_assertion< TChar >

A template for a class that asserts valid conditions.

Definition at line 23 of file jade.assert.hpp.

Member Typedef Documentation

◆ char_type

template<typename TChar >
typedef TChar jade::basic_assertion< TChar >::char_type

The character type.

Definition at line 27 of file jade.assert.hpp.

◆ string_type

template<typename TChar >
typedef std::basic_string<char_type> jade::basic_assertion< TChar >::string_type

The string type.

Definition at line 30 of file jade.assert.hpp.

Member Function Documentation

◆ validate()

template<typename TChar >
static void jade::basic_assertion< TChar >::validate ( const bool  is_true,
char_type const *const  expression,
char_type const *const  file,
const int  line 
)
inlinestatic

Validates an expression is true; if not, this method throws an exception.

Parameters
is_trueThe validated expression.
expressionThe expression text.
fileThe name of the file.
lineThe line number.

Definition at line 36 of file jade.assert.hpp.

41  {
42  if (is_true)
43  return;
44 
45  auto & err = _err();
46  err << file << char_type('(') << line << char_type(')')
47  << char_type(':') << char_type(' ') << expression
48  << std::endl;
49 
50  void * addresses[256];
51  const auto n = ::backtrace(
52  addresses,
53  std::extent<decltype(addresses)>::value);
54 
55  typedef std::unique_ptr<
56  char_type *,
57  decltype(&std::free)
58  > symbols_ptr_type;
59 
60  const symbols_ptr_type symbols_ptr (
61  _backtrace_symbols(addresses, n),
62  &std::free);
63  const auto symbols = symbols_ptr.get();
64 
65  for (auto i = 1; i < n; i++)
66  {
67  const auto symbol = symbols[i];
68 
69  //
70  // Look for the last '+' symbol; if found subract white-space
71  // off the end of the mangled function name.
72  //
73  auto end = symbol;
74  while (*end != char_type('\0'))
75  ++end;
76  while (end != symbol && *end != char_type('+'))
77  --end;
78  while (end > symbol && end[-1] == char_type(' '))
79  --end;
80 
81  //
82  // Loop back until the first white-space symbol or parenthesis
83  // symbol is found.
84  //
85  auto begin = std::max(symbol, end - 1);
86  while (
87  begin > symbol &&
88  begin[-1] != char_type(' ') &&
89  begin[-1] != char_type('('))
90  --begin;
91 
92  //
93  // If the mangled name wasn't found, then print the mangled
94  // version; otherwise, replace the manged name with the
95  // demangled version and print the reformatted line.
96  //
97  if (begin <= symbol || end <= symbol)
98  {
99  err << symbol << std::endl;
100  }
101  else
102  {
103  for (auto p = symbol; p != begin; p++)
104  err << *p;
105  const auto replaced = *end;
106  *end++ = char_type('\0');
107 
108  err << _demangle(begin) << replaced << end << std::endl;
109  }
110  }
111 
112  throw std::runtime_error("assertion failure");
113  }

The documentation for this class was generated from the following file:
jade::basic_assertion::char_type
TChar char_type
The character type.
Definition: jade.assert.hpp:27