io.hpp
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <iostream>
10 
11 namespace LCS {
12 
13 // outputs
14 
20 template <typename T>
21 std::ostream& operator<< (std::ostream& os, const Vector<T, 2>& vec)
22 {
23  os << vec.x << std::endl << vec.y;
24 
25  return os;
26 }
27 
33 template <typename T>
34 std::ostream& operator<< (std::ostream& os, const Scalar<T>& scalar)
35 {
36  os << scalar.value;
37 
38  return os;
39 }
40 
46 template <typename T, unsigned Dim>
47 std::ostream& operator<< (std::ostream& os, const Tensor<T, Dim>& tensor)
48 {
49  unsigned nx, ny;
50  std::tie(nx, ny) = tensor.Size();
51 
52  for (unsigned i = 0; i < nx; ++i)
53  for (unsigned j = 0; j < ny; ++j)
54  os << tensor(i, j) << std::endl;
55 
56  return os;
57 }
58 
64 template <typename T, unsigned Dim, unsigned Size>
65 std::ostream& operator<< (std::ostream& os, const Field<T, Dim, Size>& field)
66 {
67  os << field.GetAll();
68 
69  return os;
70 }
71 
72 // inputs
73 
79 template <typename T>
80 std::istream& operator>> (std::istream& is, Vector<T, 2>& vec)
81 {
82  is >> vec.x;
83  is >> vec.y;
84 
85  return is;
86 }
87 
93 template <typename T>
94 std::ostream& operator>> (std::ostream& is, Scalar<T>& scalar)
95 {
96  is >> scalar.value;
97 
98  return is;
99 }
100 
106 template <typename T, unsigned Dim>
107 std::istream& operator>> (std::istream& is, Tensor<T, Dim>& tensor)
108 {
109  unsigned nx, ny;
110  std::tie(nx, ny) = tensor.Size();
111 
112  for (unsigned i = 0; i < nx; ++i)
113  for (unsigned j = 0; j < ny; ++j)
114  is >> tensor(i, j);
115 
116  return is;
117 }
118 
124 template <typename T, unsigned Dim, unsigned Size>
125 std::istream& operator>> (std::istream& is, Field<T, Dim>& field)
126 {
127  is >> field.GetAll();
128 
129  return is;
130 }
131 
132 }
T y
Definition: basic.hpp:104
T x
Definition: basic.hpp:103
T value
Definition: basic.hpp:173
Class for tensors.
Definition: basic.hpp:183
auto & GetAll() const
Definition: field.hpp:47
Class for general physical fields.
Definition: field.hpp:35
Vector with one element.
Definition: basic.hpp:163
auto Size() const
Definition: basic.hpp:299
std::istream & operator>>(std::istream &is, Vector< T, 2 > &vec)
Definition: io.hpp:80
Struct for vectors.
Definition: basic.hpp:92