IMP logo
IMP Reference Guide  2.19.0
The Integrative Modeling Platform
ExampleTemplateClass.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/ExampleTemplateClass.h
3  * \brief Show how to manage a template class with Python.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H
10 #define IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H
11 
12 #include <IMP/example/example_config.h>
13 
14 #include <IMP/utility.h>
15 #include <IMP/algebra/VectorD.h>
16 
17 IMPEXAMPLE_BEGIN_NAMESPACE
18 
19 //! A line segment templated on the dimension.
20 /** Like the underlying
21  algebra::VectorD data, is not initialized when the default
22  constructor is used. Since it is a small class, it is designed to
23  be allocated on the stack and to be passed by value (or
24  const &).
25 
26  The class should be named SegmentD, but it is a demonstration.
27 
28  The source code is as follows:
29  \include ExampleTemplateClass.h
30 */
31 template <unsigned int D>
34 
35  public:
37  /** Since it is a simple object, there is no reason to provide
38  methods to change the data.
39  */
41  const IMP::algebra::VectorD<D> &b) {
42  eps_[0] = a;
43  eps_[1] = b;
44  }
45  //! Get one of the endpoints
46  const IMP::algebra::VectorD<D> &get_point(unsigned int i) const {
47  IMP_USAGE_CHECK(i < 2, "The endpoint index can only be 0 or 1");
48  return eps_[i];
49  }
50 
51  IMP_SHOWABLE_INLINE(ExampleTemplateClassD, out << eps_[0] << " " << eps_[1];);
52 };
53 
54 typedef ExampleTemplateClassD<3> ExampleTemplateClass3D;
55 typedef Vector<ExampleTemplateClassD<3> > ExampleTemplateClass3Ds;
56 
57 IMPEXAMPLE_END_NAMESPACE
58 
59 #endif /* IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H */
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
A line segment templated on the dimension.
A more IMP-like version of the std::vector.
Definition: Vector.h:42
A Cartesian vector in D-dimensions.
Definition: VectorD.h:56
const IMP::algebra::VectorD< D > & get_point(unsigned int i) const
Get one of the endpoints.
Simple D vector class.
ExampleTemplateClassD(const IMP::algebra::VectorD< D > &a, const IMP::algebra::VectorD< D > &b)
For backwards compatibility.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168