Points&Forces (survey)
Software tools facilitating the task of surveying architecture
a_material.cxx
Go to the documentation of this file.
1 /*
2 Copyright 2010-2014 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_material.h"
17 //---------------------------------------------------------------------------
18 const std::string a_material::help()
19 {
20  std::ostringstream o;
21  o << "************" << std::endl;
22  o << "a_material:" << std::endl;
23  o << "************" << std::endl;
24  o << "This class is used to model materials" << std::endl;
25  o << "Commands:" << std::endl;
26  o << "--------" << std::endl;
27  o << "a_material M: create a material named M" << std::endl;
28  o << "a_material M 'name' 'density': create a material named M with 'name' and 'density'" << std::endl;
29  o << "density 'd': sets the density to 'd'" << std::endl;
30  o << "density: gets the density" << std::endl;
31  o << "name 'n': sets the name of the material to 'n'" << std::endl;
32  o << "name: gets the name of the material" << std::endl;
33  return o.str();
34 }
35 //---------------------------------------------------------------------------
36 void a_material::read(std::istream &in)
37 {
38  std::string li,li2;
39  std::getline(in,li);
40  std::size_t r1 = li.find_first_of('"');
41  std::size_t r2 = li.find('"',r1+1);
42  name_ = li.substr(r1,r2);
43  li2 = li.substr(r2+1,li.length());
44  std::istringstream in2(li2);
45  in2 >> density_;
46 }
47 //---------------------------------------------------------------------------
48 void a_material::write(std::ostream &o) const
49 {
50  o << "\"" << name_ << "\" " << density_;
51 }
52 //***************************************************************************
53 //---------------------------------------------------------------------------
54 std::istream& operator>> (std::istream& i, a_material& f)
55 {
56  f.read(i);
57  return i;
58 }
59 //---------------------------------------------------------------------------
60 std::ostream& operator<<(std::ostream& o, const a_material& f)
61 {
62  f.write(o);
63  return o;
64 }
65 //---------------------------------------------------------------------------
66 std::istream& operator>> (std::istream& i, a_material* f)
67 {
68  f->read(i);
69  return i;
70 }
71 //---------------------------------------------------------------------------
72 std::ostream& operator<<(std::ostream& o, const a_material* f)
73 {
74  f->write(o);
75  return o;
76 }
77 //***************************************************************************
std::ostream & operator<<(std::ostream &o, const a_material &f)
Definition: a_material.cxx:60
std::istream & operator>>(std::istream &i, a_material &f)
Definition: a_material.cxx:54
virtual void read(std::istream &i)
Definition: a_material.cxx:36
double density_
Definition: a_material.h:44
static const std::string help()
get information about the class
Definition: a_material.cxx:18
std::string name_
Definition: a_material.h:45
virtual void write(std::ostream &o) const
Definition: a_material.cxx:48