IMP  2.1.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-2013 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 an demostration.
27 
28  The source code is as follows:
29  \include ExampleTemplateClass.h
30 */
31 template <unsigned int D> class ExampleTemplateClassD {
33 
34  public:
36  /** Since it is a simple object, there is no reason to provide
37  methods to change the data.
38  */
40  const IMP::algebra::VectorD<D> &b) {
41  eps_[0] = a;
42  eps_[1] = b;
43  }
44  //! Get one of the endpoints
45  const IMP::algebra::VectorD<D> &get_point(unsigned int i) const {
46  IMP_USAGE_CHECK(i < 2, "The endpoint index can only be 0 or 1");
47  return eps_[i];
48  }
49 
50  IMP_SHOWABLE_INLINE(ExampleTemplateClassD, out << eps_[0] << " " << eps_[1];);
51 };
52 
53 typedef ExampleTemplateClassD<3> ExampleTemplateClass3D;
54 typedef base::Vector<ExampleTemplateClassD<3> > ExampleTemplateClass3Ds;
55 
56 IMPEXAMPLE_END_NAMESPACE
57 
58 #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.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A Cartesian vector in D-dimensions.
Definition: VectorD.h:48
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)
Import IMP/kernel/utility.h in the namespace.