vSMC
vSMC: Scalable Monte Carlo
single_particle.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/core/single_particle.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_CORE_SINGLE_PARTICLE_HPP
33 #define VSMC_CORE_SINGLE_PARTICLE_HPP
34 
35 #include <vsmc/internal/common.hpp>
36 
37 namespace vsmc {
38 
41 template <typename T>
43 {
44  public :
45 
48  id_(id), particle_ptr_(particle_ptr) {}
49 
50  typename Particle<T>::size_type id () const {return id_;}
51 
52  const Particle<T> &particle () const {return *particle_ptr_;}
53 
54  const Particle<T> *particle_ptr () const {return particle_ptr_;}
55 
56  typename Particle<T>::rng_type &rng () const
57  {return particle_ptr_->rng(id_);}
58 
59  protected :
60 
61  Particle<T> &mutable_particle () const {return *particle_ptr_;}
62 
63  Particle<T> *mutable_particle_ptr () const {return particle_ptr_;}
64 
65  private :
66 
67  typename Particle<T>::size_type id_;
68  Particle<T> *particle_ptr_;
69 }; // class SingleParticleBase
70 
73 template <typename T>
75 {
76  public :
77 
79  const Particle<T> *particle_ptr) :
80  id_(id), particle_ptr_(particle_ptr) {}
81 
82  typename Particle<T>::size_type id () const {return id_;}
83 
84  const Particle<T> &particle () const {return *particle_ptr_;}
85 
86  const Particle<T> *particle_ptr () const {return particle_ptr_;}
87 
88  private :
89 
90  typename Particle<T>::size_type id_;
91  const Particle<T> *particle_ptr_;
92 }; // class ConstSingleParticleBase
93 
115 template <typename T>
118 {
119  typedef typename traits::SingleParticleBaseTypeTrait<T>::type base;
120 
121  public :
122 
124  Particle<T> *particle_ptr) : base(id, particle_ptr) {}
125 }; // class SingleParticle
126 
129 template <typename T>
132 {
134 
135  public :
136 
138  const Particle<T> *particle_ptr) : base(id, particle_ptr) {}
139 }; // class ConstSingleParticle
140 
141 } // namespace vsmc
142 
143 #endif // VSMC_CORE_SINGLE_PARTICLE_HPP
const Particle< T > * particle_ptr() const
Definition: adapter.hpp:37
SingleParticle base class trait.
Definition: traits.hpp:157
Particle class representing the whole particle set.
Definition: particle.hpp:48
Particle< T > * mutable_particle_ptr() const
SingleParticle(typename Particle< T >::size_type id, Particle< T > *particle_ptr)
Particle< T >::size_type id() const
SingleParticleBase(typename Particle< T >::size_type id, Particle< T > *particle_ptr)
Particle< T > & mutable_particle() const
ConstSingleParticle base class trait.
Definition: traits.hpp:162
rng_set_type::rng_type rng_type
Definition: particle.hpp:57
internal::SingleParticleBaseTypeDispatch< T, value >::type type
Definition: traits.hpp:157
A const variant to SingleParticle.
internal::ConstSingleParticleBaseTypeDispatch< T, value >::type type
Definition: traits.hpp:162
ConstSingleParticle(typename Particle< T >::size_type id, const Particle< T > *particle_ptr)
Particle< T >::size_type id() const
A thin wrapper over a complete Particle.
traits::SizeTypeTrait< T >::type size_type
Definition: particle.hpp:52
const Particle< T > & particle() const
const Particle< T > * particle_ptr() const
A thin wrapper over a complete Particle.
ConstSingleParticleBase(typename Particle< T >::size_type id, const Particle< T > *particle_ptr)
Particle< T >::rng_type & rng() const
const Particle< T > & particle() const
A const variant to SingleParticle.