IMP  2.0.1
The Integrative Modeling Platform
kernel/RestraintSet.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/RestraintSet.h
3  * \brief Used to hold a set of related restraints.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_RESTRAINT_SET_H
10 #define IMPKERNEL_RESTRAINT_SET_H
11 
12 #include <IMP/kernel/kernel_config.h>
13 #include "declare_RestraintSet.h"
14 
15 IMPKERNEL_BEGIN_NAMESPACE
16 
17 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
18 namespace {
19  template <class It>
20  void get_restraints_internal(It b, It e,
21  RestraintsTemp &ret) {
22  for (It c=b; c!= e; ++c) {
23  Restraint *cur= *c;
24  RestraintSet *rs=dynamic_cast<RestraintSet*>(cur);
25  if (rs) {
26  get_restraints_internal(rs->restraints_begin(),
27  rs->restraints_end(), ret);
28  } else {
29  ret.push_back(cur);
30  }
31  }
32  }
33 }
34 #endif
35 
36 template <class It>
37 inline RestraintsTemp get_restraints(It b, It e) {
38  RestraintsTemp ret;
39  get_restraints_internal(b,e, ret);
40  std::sort(ret.begin(), ret.end());
41  ret.erase(std::unique(ret.begin(), ret.end()), ret.end());
42  return ret;
43 }
44 
45 IMPKERNEL_END_NAMESPACE
46 
47 #endif /* IMPKERNEL_RESTRAINT_SET_H */