From 1fbfef2a51db4a3bac9d8a5b87af94a40a913b7a Mon Sep 17 00:00:00 2001
From: lichao <lichao@aiotlink.com>
Date: 星期日, 25 四月 2021 15:33:40 +0800
Subject: [PATCH] change mqid from uuid to uint64.

---
 src/shm.h |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/shm.h b/src/shm.h
index 0e834c3..a70afcb 100644
--- a/src/shm.h
+++ b/src/shm.h
@@ -25,7 +25,6 @@
 #include <boost/interprocess/sync/interprocess_mutex.hpp>
 #include <boost/interprocess/sync/scoped_lock.hpp>
 #include <boost/noncopyable.hpp>
-#include <boost/uuid/uuid.hpp>
 #include <chrono>
 #include <thread>
 
@@ -103,7 +102,16 @@
 	~SharedMemory();
 	std::string name() const { return name_; }
 	bool Remove() { return Remove(name()); }
-
+	template <class T, class... Params>
+	T *FindOrCreate(const std::string &name, Params &&...params)
+	{
+		return find_or_construct<T>(name.c_str(), std::nothrow)(std::forward<decltype(params)>(params)...);
+	}
+	template <class T, class... Params>
+	T *Create(const std::string &name, Params &&...params)
+	{
+		return construct<T>(name.c_str(), std::nothrow)(std::forward<decltype(params)>(params)...);
+	}
 	void *Alloc(const size_t size) { return allocate(size, std::nothrow); }
 	void Dealloc(void *p)
 	{
@@ -113,7 +121,7 @@
 	void Dealloc(offset_ptr<T> ptr) { return Dealloc(ptr.get()); }
 
 	template <class T, class... Params>
-	T *New(Params const &...params) { return construct<T>(anonymous_instance, std::nothrow)(params...); }
+	T *New(Params &&...params) { return construct<T>(anonymous_instance, std::nothrow)(std::forward<decltype(params)>(params)...); }
 	template <class T>
 	void Delete(T *p)
 	{
@@ -157,7 +165,7 @@
 	ShmObject(ShmType &segment, const std::string &name, Params &&...t) :
 	    shm_(segment), name_(name)
 	{
-		pdata_ = shm_.find_or_construct<Data>(ObjName(name_).c_str(), std::nothrow)(t...);
+		pdata_ = shm_.Create<Data>(ObjName(name_), std::forward<decltype(t)>(t)...);
 		if (!IsOk()) {
 			throw("Error: Not enough memory, can not allocate \"" + name_ + "\"");
 		}

--
Gitblit v1.8.0