forked from ecell/epdp
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathModel.cpp
66 lines (55 loc) · 1.97 KB
/
Model.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#include <algorithm>
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/lexical_cast.hpp>
#include "utils/fun_wrappers.hpp"
#include "SpeciesType.hpp"
#include "NetworkRules.hpp"
#include "BasicNetworkRulesImpl.hpp"
#include "Model.hpp"
Model::Model(): network_rules_(new BasicNetworkRulesImpl())
// The model class is more or less an implementation of the network rules
// The network rules define the possible reactions between species.
{
}
Model::~Model()
{
}
void Model::add_species_type(boost::shared_ptr<species_type_type> const& species)
{
species->bind_to_model(this, species_type_id_generator_());
species_type_map_.insert(std::make_pair(species->id(), species));
// the species_type_map_ is a mapping (container) between the species_id and the species object
}
boost::shared_ptr<Model::species_type_type> Model::get_species_type_by_id(species_id_type const& id) const
// Returns the species if you give it an species 'id'
{
species_type_map_type::const_iterator i(species_type_map_.find(id));
if (species_type_map_.end() == i)
{
throw not_found(boost::lexical_cast<std::string>(id));
}
return (*i).second;
}
Model::species_type_range Model::get_species_types() const
// Just gets all the species in the model
{
return species_type_range(
species_type_iterator(species_type_map_.begin(), species_second_selector_type()),
species_type_iterator(species_type_map_.end(), species_second_selector_type()));
}
std::string const& Model::operator[](std::string const& name) const
// Gets the name of the species? Or gets the value of an attribute by name?
{
string_map_type::const_iterator i(attrs_.find(name));
if (i == attrs_.end())
throw not_found((boost::format("key %s not found") % name).str());
return (*i).second;
}
std::string& Model::operator[](std::string const& name)
{
return attrs_[name];
}