Skip to content

Commit 1f7d30f

Browse files
authored
♻️ ParticleSpaceRTreeImpl (#487)
* ✨ support particles() in RTreeImpl since the internal representation of RTree has been changed, the vector in an RTree becomes always valid. * ♻️ use throw_exception instead of ostringstream
1 parent d9dc03a commit 1f7d30f

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

ecell4/core/ParticleSpaceRTreeImpl.hpp

+6-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <ecell4/core/Real3.hpp>
88
#include <ecell4/core/Integer3.hpp>
99
#include <ecell4/core/PeriodicRTree.hpp>
10+
#include <ecell4/core/exceptions.hpp>
1011

1112
#ifdef WITH_HDF5
1213
#include <ecell4/core/ParticleSpaceHDF5Writer.hpp>
@@ -82,17 +83,7 @@ class ParticleSpaceRTreeImpl
8283

8384
const particle_container_type& particles() const override
8485
{
85-
// Since PeriodicRTree manages particles as their index, the container
86-
// can occasionally contains "already-erased" particles marked as
87-
// "overwritable", like a colony (P0447R1). Because of this, the raw
88-
// reference may contain an invalid particle that is already removed
89-
// from the space. It may invalidates subsequent operation.
90-
// To avoid confusion, this method throws an exception. This will
91-
// never be implemented, so it throws a `NotSupported`, not a
92-
// `NotImplemented`. Since the default implementation of `list_species()`
93-
// uses this function, it is overriden later.
94-
throw NotSupported("ParticleSpaceRTreeImpl does not support "
95-
"`particle_container_type const& particles()`");
86+
return rtree_.list_objects();
9687
}
9788

9889
// ParticleSpace has the default list_species implementation.
@@ -104,10 +95,8 @@ class ParticleSpaceRTreeImpl
10495
{
10596
if(!rtree_.has(pid))
10697
{
107-
std::ostringstream oss;
108-
oss << "ParticleSpaceRTreeImpl::get_particle: No such particle ("
109-
<< pid << ").";
110-
throw NotFound(oss.str());
98+
throw_exception<NotFound>("ParticleSpaceRTreeImpl::get_particle: "
99+
"No such particle (", pid, ").");
111100
}
112101
return rtree_.get(pid);
113102
}
@@ -143,10 +132,8 @@ class ParticleSpaceRTreeImpl
143132
{
144133
if(!rtree_.has(pid))
145134
{
146-
std::ostringstream oss;
147-
oss << "ParticleSpaceRTreeImpl::remove_particle: No such particle ("
148-
<< pid << ").";
149-
throw NotFound(oss.str());
135+
throw_exception<NotFound>("ParticleSpaceRTreeImpl::remove_particle:"
136+
" No such particle (", pid, ").");
150137
}
151138
const auto& p = rtree_.get(pid).second;
152139
particle_pool_[p.species_serial()].erase(pid);

0 commit comments

Comments
 (0)