• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
12 #define BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
13 
14 #include <boost/config.hpp>
15 #include <string>    //std::string
16 #include <sstream>   //std::stringstream
17 #include <boost/interprocess/detail/os_thread_functions.hpp>
18 
19 namespace boost{
20 namespace interprocess{
21 namespace test{
22 
get_process_id_name(std::string & str)23 inline void get_process_id_name(std::string &str)
24 {
25    std::stringstream sstr;
26    sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
27    str = sstr.str().c_str();
28 }
29 
get_process_id_ptr_name(std::string & str,const void * ptr)30 inline void get_process_id_ptr_name(std::string &str, const void *ptr)
31 {
32    std::stringstream sstr;
33    sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << "_" << ptr << std::ends;
34    str = sstr.str().c_str();
35 }
36 
get_process_id_name()37 inline const char *get_process_id_name()
38 {
39    static std::string str;
40    get_process_id_name(str);
41    return str.c_str();
42 }
43 
get_process_id_ptr_name(void * ptr)44 inline const char *get_process_id_ptr_name(void *ptr)
45 {
46    static std::string str;
47    get_process_id_ptr_name(str, ptr);
48    return str.c_str();
49 }
50 
add_to_process_id_name(const char * name)51 inline const char *add_to_process_id_name(const char *name)
52 {
53    static std::string str;
54    get_process_id_name(str);
55    str += name;
56    return str.c_str();
57 }
58 
add_to_process_id_ptr_name(const char * name,void * ptr)59 inline const char *add_to_process_id_ptr_name(const char *name, void *ptr)
60 {
61    static std::string str;
62    get_process_id_ptr_name(str, ptr);
63    str += name;
64    return str.c_str();
65 }
66 
67 }  //namespace test{
68 }  //namespace interprocess{
69 }  //namespace boost{
70 
71 #endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
72