error_stack.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /** \file itasc/kdl/utilities/error_stack.cpp
  2. * \ingroup itasc
  3. */
  4. /*****************************************************************************
  5. * Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
  6. *
  7. * \version
  8. * ORO_Geometry V0.2
  9. *
  10. * \par History
  11. * - $log$
  12. *
  13. * \par Release
  14. * $Name: $
  15. ****************************************************************************/
  16. #include "error_stack.h"
  17. #include <stack>
  18. #include <vector>
  19. #include <string>
  20. #include <cstring>
  21. namespace KDL {
  22. // Trace of the call stack of the I/O routines to help user
  23. // interprete error messages from I/O
  24. typedef std::stack<std::string> ErrorStack;
  25. ErrorStack errorstack;
  26. // should be in Thread Local Storage if this gets multithreaded one day...
  27. void IOTrace(const std::string& description) {
  28. errorstack.push(description);
  29. }
  30. void IOTracePop() {
  31. errorstack.pop();
  32. }
  33. void IOTraceOutput(std::ostream& os) {
  34. while (!errorstack.empty()) {
  35. os << errorstack.top().c_str() << std::endl;
  36. errorstack.pop();
  37. }
  38. }
  39. void IOTracePopStr(char* buffer,int size) {
  40. if (errorstack.empty()) {
  41. *buffer = 0;
  42. return;
  43. }
  44. strncpy(buffer,errorstack.top().c_str(),size);
  45. errorstack.pop();
  46. }
  47. }