-
Notifications
You must be signed in to change notification settings - Fork 15
/
Region.hpp
91 lines (75 loc) · 2.26 KB
/
Region.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef REGION_HPP
#define REGION_HPP
#include <ostream>
#if defined(HAVE_TR1_FUNCTIONAL)
#include <tr1/functional>
#elif defined(HAVE_STD_HASH)
#include <functional>
#elif defined(HAVE_BOOST_FUNCTIONAL_HASH_HPP)
#include <boost/functional/hash.hpp>
#endif
#include <sstream>
#include "ParticleSimulationStructure.hpp"
#include "Box.hpp"
template<typename Ttraits_>
class Region: public ParticleSimulationStructure<Ttraits_>
{
public:
typedef ParticleSimulationStructure<Ttraits_> base_type;
typedef typename base_type::identifier_type identifier_type;
public:
virtual ~Region() {}
Region(identifier_type const& id): base_type(id) {}
};
template<typename Ttraits_, typename Tshape_>
class BasicRegionImpl: public Region<Ttraits_>
{
public:
typedef Region<Ttraits_> base_type;
typedef Tshape_ shape_type;
typedef typename base_type::identifier_type identifier_type;
typedef typename base_type::length_type length_type;
typedef typename base_type::position_type position_type;
public:
virtual ~BasicRegionImpl() {}
shape_type& shape()
{
return shape_;
}
shape_type const& shape() const
{
return shape_;
}
virtual bool operator==(Structure<typename Ttraits_::world_type::traits_type> const& rhs) const
{
BasicRegionImpl const* _rhs(dynamic_cast<BasicRegionImpl const*>(&rhs));
return _rhs && base_type::id_ == rhs.id() && shape_ == _rhs->shape();
}
virtual std::size_t hash() const
{
#if defined(HAVE_TR1_FUNCTIONAL)
using std::tr1::hash;
#elif defined(HAVE_STD_HASH)
using std::hash;
#elif defined(HAVE_BOOST_FUNCTIONAL_HASH_HPP)
using boost::hash;
#endif
return hash<identifier_type>()(base_type::id_) ^ hash<shape_type>()(shape());
}
virtual std::string as_string() const
{
std::ostringstream out;
out << "Region(" << base_type::id_ << ":" << shape() << ")";
return out.str();
}
std::pair<position_type, length_type>
projected_point(position_type const& pos) const
{
return ::projected_point(shape(), pos);
}
BasicRegionImpl(identifier_type const& id, shape_type const& shape)
: base_type(id), shape_(shape) {}
protected:
shape_type shape_;
};
#endif /* REGION_HPP */