#include <string>
#include <sstream>
#include <fstream>
#include "Tree.hpp"

namespace nbody {
	Tree::Tree() {
	}

	Tree::~Tree() {
		this->clean();
	}

	void Tree::clean() {
		while (!this->nodes.empty()) {
			delete this->nodes.back();
			this->nodes.pop_back();
		}
	}

	vector<Body> Tree::dubinskiParse(string filename) {
		vector<Body> result;
		string line;
		ifstream infile(filename);
		double mass, px, py, pz, vx, vy, vz;

		while (infile >> mass >> px >>  py >> pz >> vx >> vy >> vz) {
			Body b(px, py, pz, vx, vy, vz, mass);

			result.push_back(b);
		}
		return result;
	}
}
