Points&Forces (core)
Software tools facilitating the task of surveying architecture
a_base.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2012 Pierre SMARS (smars@yuntech.edu.tw)
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 2 of the License, or
6 (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
15 */
16 #include "a_base.h"
17 #include <sstream>
18 #include <fstream>
19 
20 //---------------------------------------------------------------------------
21 const std::string a_base::help()
22 {
23  std::ostringstream o;
24  o << std::endl;
25  o << "Points&Forces User Commands" << std::endl;
26  o << "Copyright (C) 2000-20 Pierre Smars. License GPLv2";
27  o << " <http://www.gnu.org/licenses/gpl-2.0.html>.";
28  o << " This is free software:";
29  o << " you are free to change and redistribute it.";
30  o << " There is NO WARRANTY, to the extent permitted by law.";
31  return o.str();
32 }
33 //---------------------------------------------------------------------------
34 void a_base::read(const std::string &file)
35 {
36  std::ifstream ff(file.c_str());
37  if (!ff) throw a_base::file_open_error();
38  try {
39  this->read(ff);
40  }
41  catch (...) {throw a_base::file_read_error();}
42  ff.close();
43 }
44 //---------------------------------------------------------------------------
45 void a_base::write(const std::string &file) const
46 {
47  std::ofstream ff(file.c_str());
48  if (!ff) throw a_base::file_open_error();
49  try {
50  this->write(ff);
51  }
52  catch (...) {throw a_base::file_write_error();}
53  ff.close();
54 }
55 //---------------------------------------------------------------------------
56 std::istream& operator>> (std::istream& i, a_base& s)
57 {
58  s.read(i);
59  return i;
60 }
61 //---------------------------------------------------------------------------
62 std::ostream& operator<< (std::ostream& o, const a_base& s)
63 {
64  s.write(o);
65  return o;
66 }
67 //---------------------------------------------------------------------------
68 std::istream& operator>> (std::istream& i, a_base* s)
69 {
70  s->read(i);
71  return i;
72 }
73 //---------------------------------------------------------------------------
74 std::ostream& operator<< (std::ostream& o, const a_base* s)
75 {
76  s->write(o);
77  return o;
78 }
79 
std::istream & operator>>(std::istream &i, a_base &s)
Definition: a_base.cxx:56
std::ostream & operator<<(std::ostream &o, const a_base &s)
Definition: a_base.cxx:62
Definition: a_base.h:28
virtual void read(std::istream &i)
Definition: a_base.h:38
virtual void write(std::ostream &o) const
Definition: a_base.h:40
static const std::string help()
Definition: a_base.cxx:21