OverSim
StrategySendAll.cc
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Institut fuer Telematik, Universitaet Karlsruhe (TH)
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 //
18 
24 #include <TreeManagement.h>
25 
26 #include "StrategySendAll.h"
27 
28 
30 {
31  lastSendCount = 0;
32 }
33 
34 
36 {
37  // TODO Auto-generated destructor stub
38 }
39 
40 
42 {
43  std::vector<double> tmpDimVector = ncsInfo.getCoords();
44  coordinatesVector tmpCoordsVector;
45  tmpCoordsVector.push_back(tmpDimVector);
46 
47  // i am my own branch here ...
48  setBranchCoordinates(thisNode, tmpCoordsVector);
49 }
50 
51 
53  coordinatesVector coordsVector)
54 {
55  if(coordData.find(node) != coordData.end()) {
56  coordData.find(node)->second = coordsVector;
57  } else {
58  coordData.insert(nodeCoordData(node, coordsVector));
59  }
60 }
61 
62 
64 {
65  SendAllStrategyCall* msg = new SendAllStrategyCall("SendAllStrategyCall");
66 
67  CoordDataContainer tmpCoordContainer;
68  tmpCoordContainer.coordinatesVector = getCombinedCoordsVector();
69 
70  lastSendCount = tmpCoordContainer.coordinatesVector.size();
71 
72  msg->setCoordData(tmpCoordContainer);
73  msg->setBitLength(SENDALLSTRATEGYCALL_L(msg));
74 
75  return msg;
76 }
77 
78 
80 {
81  SendAllStrategyCall* sendAllStrategyCall = dynamic_cast<SendAllStrategyCall*>(globalViewBuilderCall);
82  setBranchCoordinates(sendAllStrategyCall->getSrcNode(), sendAllStrategyCall->getCoordData().coordinatesVector);
83 }
84 
85 
86 const std::vector<std::vector<double> > StrategySendAll::getCombinedCoordsVector()
87 {
88  coordinatesVector combinedCoordsVector;
89  coordinatesVector branchCoordsVector;
90 
91  coordDataMap::const_iterator coordDataMapIterator = coordData.begin();
92 
93  while(coordDataMapIterator != coordData.end()) {
94 
95  branchCoordsVector = coordDataMapIterator->second;
96 
97  coordinatesVector::iterator vIterator;
98  for(vIterator=branchCoordsVector.begin(); vIterator < branchCoordsVector.end(); vIterator++) {
99  combinedCoordsVector.push_back(*vIterator);
100  }
101 
102  ++coordDataMapIterator;
103  }
104  return combinedCoordsVector;
105 }
106 
107 
108 void StrategySendAll::cleanUpCoordData(const treeNodeMap& currentTreeChildNodes)
109 {
110  coordDataMap::const_iterator coordDataMapIterator = coordData.begin();
111 
112  while(coordDataMapIterator != coordData.end()) {
113  if(currentTreeChildNodes.find(coordDataMapIterator->first) ==
114  currentTreeChildNodes.end() && coordDataMapIterator->first != thisNode) {
115  coordDataMapIterator = coordData.erase(coordDataMapIterator);
116  } else ++coordDataMapIterator;
117  }
118 }
119 
120 
122 {
123  std::stringstream tempStr;
124  tempStr << "CoordCount: " << lastSendCount;
125  return tempStr.str();
126 }
127 
128 
130 {
131  std::stringstream tempStr;
132  tempStr << "sendAll";
133 
134  return tempStr.str();
135 }
136 
137 
139 {
140  int size = 0;
141 
142  coordinatesVector::const_iterator vNodeIterator = combinedCoordsVector.begin();
143  std::vector<double>::const_iterator vCoordsIterator;
144 
145  while(vNodeIterator != combinedCoordsVector.end()) {
146 
147  size += sizeof((*vNodeIterator));
148 
149  vCoordsIterator = (*vNodeIterator).begin();
150  while(vCoordsIterator != (*vNodeIterator).end()) {
151  size += sizeof((*vCoordsIterator));
152  vCoordsIterator++;
153  }
154  vNodeIterator++;
155  }
156 
157  return size;
158 }
159 
160 
162 {
163  return sizeof((*(*combinedCoordsVector.begin()).begin()));
164 }
165 
166 std::vector<std::vector<double> > StrategySendAll::getGlobalViewData()
167 {
168  return getCombinedCoordsVector();
169 }
170