Talvos  0.1
SPIR-V interpreter and dynamic analysis framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Dim3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 the Talvos developers. All rights reserved.
2 //
3 // This file is distributed under a three-clause BSD license. For full license
4 // terms please see the LICENSE file distributed with this source code.
5 
8 
9 #ifndef TALVOS_DIM3_H
10 #define TALVOS_DIM3_H
11 
12 #include <cstdint>
13 #include <iosfwd>
14 
15 namespace talvos
16 {
17 
22 class Dim3
23 {
24 public:
26  union
27  {
28  struct
29  {
30  uint32_t X, Y, Z;
31  };
32  uint32_t Data[3];
33  };
34 
36  Dim3() : X(1), Y(1), Z(1) {}
37 
39  Dim3(uint32_t X, uint32_t Y, uint32_t Z) : X(X), Y(Y), Z(Z) {}
40 
42  Dim3(const uint32_t Data[3]) : X(Data[0]), Y(Data[1]), Z(Data[2]) {}
43 
45  Dim3 operator+(const Dim3 &D) const { return {X + D.X, Y + D.Y, Z + D.Z}; }
46 
48  Dim3 operator*(const Dim3 &D) const { return {X * D.X, Y * D.Y, Z * D.Z}; }
49 
51  Dim3 operator%(const Dim3 &D) const { return {X % D.X, Y % D.Y, Z % D.Z}; }
52 
54  bool operator==(const Dim3 &D) const
55  {
56  return X == D.X && Y == D.Y && Z == D.Z;
57  }
58 
60  uint32_t &operator[](unsigned i) { return Data[i]; }
61 
63  const uint32_t &operator[](unsigned i) const { return Data[i]; }
64 
67  friend std::ostream &operator<<(std::ostream &Stream, const Dim3 &D);
68 };
69 
70 } // namespace talvos
71 
72 #endif
Dim3(uint32_t X, uint32_t Y, uint32_t Z)
Construct a Dim3 from specific values.
Definition: Dim3.h:39
Dim3 operator%(const Dim3 &D) const
Returns the component-wise modulus of this Dim3 with D.
Definition: Dim3.h:51
uint32_t Y
Definition: Dim3.h:30
Dim3 operator+(const Dim3 &D) const
Returns the component-wise addition of this Dim3 with D.
Definition: Dim3.h:45
Dim3()
Construct a Dim3 with values (1,1,1).
Definition: Dim3.h:36
const uint32_t & operator[](unsigned i) const
Returns a const reference to the component at index i (i must be < 3).
Definition: Dim3.h:63
friend std::ostream & operator<<(std::ostream &Stream, const Dim3 &D)
Allow a Dim3 to be inserted into an output stream.
Definition: Dim3.cpp:16
bool operator==(const Dim3 &D) const
Returns true if this Dim3 is equal to D.
Definition: Dim3.h:54
uint32_t Z
Definition: Dim3.h:30
Dim3 operator*(const Dim3 &D) const
Returns the component-wise multiplication of this Dim3 with D.
Definition: Dim3.h:48
Class representing a 3-dimensional size or ID.
Definition: Dim3.h:22
uint32_t & operator[](unsigned i)
Returns a mutable reference to the component at index i (i must be < 3).
Definition: Dim3.h:60
uint32_t X
Definition: Dim3.h:30
uint32_t Data[3]
Definition: Dim3.h:32
Dim3(const uint32_t Data[3])
Construct a Dim3 from an array.
Definition: Dim3.h:42