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