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
PDBTemplateBase.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 TEMPLATE_BASE_H
20 #define TEMPLATE_BASE_H
21 
22 namespace pdb {
23 
24 template <class ObjType>
25 int16_t getTypeID();
26 
27 // Templates present a bit of a problem for the whole v-table fixing framework. The issue
28 // is that v-table fixing is done via class name, but every time someone instantiates a
29 // template, they get a new class name. It is not feasible to have someone re-register all
30 // of those classes.
31 //
32 // Our solution is to store the type code of the template argument within the template class
33 // itself. Then, we have a couple of methods that use this type code to obtain the correct
34 // deleter and correct deep copy operation of objects of type ObjType. These operations can
35 // be used to correctly delete/copy objects in the tamplete.
36 
38 
39 private:
40  // a number greater than zero indicates a type code associated with a pdb :: Object
41  // a number less than zero indicates a non-pdb :: Object for whom we know the size
42  // a number equal to zero indicates an error; we have no idea as to the type
43  int32_t info;
44 
45 public:
47 
49 
50  // set up the type
51  template <class ObjType>
52  void setup();
53 
54  // set the info value explicitly
55  void set(int32_t toMe);
56 
57  // this runs the destructor associated with this type, on the object at deletMe
58  void deleteConstituentObject(void* deleteMe) const;
59 
60  // do a placement new at target, and then copy source over
61  void setUpAndCopyFromConstituentObject(void* target, void* source) const;
62 
63  // this returns the size (in bytes) of the object pointed to by forMe... note that
64  // in general, the implementation of this will NOT look at the object pointed to by
65  // forMe, unless the object is of type pdb :: Array, since pdb :: Array is the *only*
66  // variable-sized type
67  size_t getSizeOfConstituentObject(void* forMe) const;
68 
69  // correctly set the vTable pointer of the object pointed to by forMe
70  void setVTablePtr(void* forMe) const;
71 
72  // returns true if the type indicated by info is descended from pdb :: Object
73  bool descendsFromObject() const;
74 
75  // returns the type code
76  int16_t getTypeCode() const;
77 
78  // returns the exact value of field info
79  int32_t getExactTypeInfoValue() const;
80 };
81 }
82 
83 #include "PDBTemplateBase.cc"
84 
85 #endif
size_t getSizeOfConstituentObject(void *forMe) const
void deleteConstituentObject(void *deleteMe) const
void set(int32_t toMe)
int32_t getExactTypeInfoValue() const
void setVTablePtr(void *forMe) const
int16_t getTypeID()
int16_t getTypeCode() const
void setUpAndCopyFromConstituentObject(void *target, void *source) const
PDBTemplateBase & operator=(const PDBTemplateBase &toMe)
bool descendsFromObject() const