pvAccessCPP  7.1.6
destroyable.h
1 /* destroyable.h */
2 /*
3  * Copyright information and license terms for this software can be
4  * found in the file LICENSE that is included with the distribution
5  */
6 /**
7  * @author mse
8  */
9 #ifndef DESTROYABLE_H
10 #define DESTROYABLE_H
11 
12 #include <compilerDependencies.h>
13 
14 #include <pv/sharedPtr.h>
15 
16 #include <shareLib.h>
17 
18 namespace epics { namespace pvAccess {
19 
20 
21  /**
22  * @brief Instance declaring destroy method.
23  */
24  class Destroyable {
25  public:
26  POINTER_DEFINITIONS(Destroyable);
27  /**
28  * Destroy this instance.
29  */
30  virtual void destroy() {};
31 
32  protected:
33  virtual ~Destroyable() {}
34  public:
35 
36  /** for use with shared_ptr<> when wrapping
37  *
38  @code
39  shared_ptr<foo> inner(new foo),
40  outer(inner.get, Destroyable::cleaner(inner));
41  @endcode
42 
43  @warning Do not use this trick in combination with enable_shared_from_this
44  as it is _undefined_ whether the hidden weak_ptr will be the original
45  or wrapped reference.
46  */
47  class cleaner {
48  Destroyable::shared_pointer ptr;
49  public:
50  cleaner(const Destroyable::shared_pointer& ptr) :ptr(ptr) {}
51  void operator()(Destroyable*) {
52  Destroyable::shared_pointer P;
53  P.swap(ptr);
54  P->destroy();
55  }
56  };
57  };
58 
59 }}
60 namespace epics { namespace pvData {
61  typedef ::epics::pvAccess::Destroyable Destroyable EPICS_DEPRECATED;
62 }}
63 #endif /* DESTROYABLE_H */
virtual void destroy()
Destroy this instance.
Definition: destroyable.h:30
for use with shared_ptr<> when wrapping
Definition: destroyable.h:47