00001 /** 00002 * \file example/ExampleTemplateClass.h 00003 * \brief Show how to manage a template class with python. 00004 * 00005 * Copyright 2007-2010 IMP Inventors. All rights reserved. 00006 * 00007 */ 00008 00009 #ifndef IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H 00010 #define IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H 00011 00012 #include "example_config.h" 00013 00014 #include <IMP/utility.h> 00015 #include <IMP/algebra/VectorD.h> 00016 00017 IMPEXAMPLE_BEGIN_NAMESPACE 00018 00019 //! A line segment templated on the dimension. 00020 /** It inherits from IMP::InvalidDefault since it, like the underlying 00021 algebra::VectorD data, is not initialized when the default 00022 constructor is used. Since it is a small class, it is designed to 00023 be allocated on the stack and to be passed by value (or 00024 const &). 00025 00026 The class should be named SegmentD, but it is an example. 00027 00028 The following command indicates to doxygen to mark the class 00029 as being one whose members are left uninitialized by the 00030 default constructor: 00031 \ingroup uninitialized_default 00032 00033 The source code is as follows: 00034 \include ExampleTemplateClass.h 00035 */ 00036 template <unsigned int D> 00037 class ExampleTemplateClass 00038 { 00039 IMP::algebra::VectorD<D> eps_[2]; 00040 public: 00041 ExampleTemplateClass(){} 00042 /** Since it is a simple object, there is no reason to provide 00043 methods to change the data. 00044 */ 00045 ExampleTemplateClass(const IMP::algebra::VectorD<D> &a, 00046 const IMP::algebra::VectorD<D> &b){ 00047 eps_[0]= a; 00048 eps_[1]= b; 00049 } 00050 //! Get one of the endpoints 00051 const IMP::algebra::VectorD<D>& get_point(unsigned int i) const { 00052 IMP_USAGE_CHECK(i < 2, "The endpoint index can only be 0 or 1"); 00053 return eps_[i]; 00054 } 00055 }; 00056 00057 // Make it so the C++ operator<< can be used. The _D means that it is 00058 // is templated on the dimension. See the docs for other, related macros. 00059 IMP_OUTPUT_OPERATOR_D(ExampleTemplateClass); 00060 00061 IMPEXAMPLE_END_NAMESPACE 00062 00063 #endif /* IMPEXAMPLE_EXAMPLE_TEMPLATE_CLASS_H */