SharedMemoryUtils.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2017 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_INTERPROCESS__SHARED_MEMORY_UTILS
18 #define COM_BORA_SOFTWARE__BALAU_INTERPROCESS__SHARED_MEMORY_UTILS
19 
20 #include <Balau/Type/UUID.hpp>
21 #include <Balau/Util/Strings.hpp>
22 
23 #include <boost/interprocess/managed_shared_memory.hpp>
24 #include <boost/dll/runtime_symbol_info.hpp>
25 
26 namespace Balau::Interprocess {
27 
31 using CreateOnlySelector = boost::interprocess::create_only_t;
32 
36 using OpenOrCreateSelector = boost::interprocess::open_or_create_t;
37 
41 using OpenOnlySelector = boost::interprocess::open_only_t;
42 
46 using OpenReadOnlySelector = boost::interprocess::open_read_only_t;
47 
49 
53 extern const CreateOnlySelector CreateOnly;
54 
59 
63 extern const OpenOnlySelector OpenOnly;
64 
69 
71 
79  static std::string namePrefixFromAppPath() {
80  return Util::Strings::replaceAll(boost::dll::program_location().string(), "[:/\\\\]", "_");
81  }
82 
86  static std::string namePrefixFromUUID() {
87  return Util::Strings::replaceAll(UUID().asString(), "-", "_");
88  }
89 
91 
92  public: SharedMemoryUtils() = delete;
93  public: SharedMemoryUtils(const SharedMemoryUtils &) = delete;
94  public: SharedMemoryUtils & operator = (const SharedMemoryUtils &) = delete;
95 };
96 
97 } // namespace Balau::Interprocess
98 
99 #endif // COM_BORA_SOFTWARE__BALAU_INTERPROCESS__SHARED_MEMORY_UTILS
boost::interprocess::open_or_create_t OpenOrCreateSelector
Type of OpenOrCreate constructor selector.
Definition: SharedMemoryUtils.hpp:36
const CreateOnlySelector CreateOnly
Used to select an interprocess queue/object constructor that creates only.
boost::interprocess::create_only_t CreateOnlySelector
Type of CreateOnly constructor selector.
Definition: SharedMemoryUtils.hpp:31
static std::basic_string< CharT > replaceAll(const StringT< CharT, T ... > &input, const MatchT &match, const ReplacementT &replacement)
Replace all occurrences of the specified string with the supplied replacement.
Definition: Strings.hpp:844
boost::interprocess::open_only_t OpenOnlySelector
Type of OpenOrCreate constructor selector.
Definition: SharedMemoryUtils.hpp:41
UUID class, using the Boost uuid implementation.
static std::string namePrefixFromUUID()
Create a name prefix by canonicalising a UUID.
Definition: SharedMemoryUtils.hpp:86
Interprocess functionality including interprocess containers.
Definition: MSharedMemoryObject.hpp:27
const OpenOrCreateSelector OpenOrCreate
Used to select an interprocess queue/object constructor that opens or creates.
static std::string namePrefixFromAppPath()
Create a name prefix by canonicalising the application path.
Definition: SharedMemoryUtils.hpp:79
Utilities for shared memory items.
Definition: SharedMemoryUtils.hpp:75
Utilities for strings.
const OpenOnlySelector OpenOnly
Used to select an interprocess queue/object constructor that opens only.
const OpenReadOnlySelector OpenReadOnly
Used to select an interprocess queue/object constructor that opens ready only.
UUID class, using the Boost uuid implementation.
Definition: UUID.hpp:33
boost::interprocess::open_read_only_t OpenReadOnlySelector
Type of OpenReadOnly constructor selector.
Definition: SharedMemoryUtils.hpp:46