IMP logo
IMP Reference Guide  2.6.1
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-2016 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/Object.h>
14 #include <IMP/object_macros.h>
15 #include <IMP/types.h>
16 #include <IMP/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 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 
50 
51 IMPEXAMPLE_END_NAMESPACE
52 
53 #endif /* IMPEXAMPLE_EXAMPLE_OBJECT_H */
Various general useful macros for IMP.
Basic types used by IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
An example simple object which is reference counted.
Definition: ExampleObject.h:29
Common base class for heavy weight IMP objects.
Definition: Object.h:106
A nullptr-initialized pointer to an IMP Object.
A shared base class to help in debugging and things.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168