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