中间件底层,websocket

SfNew.hpp 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //******************************************************************************
  2. // RCF - Remote Call Framework
  3. //
  4. // Copyright (c) 2005 - 2020, Delta V Software. All rights reserved.
  5. // http://www.deltavsoft.com
  6. //
  7. // RCF is distributed under dual licenses - closed source or GPL.
  8. // Consult your particular license for conditions of use.
  9. //
  10. // If you have not purchased a commercial license, you are using RCF
  11. // under GPL terms.
  12. //
  13. // Version: 3.2
  14. // Contact: support <at> deltavsoft.com
  15. //
  16. //******************************************************************************
  17. #ifndef INCLUDE_SF_SFNEW_HPP
  18. #define INCLUDE_SF_SFNEW_HPP
  19. #include <typeinfo>
  20. #include <RCF/Tools.hpp>
  21. #include <RCF/Exception.hpp>
  22. #include <RCF/TypeTraits.hpp>
  23. namespace SF {
  24. class Archive;
  25. template<typename T, typename R>
  26. R sfNewImpl(T*, R*, Archive &, RCF::TrueType *)
  27. {
  28. RCF::Exception e(RCF::RcfError_SfNoCtor);
  29. RCF_THROW(e);
  30. return NULL;
  31. }
  32. template<typename T, typename R>
  33. R sfNewImpl(T*, R*, Archive &, RCF::FalseType *)
  34. {
  35. return new T;
  36. }
  37. template<typename T, typename R>
  38. R sfNew(T*t, R*r, Archive &ar)
  39. {
  40. typedef typename std::is_abstract<T>::type type;
  41. return sfNewImpl(t, r, ar, (type *) NULL);
  42. }
  43. template<typename T, unsigned int N, typename R>
  44. R sfNew(T (*)[N], R*, Archive &)
  45. {
  46. RCF::Exception e(RCF::RcfError_SfNoCtor);
  47. RCF_THROW(e);
  48. return NULL;
  49. }
  50. // SF_CTOR
  51. #define SF_CTOR(type, ctor) \
  52. inline type *sfNew(type*, type **, SF::Archive &) \
  53. { \
  54. return new ctor; \
  55. }
  56. // SF_CUSTOM_CTOR
  57. #define SF_CUSTOM_CTOR(type, func) \
  58. inline type *sfNew(type*, type **, SF::Archive & ar) \
  59. { \
  60. type *pt = NULL; \
  61. func(ar, pt); \
  62. return pt; \
  63. }
  64. // SF_NO_CTOR
  65. #define SF_NO_CTOR(type) \
  66. inline type *sfNew(type*, type **, SF::Archive &) \
  67. { \
  68. RCF::Exception e(RCF::RcfError_SfNoCtor); \
  69. RCF_THROW(e); \
  70. return NULL; \
  71. }
  72. // SF_NO_CTOR_T1
  73. #define SF_NO_CTOR_T1(type) \
  74. template<typename T> \
  75. inline type<T> *sfNew(type<T>*, type<T> **, SF::Archive &) \
  76. { \
  77. RCF::Exception e(RCF::RcfError_SfNoCtor); \
  78. RCF_THROW(e); \
  79. return NULL; \
  80. }
  81. // SF_NO_CTOR_T2
  82. #define SF_NO_CTOR_T2(type) \
  83. template<typename T, typename U> \
  84. inline type<T,U> *sfNew(type<T,U>*, type<T,U> **, SF::Archive &) \
  85. { \
  86. RCF::Exception e(RCF::RcfError_SfNoCtor); \
  87. RCF_THROW(e); \
  88. return NULL; \
  89. }
  90. } // namespace SF
  91. #endif // ! INCLUDE_SF_SFNEW_HPP