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#include <boost/interprocess/detail/os_file_functions.hpp>
19
20namespace boost{
21namespace interprocess{
22namespace test{
23
24inline void get_process_id_name(std::string &str)
25{
26 std::stringstream sstr;
27 sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
28 str = sstr.str().c_str();
29}
30
31inline void get_process_id_ptr_name(std::string &str, const void *ptr)
32{
33 std::stringstream sstr;
34 sstr << "process_" << boost::interprocess::ipcdetail::get_current_process_id() << "_" << ptr << std::ends;
35 str = sstr.str().c_str();
36}
37
38inline const char *get_process_id_name()
39{
40 static bool done = false;
41 static std::string str;
42 if(!done)
43 get_process_id_name(str);
44 return str.c_str();
45}
46
47inline const char *get_process_id_ptr_name(void *ptr)
48{
49 static bool done = false;
50 static std::string str;
51 if(!done)
52 get_process_id_ptr_name(str, ptr);
53 return str.c_str();
54}
55
56inline const char *add_to_process_id_name(const char *name)
57{
58 static bool done = false;
59 static std::string str;
60 if(!done){
61 get_process_id_name(str);
62 str += name;
63 }
64 return str.c_str();
65}
66
67inline const char *add_to_process_id_ptr_name(const char *name, void *ptr)
68{
69 static bool done = false;
70 static std::string str;
71 if(!done){
72 get_process_id_ptr_name(str, ptr);
73 str += name;
74 }
75 return str.c_str();
76}
77
78} //namespace test{
79
80inline std::string get_filename()
81{
82 std::string ret (ipcdetail::get_temporary_path());
83 ret += "/";
84 ret += test::get_process_id_name();
85 return ret;
86}
87
88#ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES
89
90namespace test {
91
92inline void get_process_id_wname(std::wstring &str)
93{
94 std::wstringstream sstr;
95 sstr << L"process_" << boost::interprocess::ipcdetail::get_current_process_id() << std::ends;
96 str = sstr.str().c_str();
97}
98
99inline const wchar_t *get_process_id_wname()
100{
101 static bool done = false;
102 static std::wstring str;
103 if(!done)
104 get_process_id_wname(str);
105
106 return str.c_str();
107}
108
109inline const wchar_t *add_to_process_id_name(const wchar_t *name)
110{
111 static bool done = false;
112 static std::wstring str;
113 if(!done){
114 get_process_id_wname(str);
115 str += name;
116 }
117 return str.c_str();
118}
119
120} //namespace test {
121
122inline std::wstring get_wfilename()
123{
124 std::wstring ret (ipcdetail::get_temporary_wpath());
125 ret += L"/";
126 ret += test::get_process_id_wname();
127 return ret;
128}
129
130#endif
131
132} //namespace interprocess{
133} //namespace boost{
134
135#endif //#ifndef BOOST_INTERPROCESS_GET_PROCESS_ID_NAME_HPP
136

source code of boost/libs/interprocess/test/get_process_id_name.hpp