IMP  2.0.0
The Integrative Modeling Platform
ExampleRefCounted.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/ExampleRefCounted.h
3  * \brief An example showing how to make a simple ref counted object
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPEXAMPLE_EXAMPLE_REF_COUNTED_H
9 #define IMPEXAMPLE_EXAMPLE_REF_COUNTED_H
10 
11 #include <IMP/example/example_config.h>
12 
13 #include <IMP/RefCounted.h>
14 #include <IMP/macros.h>
15 #include <IMP/Object.h>
16 #include <IMP/Pointer.h>
17 #include <IMP/WeakPointer.h>
18 #include <vector>
19 
20 IMPEXAMPLE_BEGIN_NAMESPACE
21 
22 //! An example simple object which is reference counted.
23 /** Only IMP::Pointer objects should be used to store pointers to
24  instances of these objects.
25 
26  The source code is as follows:
27  \include ExampleRefCounted.h
28  \include ExampleRefCounted.cpp
29  */
30 class IMPEXAMPLEEXPORT ExampleRefCounted: public base::RefCounted
31 {
32  Floats data_;
33 public:
34  ExampleRefCounted(const Floats &data);
35 
36  double get_data(unsigned int i) const {
37  IMP_USAGE_CHECK(i < data_.size(), "Index " << i
38  << " out of range.");
39  return data_[i];
40  }
41 
42  IMP_SHOWABLE_INLINE(ExampleRefCounted, out << data_.size());
43 
44  /* Make sure that it can't be allocated on the stack
45  The macro defines an empty destructor. In general,
46  you want destructors to be empty since they are hard
47  to maintain.
48  */
50 };
51 
54 
55 IMPEXAMPLE_END_NAMESPACE
56 
57 #endif /* IMPEXAMPLE_EXAMPLE_REF_COUNTED_H */