SharedMemory.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // SharedMemory.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/SharedMemory.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Processes
  8. // Module: SharedMemory
  9. //
  10. // Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/SharedMemory.h"
  16. #include "Poco/Exception.h"
  17. #if defined(POCO_NO_SHAREDMEMORY)
  18. #include "SharedMemory_DUMMY.cpp"
  19. #elif defined(POCO_OS_FAMILY_WINDOWS)
  20. #include "SharedMemory_WIN32.cpp"
  21. #elif defined(POCO_OS_FAMILY_UNIX)
  22. #include "SharedMemory_POSIX.cpp"
  23. #else
  24. #include "SharedMemory_DUMMY.cpp"
  25. #endif
  26. namespace Poco {
  27. SharedMemory::SharedMemory():
  28. _pImpl(0)
  29. {
  30. }
  31. SharedMemory::SharedMemory(const std::string& name, std::size_t size, AccessMode mode, const void* addrHint, bool server):
  32. _pImpl(new SharedMemoryImpl(name, size, mode, addrHint, server))
  33. {
  34. }
  35. SharedMemory::SharedMemory(const Poco::File& file, AccessMode mode, const void* addrHint):
  36. _pImpl(new SharedMemoryImpl(file, mode, addrHint))
  37. {
  38. }
  39. SharedMemory::SharedMemory(const SharedMemory& other):
  40. _pImpl(other._pImpl)
  41. {
  42. if (_pImpl)
  43. _pImpl->duplicate();
  44. }
  45. SharedMemory::~SharedMemory()
  46. {
  47. if (_pImpl)
  48. _pImpl->release();
  49. }
  50. SharedMemory& SharedMemory::operator = (const SharedMemory& other)
  51. {
  52. SharedMemory tmp(other);
  53. swap(tmp);
  54. return *this;
  55. }
  56. char* SharedMemory::begin() const
  57. {
  58. if (_pImpl)
  59. return _pImpl->begin();
  60. else
  61. return 0;
  62. }
  63. char* SharedMemory::end() const
  64. {
  65. if (_pImpl)
  66. return _pImpl->end();
  67. else
  68. return 0;
  69. }
  70. } // namespace Poco