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