lichao
2021-04-25 1fbfef2a51db4a3bac9d8a5b87af94a40a913b7a
src/bh_util.h
@@ -143,6 +143,31 @@
   }
};
template <class T, class Tag>
class StaticDataRef
{
   typedef T *Ptr;
   static inline Ptr &ptr()
   {
      static Ptr sp(nullptr);
      return sp;
   }
protected:
   static inline T &GetData()
   {
      if (!ptr()) { throw std::string("Must set ShmMsg shm before use!"); }
      return *ptr();
   }
public:
   static bool SetData(T &t)
   {
      auto Bind = [&]() { ptr() = &t; return true; };
      return ptr() ? false : Bind();
   }
};
// macro helper
#define JOIN_IMPL(a, b) a##b
#define JOIN(a, b) JOIN_IMPL(a, b)