source: finroc_plugins_network_transport/tNetworkConnections.cpp @ 5:ea3cb2f0499b

13.10
Last change on this file since 5:ea3cb2f0499b was 5:ea3cb2f0499b, checked in by Max Reichardt <mreichardt@…>, 8 years ago

Implemented more required functionality

File size: 4.1 KB
Line 
1//
2// You received this file as part of Finroc
3// A framework for intelligent robot control
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    plugins/network_transport/tNetworkConnections.cpp
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2013-11-28
27 *
28 */
29//----------------------------------------------------------------------
30#include "plugins/network_transport/tNetworkConnections.h"
31
32//----------------------------------------------------------------------
33// External includes (system with <>, local with "")
34//----------------------------------------------------------------------
35
36//----------------------------------------------------------------------
37// Internal includes with ""
38//----------------------------------------------------------------------
39
40//----------------------------------------------------------------------
41// Debugging
42//----------------------------------------------------------------------
43#include <cassert>
44
45//----------------------------------------------------------------------
46// Namespace usage
47//----------------------------------------------------------------------
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace finroc
53{
54namespace network_transport
55{
56
57//----------------------------------------------------------------------
58// Forward declarations / typedefs / enums
59//----------------------------------------------------------------------
60
61//----------------------------------------------------------------------
62// Const values
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Implementation
67//----------------------------------------------------------------------
68
69//----------------------------------------------------------------------
70// tNetworkConnections constructors
71//----------------------------------------------------------------------
72tNetworkConnections::tNetworkConnections() :
73  connections()
74{}
75
76void tNetworkConnections::Add(const tNetworkConnection& connection)
77{
78  for (size_t i = 0; i < connections.size(); i++)
79  {
80    if (connections[i] == connection)
81    {
82      return;
83    }
84  }
85  connections.push_back(connection);
86}
87
88void tNetworkConnections::Remove(const tNetworkConnection& connection)
89{
90  for (size_t i = 0; i < connections.size(); i++)
91  {
92    if (connections[i] == connection)
93    {
94      connections.erase(connections.begin() + i);
95      i--;
96    }
97  }
98}
99
100rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tNetworkConnections& connections)
101{
102  stream.WriteInt(static_cast<uint>(connections.connections.size()));
103  for (size_t i = 0; i < connections.connections.size(); i++)
104  {
105    stream << connections.connections[i];
106  }
107  return stream;
108}
109
110rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tNetworkConnections& connections)
111{
112  connections.connections.clear();
113  int count = stream.ReadInt();
114  for (int i = 0; i < count; i++)
115  {
116    connections.connections.emplace_back();
117    stream >> connections.connections.back();
118  }
119  return stream;
120}
121
122//----------------------------------------------------------------------
123// End of namespace declaration
124//----------------------------------------------------------------------
125}
126}
Note: See TracBrowser for help on using the repository browser.