/* * StreamOperators.hpp * * Created on: Apr 16, 2012 * Author: ankele */ #ifndef STREAMOPERATORS_HPP_ #define STREAMOPERATORS_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "LinearAlgebra/Vector.hpp" #include "LinearAlgebra/RealSpaceMatrix.hpp" #include "Box.hpp" #include "Element/element.hpp" #include "molecule.hpp" #include "CodePatterns/Assert.hpp" class Vector; class Box; class RealSpaceMatrix; class molecule; class element; inline std::istream& operator>>(std::istream& ist, Vector& m) { std::string line; getline(ist,line); if (!line.empty() && line[0] == '(') line.erase(0, 1); if (!line.empty() && line[line.size() - 1] == ')') line.erase(line.size() - 1, 1); Vector temp_vector; // dissect by "," double coord = 0.; int counter = 0; std::string::iterator olditer = line.begin(); for(std::string::iterator iter = line.begin(); (iter != line.end()) && (counter != 3); ++iter) { if ((*iter == ',') || (*iter == ' ')) { std::istringstream stream(std::string(olditer, iter)); stream >> coord; temp_vector[counter++] = coord; olditer = iter + 1; } } if ((olditer != line.begin()) && (counter != 3)) { // insert last part also std::istringstream stream(std::string(olditer, line.end())); stream >> coord; temp_vector[counter++] = coord; } m = temp_vector; return ist; }; inline std::istream& operator>>(std::istream& ist, RealSpaceMatrix& m) { std::string line; getline(ist,line); if (!line.empty() && line[0] == '(') line.erase(0, 1); if (!line.empty() && line[line.size() - 1] == ')') line.erase(line.size() - 1, 1); double temp[6]; // dissect by "," double coord = 0.; int counter = 0; std::string::iterator olditer = line.begin(); for(std::string::iterator iter = line.begin(); (iter != line.end()) && (counter != 6); ++iter) { if ((*iter == ',') || (*iter == ' ')) { std::istringstream stream(std::string(olditer, iter)); stream >> coord; temp[counter++] = coord; olditer = iter + 1; } } if ((olditer != line.begin()) && (counter != 6)) { // insert last part also std::istringstream stream(std::string(olditer, line.end())); stream >> coord; temp[counter++] = coord; } m.set(0,0, temp[0]); m.set(0,1, temp[1]); m.set(0,2, temp[2]); m.set(1,0, temp[1]); m.set(1,1, temp[3]); m.set(1,2, temp[4]); m.set(2,0, temp[2]); m.set(2,1, temp[4]); m.set(2,2, temp[5]); return ist; }; inline std::istream& operator>>(std::istream& ist, Box& m) { RealSpaceMatrix M; ist >> M; m.setM(M); return ist; }; inline std::istream& operator>>(std::istream& ist, const molecule* & m) { std::cout << "=============== operator >> (istream, const element *) not implemented!\n"; ASSERT(0, "operator >> (istream, const element *) not implemented!"); return ist; } inline std::istream& operator>>(std::istream& ist, const element* & m) { std::cout << "=============== operator >> (istream, const element *) not implemented!\n"; ASSERT(0, "operator >> (istream, const element *) not implemented!"); return ist; } inline std::istream& operator>>(std::istream& ist, std::vector & m) { std::cout << "=============== operator >> (istream, std::vector) not implemented!\n"; ASSERT(0, "operator >> (istream, std::vector) not implemented!"); return ist; } inline std::istream& operator>>(std::istream& ist, std::vector & m) { std::cout << "=============== operator >> (istream, std::vector) not implemented!\n"; ASSERT(0, "operator >> (istream, std::vector) not implemented!"); return ist; } inline std::istream& operator>>(std::istream& ist, std::vector & m) { std::cout << "=============== operator >> (istream, std::vector) not implemented!\n"; ASSERT(0, "operator >> (istream, std::vector) not implemented!"); return ist; } #endif /* STREAMOPERATORS_HPP_ */