Flow123d  jenkins-Flow123d-windows-release-multijob-285
substance.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  * @file
26  * @brief Classes for storing substance data.
27  * @author Jan Stebel
28  */
29 
30 
31 #include <iostream>
32 #include <iomanip>
33 
34 #include "transport/substance.hh"
35 
36 
37 
38 using namespace Input::Type;
39 
40 
42  = Record("Substance", "Chemical substance.")
43  .declare_key("name", String(), Default::obligatory(), "Name of the substance.")
44  .declare_key("molar_mass", Double(0), Default("1"), "Molar mass of the substance [kg/mol].")
45  .allow_auto_conversion("name");
46 
47 
48 
49 
51  : name_(""),
52  molar_mass_(1)
53 {
54 }
55 
57 {
58  name_ = in_rec.val<std::string>("name");
59  molar_mass_ = in_rec.val<double>("molar_mass");
60 }
61 
62 
63 
64 
65 
66 
67 
69 {
70  substances_ = boost::make_shared<std::vector<Substance> >();
71  names_ = boost::make_shared<std::vector<std::string> >();
72 
73  for (auto it = in_array.begin<Input::Record>(); it != in_array.end(); ++it)
74  {
75  Substance s(*it);
76  (*substances_).push_back(s);
77  (*names_).push_back(s.name());
78  }
79 }
80 
82 {
83  substances_ = list.substances_;
84  names_ = list.names_;
85 }
86 
87 
89 {
90  substances_ = boost::make_shared<std::vector<Substance> >();
91  names_ = boost::make_shared<std::vector<std::string> >(names);
92 
93  // copy names to internal vectors
94  (*substances_).resize(names.size());
95  for (unsigned int i=0; i<names.size(); ++i) (*substances_)[i].name_ = names[i];
96  *names_ = names;
97 }
98 
Iterator< ValueType > begin() const
Accessor to input data conforming to declared Array.
Definition: accessors.hh:558
Substance()
Default constructor.
Definition: substance.cc:50
const std::vector< std::string > & names()
Definition: substance.hh:97
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:39
boost::shared_ptr< std::vector< Substance > > substances_
The actual list of substances.
Definition: substance.hh:104
static Default obligatory()
Definition: type_record.hh:89
void initialize(const Input::Array &in_array)
Read from input array.
Definition: substance.cc:68
boost::shared_ptr< std::vector< std::string > > names_
Auxiliary list of substance names used in some classes.
Definition: substance.hh:107
IteratorBase end() const
std::string name_
Name of a chemical substance.
Definition: substance.hh:67
double molar_mass_
Molar mass [kg/mol] of the substance.
Definition: substance.hh:70
Record & allow_auto_conversion(const string &from_key)
Definition: type_record.cc:111
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:392
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
const Ret val(const string &key) const
Classes for storing substance data.
Record type proxy class.
Definition: type_record.hh:169
static Input::Type::Record input_type
Input type for a substance.
Definition: substance.hh:62
std::string name() const
Getter for substance name.
Definition: substance.hh:55
Record & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:430