IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
base_utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/base_utility.h
3  * \brief Various general useful functions for IMP.
4  *
5  * Copyright 2007-2018 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_BASE_UTILITY_H
10 #define IMPKERNEL_BASE_UTILITY_H
11 
12 #include <IMP/kernel_config.h>
13 #include <boost/utility.hpp>
14 #include <cmath>
15 #include "base_macros.h"
16 #include <IMP/Vector.h>
17 #include <IMP/math.h>
18 
19 IMPKERNEL_BEGIN_NAMESPACE
20 
21 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
22 template <class T>
23 inline T square(T t) IMP_NO_SIDEEFFECTS;
24 template <class T>
25 inline T cube(T t) IMP_NO_SIDEEFFECTS;
26 
27 //! Compute the square of a number
28 template <class T>
29 inline T square(T t) {
30  return t * t;
31 }
32 
33 //! Compute the cube of a number
34 template <class T>
35 inline T cube(T t) {
36  return t * t * t;
37 }
38 
39 template <class T>
40 inline bool is_nan(const T &a) {
41  return isnan(a);
42 }
43 
44 //! A version of std::for_each which works with ranges
45 /** This is needed to apply the functor to a range which is a temporary
46  object, since you can't call both begin and end on it.
47  */
48 template <class Range, class Functor>
49 inline void for_each(const Range &r, const Functor &f) {
50  std::for_each(r.begin(), r.end(), f);
51 }
52 
53 template <class T>
54 inline int compare(const T &a, const T &b) {
55  return a.compare(b);
56 }
57 
58 //! Convert between different types of lists.
59 template <class Out, class In>
60 inline Out get_as(const In &in) {
61  return Out(in.begin(), in.end());
62 }
63 #endif
64 
65 //! Return a unique name produced from the string.
66 /** This is done by replacing %1% with a sequential number.*/
67 IMPKERNELEXPORT std::string get_unique_name(std::string templ);
68 
69 IMPKERNEL_END_NAMESPACE
70 
71 #endif /* IMPKERNEL_BASE_UTILITY_H */
Declare an efficient stl-compatible map.
std::string get_unique_name(std::string templ)
Return a unique name produced from the string.
#define IMP_NO_SIDEEFFECTS
Use this to label a function with no side effects.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Definition: VectorD.h:179
A class for storing lists of IMP items.
bool isnan(const T &a)
Return true if a number is NaN.
Definition: math.h:24
Various general useful macros for IMP.