A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DeepCopy.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef ENABLE_DEEP_COPY
20 
21 // This defines the macro ENABLE_DEEP_COPY
22 //
23 // Any subclass of pdb :: Object that wishes to make proper use of the Object's
24 // deep copying facilities needs to have the macro ENABLE_DEEP_COPY somewhere in
25 // the public section of the class definition. Example:
26 //
27 // class Foo : public Objct {
28 //
29 // public:
30 //
31 // ENABLE_DEEP_COPY
32 //
33 // };
34 //
35 //
36 template <class ObjType>
37 void setUpAndCopyFromTemplate(void* target, void* source, const ObjType* dummy) {
38  new (target) ObjType();
39  *((ObjType*)target) = *((ObjType*)source);
40 }
41 
42 template <class ObjType>
43 size_t computeSize(ObjType* dummy) {
44  return sizeof(ObjType);
45 }
46 
47 template <class ObjType>
48 void deleter(void* deleteMe, ObjType* dummy) {
49  ((ObjType*)deleteMe)->~ObjType();
50 }
51 
52 #define ENABLE_DEEP_COPY \
53  void setUpAndCopyFrom(void* target, void* source) const override { \
54  setUpAndCopyFromTemplate(target, source, this); \
55  } \
56  \
57  void deleteObject(void* deleteMe) override { \
58  deleter(deleteMe, this); \
59  } \
60  \
61  size_t getSize(void* ofMe) override { \
62  return computeSize(this); \
63  }
64 
65 #endif
void setUpAndCopyFromTemplate(void *target, void *source, const ObjType *dummy)
Definition: DeepCopy.h:37
void deleter(void *deleteMe, ObjType *dummy)
Definition: DeepCopy.h:48
size_t computeSize(ObjType *dummy)
Definition: DeepCopy.h:43