VPTissue Reference Manual
WallAttributes.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "WallAttributes.h"
21 
22 #include "WallType.h"
23 #include "util/misc/Exception.h"
24 #include "util/misc/log_debug.h"
25 
26 #include <boost/optional.hpp>
27 #include <iostream>
28 #include <sstream>
29 #include <string>
30 #include <utility>
31 
32 using namespace std;
33 using namespace boost::property_tree;
34 using boost::optional;
35 using namespace SimPT_Sim;
36 using namespace SimPT_Sim::Util;
37 
38 namespace SimPT_Sim {
39 
40 WallAttributes::WallAttributes(unsigned int num_chem)
41  : m_rest_length(0.0), m_rest_length_init(0.0), m_strength(0.0),
42  m_transporters1(vector<double>(num_chem)), m_transporters2(vector<double>(num_chem)),
43  m_wall_type(WallType::Type::Normal)
44 {
45 }
46 
47 WallAttributes::WallAttributes(double rest_length, double rest_length_init, double strength,
48  const vector<double>& transporters1, const vector<double>& transporters2, WallType::Type wall_type)
49  : m_rest_length(rest_length), m_rest_length_init(rest_length_init), m_strength(strength),
50  m_transporters1(transporters1), m_transporters2(transporters2), m_wall_type(wall_type)
51 {
52 }
53 
54 void WallAttributes::CycleWallType()
55 {
56  if (m_wall_type == WallType::Type::Normal) {
57  m_wall_type = WallType::Type::AuxinSource;
58  } else if (m_wall_type == WallType::Type::AuxinSource) {
59  m_wall_type = WallType::Type::AuxinSink;
60  } else if (m_wall_type == WallType::Type::AuxinSink) {
61  m_wall_type = WallType::Type::Normal;
62  }
63 }
64 
65 void WallAttributes::Swap(WallAttributes& src)
66 {
67  swap(m_rest_length, src.m_rest_length);
68  swap(m_rest_length_init, src.m_rest_length_init);
69  swap(m_transporters1, src.m_transporters1);
70  swap(m_transporters2, src.m_transporters2);
71  swap(m_wall_type, src.m_wall_type);
72 }
73 
74 void WallAttributes::ReadPtree(boost::property_tree::ptree const& wall_pt)
75 {
76  try {
77  m_rest_length = wall_pt.get<double>("rest_length");
78  m_rest_length_init = wall_pt.get<double>("rest_length_init");
79  m_strength = wall_pt.get<double>("strength");
80  m_transporters1.assign(m_transporters1.size(), 0.0);
81  m_transporters2.assign(m_transporters2.size(), 0.0);
82  m_wall_type = WallType::FromString(wall_pt.get<string>("type", "normal"));
83 
84  optional<ptree const&> tp1_array_pt = wall_pt.get_child_optional("transporter1_array");
85  if (tp1_array_pt) {
86  assert(tp1_array_pt->size() <= m_transporters1.size());
87  int tp1_i = 0;
88  for (auto const& tp1_v : *tp1_array_pt) {
89  m_transporters1[tp1_i++] = tp1_v.second.get_value<double>();
90  }
91  }
92 
93  optional<ptree const&> tp2_array_pt = wall_pt.get_child_optional("transporter2_array");
94  if (tp2_array_pt) {
95  assert(tp2_array_pt->size() <= m_transporters1.size());
96  int tp2_i = 0;
97  for (auto const& tp2_v : *tp2_array_pt) {
98  m_transporters2[tp2_i++] = tp2_v.second.get_value<double>();
99  }
100  }
101  }
102  catch(exception& e) {
103  const string here = string(VL_HERE) + " exception:\n";
104  throw Exception(here + e.what());
105  }
106 }
107 
109 {
110  ptree ret;
111 
112  ret.put("rest_length", GetRestLength());
113  ret.put("rest_length_init", GetRestLengthInit());
114  ret.put("strength", GetStrength());
115  ret.put("type", WallType::ToString(m_wall_type));
116 
117  ptree tp1_pt;
118  for (const auto& t : m_transporters1) {
119  tp1_pt.add("transporter1", t);
120  }
121  ret.put_child("transporter1_array", tp1_pt);
122 
123  ptree tp2_pt;
124  for (const auto& t : m_transporters2) {
125  tp2_pt.add("transporter2", t);
126  }
127  ret.put_child("transporter2_array", tp2_pt);
128 
129  return ret;
130 }
131 
132 } // namespace
Type FromString(string s)
Converts a string with name to WallType::Type value.
Definition: WallType.cpp:59
STL namespace.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
string ToString(Type w)
Converts a WallType::Type value to corresponding name.
Definition: WallType.cpp:49
Type
Enumerates the wall types.
Definition: WallType.h:27
Definition of WallType.
Extremely simple Exception root class.
Definition: Exception.h:28
Namespace for the core simulator.
Interface for WallAttributes.
Macro defs for debug and logging.
Attributes associated with a wall.
Header file for Exception class.
virtual boost::property_tree::ptree ToPtree() const
Convert the wall attributes to a ptree.