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
RefCountedObject.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 REF_COUNTED_OBJECT_H
20 #define REF_COUNTED_OBJECT_H
21 
22 #include <cstddef>
23 #include <iostream>
24 #include <vector>
25 #include <algorithm>
26 #include <iterator>
27 #include <cstring>
28 
29 namespace pdb {
30 
31 // When an Object is stored in an allocator, we have to have a bit of meta-data
32 // associated with it. It is the job of the RefCountedObject class to manage
33 // this meta-data, along with the Object. Specifically, we need:
34 //
35 // (1) A count of the number of Handles that are currently pointing to the Object.
36 // When this count goes down to zero, then the object is unreachable and can
37 // be freed.
38 //
39 class Object;
40 class PDBTemplateBase;
41 
42 template <class ObjType>
43 class RefCountedObject {
44 
45 public:
46  // set the number of references to this object to a specific value
47  void setRefCount(unsigned toMe);
48 
49  // increment the reference count for the object by one
50  void incRefCount();
51 
52  // return the ref count
53  unsigned getRefCount();
54 
55  // decrement the ref count for the object by one. If the value of the
56  // reference count goes down to zero, the object is deleted using the
57  // PDBTemplateBased object
58  void decRefCount(PDBTemplateBase& typeInfo);
59 
60  // get a pointer to the object itself
61  ObjType* getObject() const;
62 
63 private:
64  // so that no one can create one
66 };
67 }
68 
69 #include "RefCountedObject.cc"
70 
71 #endif
void decRefCount(PDBTemplateBase &typeInfo)
ObjType * getObject() const
void setRefCount(unsigned toMe)