Blender  V3.3
tuple.h
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #ifndef LIBMV_IMAGE_TUPLE_H
22 #define LIBMV_IMAGE_TUPLE_H
23 
24 #include <algorithm>
25 
26 namespace libmv {
27 
28 // A vector of elements with fixed length and deep copy semantics.
29 template <typename T, int N>
30 class Tuple {
31  public:
32  enum { SIZE = N };
33  Tuple() {}
34  Tuple(T initial_value) { Reset(initial_value); }
35 
36  template <typename D>
37  Tuple(D* values) {
38  Reset(values);
39  }
40 
41  template <typename D>
42  Tuple(const Tuple<D, N>& b) {
43  Reset(b);
44  }
45 
46  template <typename D>
48  Reset(b);
49  return *this;
50  }
51 
52  template <typename D>
53  void Reset(const Tuple<D, N>& b) {
54  Reset(b.Data());
55  }
56 
57  template <typename D>
58  void Reset(D* values) {
59  for (int i = 0; i < N; i++) {
60  data_[i] = T(values[i]);
61  }
62  }
63 
64  // Set all tuple values to the same thing.
65  void Reset(T value) {
66  for (int i = 0; i < N; i++) {
67  data_[i] = value;
68  }
69  }
70 
71  // Pointer to the first element.
72  T* Data() { return &data_[0]; }
73  const T* Data() const { return &data_[0]; }
74 
75  T& operator()(int i) { return data_[i]; }
76  const T& operator()(int i) const { return data_[i]; }
77 
78  bool operator==(const Tuple<T, N>& other) const {
79  for (int i = 0; i < N; ++i) {
80  if ((*this)(i) != other(i)) {
81  return false;
82  }
83  }
84  return true;
85  }
86  bool operator!=(const Tuple<T, N>& other) const { return !(*this == other); }
87 
88  private:
89  T data_[N];
90 };
91 
92 } // namespace libmv
93 
94 #endif // LIBMV_IMAGE_TUPLE_H
void Reset(T value)
Definition: tuple.h:65
T * Data()
Definition: tuple.h:72
bool operator==(const Tuple< T, N > &other) const
Definition: tuple.h:78
Tuple(T initial_value)
Definition: tuple.h:34
void Reset(const Tuple< D, N > &b)
Definition: tuple.h:53
const T & operator()(int i) const
Definition: tuple.h:76
bool operator!=(const Tuple< T, N > &other) const
Definition: tuple.h:86
T & operator()(int i)
Definition: tuple.h:75
void Reset(D *values)
Definition: tuple.h:58
Tuple & operator=(const Tuple< D, N > &b)
Definition: tuple.h:47
Tuple(D *values)
Definition: tuple.h:37
Tuple(const Tuple< D, N > &b)
Definition: tuple.h:42
const T * Data() const
Definition: tuple.h:73
#define N
#define T
static const pxr::TfToken b("b", pxr::TfToken::Immortal)