PSCF v1.1
IntVec.h
1#ifndef PSCF_INT_VEC_H
2#define PSCF_INT_VEC_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Vec.h"
12#include <iostream>
13#include <util/global.h>
14
15namespace Pscf
16{
17
25 template <int D, typename T = int>
26 class IntVec : public Vec<D, T>
27 {
28
29 public:
30
32
33
38 : Vec<D, T>()
39 {}
40
47 : Vec<D, T>(v)
48 {}
49
55 IntVec<D, T>(T const * v)
56 : Vec<D, T>(v)
57 {}
58
64 explicit IntVec<D, T>(T s)
65 : Vec<D, T>(s)
66 {}
67
69 static const int Width = 10;
70
71 };
72
73 // Friend functions and operators
74
84 template <int D, typename T>
85 std::istream& operator >> (std::istream& in, IntVec<D, T> &vector)
86 {
87 for (int i = 0; i < D; ++i) {
88 in >> vector[i];
89 }
90 return in;
91 }
92
103 template <int D, typename T>
104 std::ostream& operator << (std::ostream& out, const IntVec<D, T> &vector)
105 {
106 for (int i = 0; i < D; ++i) {
107 out.width(IntVec<D, T>::Width);
108 out << vector[i];
109 }
110 return out;
111 }
112
118 template <int D, typename T>
119 inline
120 bool operator == (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
121 {
122 for (int i = 0; i < D; ++i) {
123 if (v1[i] != v2[i]) {
124 return false;
125 }
126 }
127 return true;
128 }
129
135 template <int D, typename T>
136 inline
137 bool operator == (const IntVec<D, T>& v1, const Vec<D, T>& v2)
138 {
139 for (int i = 0; i < D; ++i) {
140 if (v1[i] != v2[i]) {
141 return false;
142 }
143 }
144 return true;
145 }
146
152 template <int D, typename T>
153 inline
154 bool operator == (const Vec<D, T>& v1, const IntVec<D, T>& v2)
155 { return (v2 == v1); }
156
162 template <int D, typename T>
163 inline
164 bool operator != (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
165 { return !(v1 == v2); }
166
172 template <int D, typename T>
173 inline
174 bool operator != (const IntVec<D, T>& v1, const Vec<D, T>& v2)
175 { return !(v1 == v2); }
176
182 template <int D, typename T>
183 inline
184 bool operator != (const Vec<D, T>& v1, const IntVec<D, T>& v2)
185 { return !(v2 == v1); }
186
194 template <int D, typename T>
195 inline
196 bool operator < (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
197 {
198 for (int i = 0; i < D; ++i) {
199 if (v1[i] > v2[i]) {
200 return false;
201 } else
202 if (v1[i] < v2[i]) {
203 return true;
204 }
205 // This point is reached iff v1[i] == v2[i]
206 }
207 // If loop completes, the vectors are equal
208 return false;
209 }
210
218 template <int D, typename T>
219 inline
220 bool operator <= (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
221 {
222 for (int i = 0; i < D; ++i) {
223 if (v1[i] > v2[i]) {
224 return false;
225 } else
226 if (v1[i] < v2[i]) {
227 return true;
228 }
229 // This point is reached iff v1[i] == v2[i]
230 }
231 // If loop completes, the vectors are equal
232 return true;
233 }
234
240 template <int D, typename T>
241 inline
242 bool operator > (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
243 { return !(v1 <= v2); }
244
250 template <int D, typename T>
251 inline
252 bool operator >= (const IntVec<D, T>& v1, const IntVec<D, T>& v2)
253 { return !(v1 < v2); }
254
255}
256#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition: IntVec.h:27
static const int Width
Width of field per Cartesian coordinate in stream IO.
Definition: IntVec.h:69
A Vec<D, T><D,T> is a D-component vector with elements of type T.
Definition: Vec.h:66
File containing preprocessor macros for error handling.
C++ namespace for polymer self-consistent field theory (PSCF).
bool operator>(const IntVec< D, T > &v1, const IntVec< D, T > &v2)
Greater than comparison for two IntVec<D, T>s.
Definition: IntVec.h:242
bool operator<(const IntVec< D, T > &v1, const IntVec< D, T > &v2)
Less than comparison for two IntVec<D, T>s.
Definition: IntVec.h:196
bool operator>=(const IntVec< D, T > &v1, const IntVec< D, T > &v2)
Greater than or equal to comparison for two IntVec<D, T>s.
Definition: IntVec.h:252
bool operator<=(const IntVec< D, T > &v1, const IntVec< D, T > &v2)
Less than or equal to comparison for two IntVec<D, T>s.
Definition: IntVec.h:220
bool operator==(Polynomial< T > const &a, Polynomial< T > const &b)
Equality operator for polynomials.
Definition: Polynomial.h:675
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition: Pair.h:57
bool operator!=(Polynomial< T > const &a, Polynomial< T > const &b)
Inequality operator for polynomials.
Definition: Polynomial.h:694