IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2026 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
17IMPEXAMPLE_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*/
31template <unsigned int D>
32class ExampleTemplateClassD {
34
35 public:
36 ExampleTemplateClassD() {}
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
54typedef ExampleTemplateClassD<3> ExampleTemplateClass3D;
55typedef Vector<ExampleTemplateClassD<3>> ExampleTemplateClass3Ds;
56
57IMPEXAMPLE_END_NAMESPACE
58
59#endif /* IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H */
Simple D vector class.
#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:38
A more IMP-like version of the std::vector.
Definition Vector.h:60
A line segment templated on the dimension.
const IMP::algebra::VectorD< D > & get_point(unsigned int i) const
Get one of the endpoints.
ExampleTemplateClassD(const IMP::algebra::VectorD< D > &a, const IMP::algebra::VectorD< D > &b)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Various general useful functions for IMP.