An example simple object which is reference counted.
Only IMP::Pointer objects should be used to store pointers to instances of these objects.
The source code is as follows:
#ifndef IMPEXAMPLE_EXAMPLE_REF_COUNTED_H
#define IMPEXAMPLE_EXAMPLE_REF_COUNTED_H
#include "example_config.h"
#include <vector>
IMPEXAMPLE_BEGIN_NAMESPACE
class IMPEXAMPLEEXPORT ExampleRefCounted: public base::RefCounted
{
Floats data_;
public:
ExampleRefCounted(const Floats &data);
double get_data(unsigned int i) const {
<< " out of range.");
return data_[i];
}
};
typedef base::Vector<Pointer<ExampleRefCounted> > ExampleRefCounteds;
typedef base::Vector<WeakPointer<ExampleRefCounted> > ExampleRefCountedsTemp;
IMPEXAMPLE_END_NAMESPACE
#endif
IMPEXAMPLE_BEGIN_NAMESPACE
ExampleRefCounted::ExampleRefCounted(const Floats &data ):
data_(data){
}
namespace {
#ifdef __clang__
#pragma clang diagnostic ignored "-Wunused-function"
#endif
void usage_example() {
Floats data(1000, -1);
IMP_NEW(ExampleRefCounted, rc, (data));
Pointer<ExampleRefCounted> rc_other= new ExampleRefCounted(data);
Pointer<ExampleRefCounted> rc2=rc;
rc=static_cast<ExampleRefCounted*>(nullptr);
std::cout << rc2->get_data(100);
}
}
IMPEXAMPLE_END_NAMESPACE