1 #ifndef LIBGEODECOMP_GEOMETRY_STREAK_H
2 #define LIBGEODECOMP_GEOMETRY_STREAK_H
3 
4 #include <libgeodecomp/config.h>
5 #include <libgeodecomp/geometry/coord.h>
6 
7 namespace LibGeoDecomp {
8 
9 /**
10  * A single run-lenght coded fragment of the StreakCollection. In the
11  * 2D case, it begins at origin (x, y) and runs until (endX, y). endX
12  * points just one past the last contained coordinate. It can be
13  * tagged as follows:
14  */
15 template<int DIM>
16 class Streak
17 {
18 public:
19     friend class Serialization;
20     friend class Typemaps;
21 
22     inline explicit Streak(
23         const Coord<DIM>& origin = Coord<DIM>(),
24         int endX = 0) :
origin(origin)25         origin(origin),
26         endX(endX)
27     {}
28 
end()29     Coord<DIM> end() const
30     {
31         Coord<DIM> ret = origin;
32         ret.x() = endX;
33         return ret;
34     }
35 
36     bool operator==(const Streak& other) const
37     {
38         return
39             (origin == other.origin) &&
40             (endX == other.endX);
41     }
42 
length()43     int length() const
44     {
45         return endX - origin.x();
46     }
47 
48     Coord<DIM> origin;
49     int endX;
50 };
51 
52 /**
53  * The MPI typemap generator need to find out for which template
54  * parameter values it should generate typemaps. It does so by
55  * scanning all class members. Therefore this dummy class forces the
56  * typemap generator to create MPI datatypes for Streaks with the
57  * dimensions as specified below.
58  */
59 class StreakMPIDatatypeHelper
60 {
61     friend class Typemaps;
62     Streak<1> a;
63     Streak<2> b;
64     Streak<3> c;
65 };
66 
67 template<typename _CharT, typename _Traits, int _Dim>
68 std::basic_ostream<_CharT, _Traits>&
69 operator<<(std::basic_ostream<_CharT, _Traits>& __os,
70            const Streak<_Dim>& streak)
71 {
72     __os << "(origin: " << streak.origin << ", endX: " << streak.endX << ")";
73     return __os;
74 }
75 
76 }
77 
78 #endif
79