General Purpose Debugging Tools
Empirical vectors and arrays
Empirical contains of intelligent versions of STL vectors and arrays that will warn you if you make common errors, but otherwise behave identically to the STL version. Most importantly, they will detect attempts to index to out-of-bounds locations and throw an error. These features are critical for writing code that will be compiled to Javascript with Emscripten, because Valgrind doesn’t run on Javascript. They also save a lot of debugging time when writing native C++ code.
“But wait,” you might say, “surely all of these additional checks slow down your code!” This is true when you compile in debug mode (the default). However, when you compile with the -DNDEBUG flag, these objects are directly replaced with their STL equivalent, removing any slowdown. That way, you can get all the debugging benefits while you’re writing your program, but all the speed benefits when you’re actually using it.
emp::vector Example
#include "Empirical/include/emp/base/vector.hpp"
emp::vector<int> vec({1,2,3});
// You can treat this just like an std::vector<int>
emp::array Example
#include "Empirical/include/emp/base/array.hpp"
emp::array<int, 3> array({1,2,3});
// You can treat this just like an std::array<int, 3>
Empirical asserts
These asserts function similarly to normal asserts, with a few important additional features:
If compiled with Emscripten they will provide pop-up alerts when run in a web browser.
emp_assert can take additional arguments. If the assert is triggered, those extra arguments will be evaluated and printed.
if NDEBUG or EMP_NDEBUG is defined, the expression in emp_assert() is not evaluated.
if EMP_TDEBUG is defined, emp_assert() goes into test mode and records failures, but does not abort. (useful for unit tests of asserts)
Example:
#include "Empirical/include/emp/base/assert.hpp"
int a = 6;
emp_assert(a==5, a);
When compiled in debug mode (i.e. without the -DNDEBUG flag), this will trigger an assertion error and print the value of a.
Empirical also has an emscripten-specific assert, which will only trigger an error when the code was compiled with Emscripten:
#include "Empirical/include/emp/base/emscripten_assert.hpp"
int a = 6;
// If compiled in with emscripten in debug mode,
// this will print a warning and the value of a
emp_emscripten_assert(a==5, a);
If you want your assert to be triggered outside of debug mode, you can use emp_always_assert()
.
Empirical Warnings
These work very similar to Empirical asserts, except they do not throw assertion errors. When compiled in debug mode, they will print a warning (and any desired additional information) on failure but program execution will continue. When compiled outside of debug mode they do nothing.
#include "Empirical/include/emp/base/assert_warning.hpp"
#include <iostream>
int a = 6;
// If compiled in debug mode, this will print a
// warning and the value of a
emp_assert_warning(a==5, a);
// This will get printed because no assertion
// error will be triggered
std::cout << "Still running!" << std::endl;
If you want your warning to be triggered outside of debug mode, you can use emp_always_assert_warning()
.
Empirical pointers
Ptr objects behave as normal pointers under most conditions. However, if
a program is compiled with EMP_TRACK_MEM
set, then these pointers
perform extra tests to ensure that they point to valid memory and that
memory is freed before pointers are released.
If you trip an assert, you can re-do the run a track a specific pointer
by defining EMP_ABORT_PTR_NEW
or EMP_ABORT_PTR_DELETE
to the ID of
the pointer in question. This will allow you to track the pointer more
easily in a debugger.
Example:
#include "Empirical/include/emp/base/Ptr.hpp"
emp::Ptr<int> int_ptr;
int_ptr.New(123456); // Store the value 123456 in int_ptr.
std::cout << "*int_ptr = " << *int_ptr << std::endl;
int_ptr.Delete();
API
- MapProxy.hpp
MapProxy
MapProxy::MapProxy()
MapProxy::emp_GetValue()
MapProxy::emp_GetValue()
MapProxy::emp_IsInit()
MapProxy::operator=()
MapProxy::operator+=()
MapProxy::operator-=()
MapProxy::operator*=()
MapProxy::operator/=()
MapProxy::operator%=()
MapProxy::operator&=()
MapProxy::operator|=()
MapProxy::operator^=()
MapProxy::operator<<=()
MapProxy::operator>>=()
MapProxy::operator++()
MapProxy::operator--()
MapProxy::operator++()
MapProxy::operator--()
MapProxy::operator+()
MapProxy::operator-()
MapProxy::operator!()
MapProxy::operator~()
MapProxy::operator+()
MapProxy::operator-()
MapProxy::operator*()
MapProxy::operator/()
MapProxy::operator%()
MapProxy::operator&()
MapProxy::operator|()
MapProxy::operator^()
MapProxy::operator<<()
MapProxy::operator>>()
MapProxy::operator&&()
MapProxy::operator||()
MapProxy::operator==()
MapProxy::operator!=()
MapProxy::operator<()
MapProxy::operator<=()
MapProxy::operator>()
MapProxy::operator>=()
MapProxy::operator[]()
MapProxy::operator[]()
MapProxy::operator*()
MapProxy::operator*()
MapProxy::operator&()
MapProxy::operator->()
MapProxy::operator->*()
MapProxy::operator()()
MapProxy::operator()()
MapProxy::operator,()
MapProxy::IsNull()
MapProxy::Delete()
MapProxy::DeleteArray()
MapProxy::operator T&()
MapProxy::operator const T&()
MapProxy::value
MapProxy::is_init
- Ptr.hpp
PtrStatus
FillMemory()
FillMemoryFunction()
SetPtrDebug()
GetPtrDebug()
operator<<()
operator>>()
ToPtr()
TrackPtr()
NewPtr()
CopyPtr()
CopyPtrs()
ClonePtrs()
NewArrayPtr()
CopyMemory()
PtrInfo
PtrInfo::PtrInfo()
PtrInfo::PtrInfo()
PtrInfo::PtrInfo()
PtrInfo::PtrInfo()
PtrInfo::operator=()
PtrInfo::operator=()
PtrInfo::~PtrInfo()
PtrInfo::GetPtr()
PtrInfo::GetCount()
PtrInfo::GetArrayBytes()
PtrInfo::IsActive()
PtrInfo::IsArray()
PtrInfo::SetArray()
PtrInfo::Inc()
PtrInfo::Dec()
PtrInfo::MarkDeleted()
PtrInfo::OK()
PtrInfo::ptr
PtrInfo::count
PtrInfo::status
PtrInfo::array_bytes
PtrTracker
PtrTracker::~PtrTracker()
PtrTracker::GetInfo()
PtrTracker::GetInfo()
PtrTracker::HasPtr()
PtrTracker::GetCurID()
PtrTracker::GetNumIDs()
PtrTracker::GetArrayBytes()
PtrTracker::IsDeleted()
PtrTracker::IsActive()
PtrTracker::IsActiveID()
PtrTracker::IsArrayID()
PtrTracker::GetIDCount()
PtrTracker::New()
PtrTracker::NewArray()
PtrTracker::IncID()
PtrTracker::DecID()
PtrTracker::MarkDeleted()
PtrTracker::Get()
PtrTracker::PtrTracker()
PtrTracker::PtrTracker()
PtrTracker::PtrTracker()
PtrTracker::operator=()
PtrTracker::operator=()
PtrTracker::ptr_id
PtrTracker::id_info
PtrTracker::UNTRACKED_ID
BasePtr
BasePtr
BasePtr
Ptr
Ptr::element_type
Ptr::Ptr()
Ptr::Ptr()
Ptr::Ptr()
Ptr::Ptr()
Ptr::Ptr()
Ptr::Ptr()
Ptr::~Ptr()
Ptr::IsNull()
Ptr::Raw()
Ptr::Raw()
Ptr::Cast()
Ptr::ConstCast()
Ptr::DynamicCast()
Ptr::ReinterpretCast()
Ptr::New()
Ptr::NewArray()
Ptr::Delete()
Ptr::DeleteArray()
Ptr::Hash()
Ptr::operator=()
Ptr::operator=()
Ptr::operator=()
Ptr::operator TYPE*()
Ptr::operator bool()
Ptr::operator bool()
Ptr::operator==()
Ptr::operator!=()
Ptr::operator<()
Ptr::operator>()
Ptr::operator<=()
Ptr::operator>=()
Ptr::operator+()
Ptr::operator-()
Ptr::operator+()
Ptr::operator-()
Ptr::FillMemoryFunction()
Ptr::FillMemory()
Ptr::DebugGetCount()
Ptr::DebugIsArray()
Ptr::DebugGetArrayBytes()
Ptr::DebugIsActive()
Ptr::OK()
Ptr::hash_t
- always_assert.hpp
- always_assert_warning.hpp
- array.hpp
array_iterator
array_iterator::this_t
array_iterator::array_t
array_iterator::iterator_category
array_iterator::value_type
array_iterator::difference_type
array_iterator::pointer
array_iterator::reference
array_iterator::array_iterator()
array_iterator::array_iterator()
array_iterator::array_iterator()
array_iterator::array_iterator()
array_iterator::~array_iterator()
array_iterator::OK()
array_iterator::operator=()
array_iterator::operator=()
array_iterator::operator ITERATOR_T()
array_iterator::operator const ITERATOR_T()
array_iterator::operator*()
array_iterator::operator*()
array_iterator::operator->()
array_iterator::operator->()
array_iterator::operator++()
array_iterator::operator++()
array_iterator::operator--()
array_iterator::operator--()
array_iterator::operator+()
array_iterator::operator-()
array_iterator::operator-()
array_iterator::operator+=()
array_iterator::operator-=()
array_iterator::operator[]()
array_iterator::operator[]()
array_iterator::it
array_iterator::arr_ptr
array
array::this_t
array::iterator
array::const_iterator
array::reverse_iterator
array::const_reverse_iterator
array::value_type
array::size_type
array::reference
array::const_reference
array::operator<=>()
array::operator std::array<T, N>()
array::size()
array::data()
array::data()
array::begin()
array::begin()
array::end()
array::end()
array::operator[]()
array::operator[]()
array::back()
array::back()
array::front()
array::front()
array::fill()
array::resize()
array::resize()
array::push_back()
array::pop_back()
array::insert()
array::erase()
array::emplace()
array::emplace_back()
array::serialize()
array::_data
array::N
tuple_size
- assert.hpp
- assert_warning.hpp
- emscripten_assert.hpp
- error.hpp
- errors.hpp
- map.hpp
map
map::key_type
map::mapped_type
map::value_type
map::key_compare
map::value_compare
map::allocator_type
map::reference
map::const_reference
map::pointer
map::const_pointer
map::iterator
map::const_iterator
map::reverse_iterator
map::const_reverse_iterator
map::difference_type
map::size_type
map::map()
map::map()
map::map()
map::map()
map::map()
map::map()
map::map()
map::map()
map::operator=()
map::operator=()
map::operator[]()
map::this_t
map::base_t
map::proxy_t
multimap
multimap::key_type
multimap::mapped_type
multimap::value_type
multimap::key_compare
multimap::value_compare
multimap::allocator_type
multimap::reference
multimap::const_reference
multimap::pointer
multimap::const_pointer
multimap::iterator
multimap::const_iterator
multimap::reverse_iterator
multimap::const_reverse_iterator
multimap::difference_type
multimap::size_type
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::multimap()
multimap::operator=()
multimap::operator=()
multimap::operator[]()
multimap::this_t
multimap::base_t
multimap::proxy_t
- notify.hpp
notify
notify::id_t
notify::message_t
notify::except_data_t
notify::id_arg_t
notify::message_arg_t
notify::response_t
notify::exit_fun_t
notify::Type
notify::TypeID()
notify::ColorTypeID()
notify::GetData()
notify::MessageHandlers()
notify::DebugHandlers()
notify::WarningHandlers()
notify::ErrorHandlers()
notify::AddExitHandler()
notify::ClearExitHandlers()
notify::ReplaceExitHandlers()
notify::ReplaceExitHandlers()
notify::Exit()
notify::Notify()
notify::Pause()
notify::Unpause()
notify::Message()
notify::Debug()
notify::Warning()
notify::Error()
notify::TestWarning()
notify::TestError()
notify::AddHandler()
notify::AddHandler()
notify::Ignore()
notify::SetVerbose()
notify::Verbose()
notify::Exception()
notify::GetExceptions()
notify::GetException()
notify::CountExceptions()
notify::CountExceptions()
notify::HasExceptions()
notify::HasException()
notify::ClearExceptions()
notify::ClearException()
notify::num_types
notify::ExceptInfo
notify::HandlerSet
notify::HandlerSet::HandlerSet()
notify::HandlerSet::HandlerSet()
notify::HandlerSet::HandlerSet()
notify::HandlerSet::~HandlerSet()
notify::HandlerSet::GetExitOnFail()
notify::HandlerSet::SetExitOnFail()
notify::HandlerSet::Trigger()
notify::HandlerSet::Trigger()
notify::HandlerSet::Trigger()
notify::HandlerSet::Add()
notify::HandlerSet::Add()
notify::HandlerSet::Add()
notify::HandlerSet::Clear()
notify::HandlerSet::Replace()
notify::HandlerSet::Replace()
notify::HandlerSet::fun_t
notify::HandlerSet::fun_no_data_t
notify::HandlerSet::fun_msg_only_t
notify::HandlerSet::handlers
notify::HandlerSet::exit_on_fail
notify::NotifyData
- optional.hpp
- optional_throw.hpp
- unordered_map.hpp
unordered_map
unordered_map::key_type
unordered_map::mapped_type
unordered_map::value_type
unordered_map::hasher
unordered_map::key_equal
unordered_map::allocator_type
unordered_map::reference
unordered_map::const_reference
unordered_map::pointer
unordered_map::const_pointer
unordered_map::iterator
unordered_map::const_iterator
unordered_map::local_iterator
unordered_map::const_local_iterator
unordered_map::difference_type
unordered_map::size_type
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::unordered_map()
unordered_map::operator=()
unordered_map::operator=()
unordered_map::operator[]()
unordered_map::this_t
unordered_map::base_t
unordered_map::proxy_t
unordered_multimap
unordered_multimap::key_type
unordered_multimap::mapped_type
unordered_multimap::value_type
unordered_multimap::hasher
unordered_multimap::key_equal
unordered_multimap::allocator_type
unordered_multimap::reference
unordered_multimap::const_reference
unordered_multimap::pointer
unordered_multimap::const_pointer
unordered_multimap::iterator
unordered_multimap::const_iterator
unordered_multimap::local_iterator
unordered_multimap::const_local_iterator
unordered_multimap::difference_type
unordered_multimap::size_type
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::unordered_multimap()
unordered_multimap::operator=()
unordered_multimap::operator=()
unordered_multimap::operator[]()
unordered_multimap::this_t
unordered_multimap::base_t
unordered_multimap::proxy_t
- vector.hpp
operator<<()
operator>>()
vector
vector::iterator
vector::const_iterator
vector::reverse_iterator
vector::const_reverse_iterator
vector::value_type
vector::size_type
vector::reference
vector::const_reference
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::~vector()
vector::size()
vector::begin()
vector::begin()
vector::end()
vector::end()
vector::cbegin()
vector::cend()
vector::rbegin()
vector::rbegin()
vector::rend()
vector::rend()
vector::crbegin()
vector::crend()
vector::resize()
vector::resize()
vector::operator=()
vector::operator[]()
vector::operator[]()
vector::back()
vector::back()
vector::front()
vector::front()
vector::push_back()
vector::pop_back()
vector::insert()
vector::erase()
vector::emplace()
vector::emplace_back()
vector::revision
vector::this_t
vector::stdv_t
vector::MAX_SIZE
vector::iterator_wrapper
vector::iterator_wrapper::this_t
vector::iterator_wrapper::wrapped_t
vector::iterator_wrapper::vec_t
vector::iterator_wrapper::iterator_wrapper()
vector::iterator_wrapper::iterator_wrapper()
vector::iterator_wrapper::iterator_wrapper()
vector::iterator_wrapper::iterator_wrapper()
vector::iterator_wrapper::~iterator_wrapper()
vector::iterator_wrapper::OK()
vector::iterator_wrapper::operator=()
vector::iterator_wrapper::operator=()
vector::iterator_wrapper::operator ITERATOR_T()
vector::iterator_wrapper::operator const ITERATOR_T()
vector::iterator_wrapper::operator*()
vector::iterator_wrapper::operator*()
vector::iterator_wrapper::operator->()
vector::iterator_wrapper::operator->()
vector::iterator_wrapper::operator++()
vector::iterator_wrapper::operator++()
vector::iterator_wrapper::operator--()
vector::iterator_wrapper::operator--()
vector::iterator_wrapper::operator+()
vector::iterator_wrapper::operator-()
vector::iterator_wrapper::operator-()
vector::iterator_wrapper::operator+=()
vector::iterator_wrapper::operator-=()
vector::iterator_wrapper::operator[]()
vector::iterator_wrapper::v_ptr
vector::iterator_wrapper::revision
vector::iterator_wrapper::ErrorCode()
vector::iterator_wrapper::ErrorStart()
vector
vector::iterator
vector::const_iterator
vector::value_type
vector::size_type
vector::reference
vector::const_reference
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::vector()
vector::resize()
vector::resize()
vector::operator=()
vector::operator[]()
vector::operator[]()
vector::back()
vector::back()
vector::front()
vector::front()
vector::pop_back()
vector::this_t
vector::stdv_t
vector::MAX_SIZE