Swarm-NG  1.1
snapshot.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2011 by Saleh Dindar and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
24 #pragma once
25 
26 #include "common.hpp"
27 #include "types/ensemble.hpp"
28 #include "ensemble_alloc.hpp"
29 
30 using std::string;
31 
32 namespace swarm {
33 
149 namespace snapshot {
150 
153  struct header {
154  int nsys, nbod, nsysattr, nbodattr;
155  };
159  struct sys {
160  double time;
161  int id;
162  int state;
163  double attribute[ensemble::NUM_SYS_ATTRIBUTES];
164  };
168  struct body {
169  double pos[3], vel[3], mass, attribute[ensemble::NUM_BODY_ATTRIBUTES];
170  };
171 
174  struct readfileexception : public std::exception {
175  string filename;
176  int lineno;
177  string message;
178  readfileexception( const string& filename, const string& message, const int& lineno = 0): filename(filename),message(message),lineno(lineno) {}
179  virtual ~readfileexception()throw(){}
180  virtual const char* what() const throw() {
181  return ("Error reading " + filename + " : " + message).c_str();
182  }
183  };
184 
187  struct writefileexception : public std::exception {
188  string filename;
189  int lineno;
190  string message;
191  writefileexception( const string& filename, const string& message, const int& lineno = 0): filename(filename),message(message),lineno(lineno) {}
192  virtual ~writefileexception()throw(){}
193  virtual const char* what() const throw() {
194  return ("Error writing " + filename + " : " + message).c_str();
195  }
196  };
197 
199  defaultEnsemble load(const string& filename)
200  throw (readfileexception);
201 
203  defaultEnsemble load_text(const string& filename)
204  throw (readfileexception);
205 
207  void save(defaultEnsemble& ens, const string& filename)
208  throw (writefileexception);
209 
211  void save_text(defaultEnsemble& ens, const string& filename)
212  throw (writefileexception);
213 
214 }
215 
216 }
217