get_process_id_name.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
  11. #define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
  12. #include <boost/config.hpp>
  13. #include <string> //std::string
  14. #include <sstream> //std::stringstream
  15. #include <boost/interprocess/detail/os_thread_functions.hpp>
  16. namespace boost{
  17. namespace interprocess{
  18. namespace test{
  19. inline void get_process_id_name(std::string &str)
  20. {
  21. std::stringstream sstr;
  22. sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
  23. str = sstr.str().c_str();
  24. }
  25. inline void get_process_id_ptr_name(std::string &str, const void *ptr)
  26. {
  27. std::stringstream sstr;
  28. sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << "_" << ptr << std::ends;
  29. str = sstr.str().c_str();
  30. }
  31. inline const char *get_process_id_name()
  32. {
  33. static std::string str;
  34. get_process_id_name(str);
  35. return str.c_str();
  36. }
  37. inline const char *get_process_id_ptr_name(void *ptr)
  38. {
  39. static std::string str;
  40. get_process_id_ptr_name(str, ptr);
  41. return str.c_str();
  42. }
  43. inline const char *add_to_process_id_name(const char *name)
  44. {
  45. static std::string str;
  46. get_process_id_name(str);
  47. str += name;
  48. return str.c_str();
  49. }
  50. inline const char *add_to_process_id_ptr_name(const char *name, void *ptr)
  51. {
  52. static std::string str;
  53. get_process_id_ptr_name(str, ptr);
  54. str += name;
  55. return str.c_str();
  56. }
  57. } //namespace test{
  58. } //namespace interprocess{
  59. } //namespace boost{
  60. #endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP