1 | /*
|
---|
2 | * StreamOperators.hpp
|
---|
3 | *
|
---|
4 | * Created on: Apr 16, 2012
|
---|
5 | * Author: ankele
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef STREAMOPERATORS_HPP_
|
---|
9 | #define STREAMOPERATORS_HPP_
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 | // include config.h
|
---|
15 | #ifdef HAVE_CONFIG_H
|
---|
16 | #include <config.h>
|
---|
17 | #endif
|
---|
18 |
|
---|
19 | #include <string>
|
---|
20 | #include <iosfwd>
|
---|
21 |
|
---|
22 | #include "LinearAlgebra/Vector.hpp"
|
---|
23 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
24 | #include "Box.hpp"
|
---|
25 | #include "Element/element.hpp"
|
---|
26 | #include "molecule.hpp"
|
---|
27 |
|
---|
28 | #include "CodePatterns/Assert.hpp"
|
---|
29 |
|
---|
30 | class Vector;
|
---|
31 | class Box;
|
---|
32 | class RealSpaceMatrix;
|
---|
33 | class molecule;
|
---|
34 | class element;
|
---|
35 |
|
---|
36 | inline std::istream& operator>>(std::istream& ist, Vector& m)
|
---|
37 | {
|
---|
38 |
|
---|
39 | std::string line;
|
---|
40 | getline(ist,line);
|
---|
41 |
|
---|
42 | if (!line.empty() && line[0] == '(')
|
---|
43 | line.erase(0, 1);
|
---|
44 | if (!line.empty() && line[line.size() - 1] == ')')
|
---|
45 | line.erase(line.size() - 1, 1);
|
---|
46 | Vector temp_vector;
|
---|
47 |
|
---|
48 | // dissect by ","
|
---|
49 | double coord = 0.;
|
---|
50 | int counter = 0;
|
---|
51 | std::string::iterator olditer = line.begin();
|
---|
52 | for(std::string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) {
|
---|
53 | if ((*iter == ',') || (*iter == ' ')) {
|
---|
54 | std::istringstream stream(std::string(olditer, iter));
|
---|
55 |
|
---|
56 | stream >> coord;
|
---|
57 |
|
---|
58 | temp_vector[counter++] = coord;
|
---|
59 |
|
---|
60 | olditer = iter + 1;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | if ((olditer != line.begin()) && (counter != 3)) { // insert last part also
|
---|
64 |
|
---|
65 | std::istringstream stream(std::string(olditer, line.end()));
|
---|
66 | stream >> coord;
|
---|
67 | temp_vector[counter++] = coord;
|
---|
68 | }
|
---|
69 | m = temp_vector;
|
---|
70 | return ist;
|
---|
71 | };
|
---|
72 |
|
---|
73 | inline std::istream& operator>>(std::istream& ist, RealSpaceMatrix& m)
|
---|
74 | {
|
---|
75 |
|
---|
76 | std::string line;
|
---|
77 | getline(ist,line);
|
---|
78 |
|
---|
79 | if (!line.empty() && line[0] == '(')
|
---|
80 | line.erase(0, 1);
|
---|
81 | if (!line.empty() && line[line.size() - 1] == ')')
|
---|
82 | line.erase(line.size() - 1, 1);
|
---|
83 | double temp[6];
|
---|
84 |
|
---|
85 | // dissect by ","
|
---|
86 | double coord = 0.;
|
---|
87 | int counter = 0;
|
---|
88 | std::string::iterator olditer = line.begin();
|
---|
89 | for(std::string::iterator iter = line.begin(); (iter != line.end()) && (counter != 6); ++iter) {
|
---|
90 | if ((*iter == ',') || (*iter == ' ')) {
|
---|
91 | std::istringstream stream(std::string(olditer, iter));
|
---|
92 |
|
---|
93 | stream >> coord;
|
---|
94 |
|
---|
95 | temp[counter++] = coord;
|
---|
96 |
|
---|
97 | olditer = iter + 1;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | if ((olditer != line.begin()) && (counter != 6)) { // insert last part also
|
---|
101 |
|
---|
102 | std::istringstream stream(std::string(olditer, line.end()));
|
---|
103 | stream >> coord;
|
---|
104 | temp[counter++] = coord;
|
---|
105 | }
|
---|
106 | m.set(0,0, temp[0]);
|
---|
107 | m.set(0,1, temp[1]);
|
---|
108 | m.set(0,2, temp[2]);
|
---|
109 | m.set(1,0, temp[1]);
|
---|
110 | m.set(1,1, temp[3]);
|
---|
111 | m.set(1,2, temp[4]);
|
---|
112 | m.set(2,0, temp[2]);
|
---|
113 | m.set(2,1, temp[4]);
|
---|
114 | m.set(2,2, temp[5]);
|
---|
115 | return ist;
|
---|
116 | };
|
---|
117 |
|
---|
118 | inline std::istream& operator>>(std::istream& ist, Box& m)
|
---|
119 | {
|
---|
120 | RealSpaceMatrix M;
|
---|
121 | ist >> M;
|
---|
122 | m.setM(M);
|
---|
123 | return ist;
|
---|
124 | };
|
---|
125 |
|
---|
126 |
|
---|
127 | inline std::istream& operator>>(std::istream& ist, const molecule* & m)
|
---|
128 | {
|
---|
129 | std::cout << "=============== operator >> (istream, const element *) not implemented!\n";
|
---|
130 | ASSERT(0, "operator >> (istream, const element *) not implemented!");
|
---|
131 | return ist;
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | inline std::istream& operator>>(std::istream& ist, const element* & m)
|
---|
136 | {
|
---|
137 | std::cout << "=============== operator >> (istream, const element *) not implemented!\n";
|
---|
138 | ASSERT(0, "operator >> (istream, const element *) not implemented!");
|
---|
139 | return ist;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | inline std::istream& operator>>(std::istream& ist, std::vector<const molecule*> & m)
|
---|
144 | {
|
---|
145 | std::cout << "=============== operator >> (istream, std::vector<const element *>) not implemented!\n";
|
---|
146 | ASSERT(0, "operator >> (istream, std::vector<const element *>) not implemented!");
|
---|
147 | return ist;
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | inline std::istream& operator>>(std::istream& ist, std::vector<const element*> & m)
|
---|
152 | {
|
---|
153 | std::cout << "=============== operator >> (istream, std::vector<const element *>) not implemented!\n";
|
---|
154 | ASSERT(0, "operator >> (istream, std::vector<const element *>) not implemented!");
|
---|
155 | return ist;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | inline std::istream& operator>>(std::istream& ist, std::vector<std::string> & m)
|
---|
160 | {
|
---|
161 | std::cout << "=============== operator >> (istream, std::vector<std::string>) not implemented!\n";
|
---|
162 | ASSERT(0, "operator >> (istream, std::vector<std::string>) not implemented!");
|
---|
163 | return ist;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | #endif /* STREAMOPERATORS_HPP_ */
|
---|