IMP  2.1.0
The Integrative Modeling Platform
ExampleObject.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/ExampleObject.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_OBJECT_H
9 #define IMPEXAMPLE_EXAMPLE_OBJECT_H
10 
11 #include <IMP/example/example_config.h>
12 
13 #include <IMP/base/Object.h>
14 #include <IMP/base/object_macros.h>
15 #include <IMP/base/types.h>
16 #include <IMP/base/Pointer.h>
17 #include <vector>
18 
19 IMPEXAMPLE_BEGIN_NAMESPACE
20 
21 //! An example simple object which is reference counted.
22 /** Only IMP::Pointer objects should be used to store pointers to
23  instances of these objects.
24 
25  The source code is as follows:
26  \include ExampleObject.h
27  \include ExampleObject.cpp
28  */
29 class IMPEXAMPLEEXPORT ExampleObject : public base::Object {
30  Floats data_;
31 
32  public:
33  ExampleObject(const Floats &data);
34 
35  double get_data(unsigned int i) const {
36  IMP_USAGE_CHECK(i < data_.size(), "Index " << i << " out of range.");
37  return data_[i];
38  }
39 
40  /* Make sure that it can't be allocated on the stack
41  The macro defines an empty destructor. In general,
42  you want destructors to be empty since they are hard
43  to maintain.
44  */
46 };
47 
51 
52 IMPEXAMPLE_END_NAMESPACE
53 
54 #endif /* IMPEXAMPLE_EXAMPLE_OBJECT_H */
Basic types used by IMP.
A nullptr-initialized pointer to an IMP Object.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
An example simple object which is reference counted.
Definition: ExampleObject.h:29
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Common base class for heavy weight IMP objects.
Various general useful macros for IMP.
A shared base class to help in debugging and things.