IMP  2.3.1
The Integrative Modeling Platform
kernel/particle_index.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/particle_index.h
3  * \brief Various general useful functions for IMP.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_PARTICLE_INDEX_H
10 #define IMPKERNEL_PARTICLE_INDEX_H
11 
12 #include <IMP/kernel/kernel_config.h>
13 #include "base_types.h"
14 #include <boost/shared_ptr.hpp>
15 
16 IMPKERNEL_BEGIN_NAMESPACE
17 
18 class Particle;
19 class Decorator;
20 
21 /** Get the indexes from a list of particles.*/
22 IMPKERNELEXPORT ParticleIndexes get_indexes(const ParticlesTemp &ps);
23 
24 /** Get the particles from a list of indexes.*/
25 IMPKERNELEXPORT ParticlesTemp
26  get_particles(kernel::Model *m, const ParticleIndexes &ps);
27 
28 /** Get the indexes from a list of particle pairs. */
29 IMPKERNELEXPORT ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps);
30 
31 /** Take Decorator, Particle or ParticleIndex. */
32 class IMPKERNELEXPORT ParticleIndexAdaptor
33 #ifndef SWIG
34  // suppress swig warning that doesn't make sense and I can't make go away
35  : public ParticleIndex,
37 #endif
38  {
39  public:
43 #if !defined(SWIG) && !defined(IMP_DOXYGEN) && !defined(IMP_SWIG_WRAPPER)
46 #endif
47 };
48 
49 /** Take Decorator, Particle or ParticleIndex. */
50 class IMPKERNELEXPORT ParticleIndexesAdaptor : public base::InputAdaptor {
51  boost::shared_ptr<ParticleIndexes> tmp_;
52  const ParticleIndexes *val_;
53 
54  public:
55 #if !defined(SWIG)
56  template <class PS>
57  ParticleIndexesAdaptor(const PS &ps)
58  : tmp_(new ParticleIndexes(ps.size())), val_(tmp_.get()) {
59  for (unsigned int i = 0; i < ps.size(); ++i) {
60  (*tmp_)[i] = ps[i].get_particle_index();
61  }
62  }
64 #endif
67  : tmp_(new ParticleIndexes(pi)), val_(tmp_.get()) {}
68  ParticleIndexesAdaptor() : tmp_(new ParticleIndexes()), val_(tmp_.get()) {}
69 #ifndef SWIG
70  typedef ParticleIndexes::value_type value_type;
71  typedef ParticleIndexes::const_reference reference;
72  typedef ParticleIndexes::const_pointer pointer;
73  typedef ParticleIndexes::size_type size_type;
74  typedef ParticleIndexes::const_reference const_reference;
75  typedef ParticleIndexes::const_pointer const_pointer;
76  operator const ParticleIndexes &() const { return *val_; }
77  ParticleIndex operator[](unsigned int i) const { return (*val_)[i]; }
78  unsigned int size() const { return val_->size(); }
79  typedef ParticleIndexes::const_iterator const_iterator;
80  typedef ParticleIndexes::const_iterator iterator;
81  const_iterator begin() const { return val_->begin(); }
82  const_iterator end() const { return val_->end(); }
83 #endif
84 };
85 
86 /** Take ParticlePairs or ParticleIndexPairs. */
87 class IMPKERNELEXPORT ParticleIndexPairsAdaptor
88 #ifndef SWIG
89  // suppress swig warning that doesn't make sense and I can't make go away
90  : public ParticleIndexPairs,
92 #endif
93  {
94  public:
95 #if !defined(SWIG)
96  template <class PS>
97  ParticleIndexPairsAdaptor(const PS &ps) {
98  resize(ps.size());
99  for (unsigned int i = 0; i < ps.size(); ++i) {
100  operator[](i) = ParticleIndexPair(ps[i][0].get_particle_index(),
101  ps[i][1].get_particle_index());
102  }
103  }
104 #endif
107  : ParticleIndexPairs(pi) {}
109 };
110 
111 IMPKERNEL_END_NAMESPACE
112 
113 #endif /* IMPKERNEL_PARTICLE_INDEX_H */
IMP::kernel::ParticleIndexes ParticleIndexes
ParticlesTemp get_particles(kernel::Model *m, const ParticleIndexes &ps)
Basic types used by IMP.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
A class to store an fixed array of same-typed values.
Definition: Array.h:33
IMP::base::Vector< ParticleIndexPair > ParticleIndexPairs
IMP::kernel::Model Model
IMP::base::Vector< ParticlePair > ParticlePairsTemp
Class to handle individual model particles.
base::Index< ParticleIndexTag > ParticleIndex
IMP::kernel::Particle Particle
IMP::kernel::Decorator Decorator
ParticleIndexPairs get_indexes(const ParticlePairsTemp &ps)