PGROUTING  2.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pgr_assert.h File Reference

Assertions Handling. More...

#include <string>
#include <exception>

Go to the source code of this file.

Classes

class  AssertFailedException
 Extends std::exception and is the exception that we throw if an assert fails. More...
 

Macros

#define __STRING(x)   #x
 
#define __TOSTRING(x)   __STRING(x)
 
#define pgassert(expr)
 Uses the standard assert syntax. More...
 
#define pgassertwm(expr, msg)
 Adds a message to the assertion. More...
 

Functions

std::string get_backtrace ()
 returns the execution path of the trace More...
 
std::string get_backtrace (const std::string &)
 

Detailed Description

Assertions Handling.

An assert functionality that uses C++ throw().

This file provides an alternative to assert functionality that will convert all pgassert() into C++ throw using an AssertFailedException class.

This allows catching errors and do appropriate clean up re-throw if needed to catch errors in the postgresql environment

Do not crash the backend server.

Definition in file pgr_assert.h.

Macro Definition Documentation

#define __STRING (   x)    #x

Definition at line 42 of file pgr_assert.h.

#define __TOSTRING (   x)    __STRING(x)

Definition at line 45 of file pgr_assert.h.

#define pgassert (   expr)
Value:
((expr) \
? static_cast<void>(0) \
"AssertFailedException: " __STRING(expr) \
" at " __FILE__ ":" __TOSTRING(__LINE__) + get_backtrace() ) )
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
std::string get_backtrace()
returns the execution path of the trace
Definition: pgr_assert.cpp:26
#define __TOSTRING(x)
Definition: pgr_assert.h:45
#define __STRING(x)
Definition: pgr_assert.h:42

Uses the standard assert syntax.

When an assertion fails it will throw AssertFailedException and what() will return a string like "AssertFailedException(2+2 == 5) at t.cpp:11"

Example:

#include <iostream>
#include "pgr_assert.h"
int main() {
try {
pgassert(2+2 == 4);
pgassert(2+2 == 5);
}
catch (AssertFailedException &e) {
std::cout << e.what() << "\n";
}
catch (std::exception& e) {
std::cout << e.what() << "\n";
}
catch(...) {
std::cout << "Caught unknown exception!\n";
}
return 0;
}

Definition at line 81 of file pgr_assert.h.

Referenced by pgrouting::contraction::Pgr_linear< G >::add_shortcut(), pgrouting::graph::Pgr_contractionGraph< G, T_V, T_E >::add_shortcut(), pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::add_vertices(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::adjacent(), pgrouting::tsp::TSP< MATRIX >::annealing(), Path::append(), create_new_edges(), pgrouting::vrp::Tw_node::Did(), do_pgr_astarManyToMany(), do_pgr_bdDijkstra(), do_pgr_contractGraph(), do_pgr_dijkstraVia(), do_pgr_driving_many_to_dist(), do_pgr_eucledianTSP(), do_pgr_floydWarshall(), do_pgr_ksp(), do_pgr_many_to_many_dijkstra(), do_pgr_many_to_many_withPoints(), do_pgr_many_withPointsDD(), do_pgr_max_flow(), do_pgr_test_c_edges(), do_pgr_test_matrixRows(), do_pgr_testXYedges(), do_pgr_tsp(), do_pgr_withPointsKsp(), pgrouting::contraction::Pgr_linear< G >::doContraction(), pgrouting::vrp::Vehicle_pickDeliver::erase(), pgrouting::vrp::Vehicle::erase(), pgrouting::vrp::Vehicle::evaluate(), pgrouting::vrp::Initial_solution::fill_truck_while_compatibleI(), pgrouting::vrp::Initial_solution::fill_truck_while_compatibleJ(), pgrouting::tsp::TSP< MATRIX >::find_closest_city(), pgrouting::vrp::Vehicle_pickDeliver::get_first_order(), pgrouting::tsp::eucledianDmatrix::get_row(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::get_V(), pgrouting::vrp::Vehicle_pickDeliver::get_worse_order(), Path::getSubpath(), pgrouting::graph::Pgr_base_graph< G, Vertex, Edge >::graph_add_edge(), pgrouting::tsp::TSP< MATRIX >::greedyInitial(), pgrouting::vrp::Vehicle_pickDeliver::insert(), pgrouting::vrp::Vehicle::insert(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::insert_edges(), pgrouting::vrp::Initial_solution::invariant(), pgrouting::vrp::Vehicle::invariant(), pgrouting::tsp::TSP< MATRIX >::invariant(), pgrouting::contraction::Pgr_deadend< G >::is_dead_end(), pgrouting::vrp::m_original_data(), pgrouting::vrp::Optimize::move_order(), pgrouting::vrp::Optimize::move_reduce_cost(), pgrouting::vrp::Pgr_pickDeliver::node(), Pgr_ksp< G >::compPaths::operator()(), pgrouting::vrp::operator<<(), pgrouting::vrp::Order::Order(), pgrouting::vrp::Pgr_pickDeliver::order_of(), pgrouting::graph::Pgr_base_graph< G, T_V, T_E >::Pgr_base_graph(), pgrouting::vrp::Tw_node::Pid(), pgrouting::vrp::Vehicle_pickDeliver::pop_back(), pgrouting::vrp::Vehicle::pop_back(), pgrouting::vrp::Vehicle_pickDeliver::pop_front(), pgrouting::vrp::Vehicle::pop_front(), pgrouting::vrp::Vehicle_pickDeliver::push_back(), pgrouting::vrp::Vehicle_pickDeliver::push_front(), rand(), pgrouting::tsp::Tour::reverse(), pgrouting::tsp::Tour::rotate(), pgrouting::vrp::Tw_node::set_Did(), pgrouting::vrp::Tw_node::set_Pid(), pgrouting::tsp::Tour::slide(), succ(), pgrouting::tsp::Tour::swap(), pgrouting::vrp::Vehicle::swap(), pgrouting::vrp::Optimize::swap_order(), pgrouting::vrp::Optimize::swap_worse(), pgrouting::tsp::TSP< MATRIX >::swapClimb(), pgrouting::tsp::Dmatrix::tourCost(), pgrouting::vrp::Tw_node::travel_time_to(), and pgrouting::tsp::TSP< MATRIX >::TSP().

#define pgassertwm (   expr,
  msg 
)
Value:
((expr) \
? static_cast<void>(0) \
"AssertFailedException: " __STRING(expr) \
" at " __FILE__ ":" __TOSTRING(__LINE__) + get_backtrace(msg) ) )
Extends std::exception and is the exception that we throw if an assert fails.
Definition: pgr_assert.h:126
std::string get_backtrace()
returns the execution path of the trace
Definition: pgr_assert.cpp:26
#define __TOSTRING(x)
Definition: pgr_assert.h:45
#define __STRING(x)
Definition: pgr_assert.h:42

Adds a message to the assertion.

Example:

pgassert(2+2 == 5, "Expected a 4 as result");
std::ostringstream log;
log << "Expected a 4 as result"
pgassert(2+2 == 5, log.str());

Definition at line 104 of file pgr_assert.h.

Referenced by pgrouting::vrp::Optimize::decrease_truck(), pgrouting::tsp::TSP< MATRIX >::find_closest_city(), pgrouting::tsp::TSP< MATRIX >::getDeltaReverse(), pgrouting::tsp::TSP< MATRIX >::getDeltaSlide(), pgrouting::tsp::TSP< MATRIX >::getDeltaSwap(), pgrouting::tsp::TSP< MATRIX >::greedyInitial(), pgrouting::vrp::Vehicle_pickDeliver::insert(), pgrouting::tsp::Dmatrix::is_symmetric(), pgrouting::vrp::Pgr_pickDeliver::order_of(), and pgrouting::tsp::eucledianDmatrix::set_ids().

Function Documentation

std::string get_backtrace ( )

returns the execution path of the trace

In case of a failed exception the backtrace can be is shown in the error message.

Does not work for windows, please read: http://stackoverflow.com/questions/27639931/can-not-find-execinfo-h-when-setup-malpack

Definition at line 26 of file pgr_assert.cpp.

Referenced by get_backtrace().

std::string get_backtrace ( const std::string &  )

Definition at line 47 of file pgr_assert.cpp.

References get_backtrace().