IBR-DTNSuite  0.12
BundleSet.cpp
Go to the documentation of this file.
1 /*
2  * BundleSet.cpp
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: David Goltzsche <goltzsch@ibr.cs.tu-bs.de>
7  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Created on: 18.12.2012
22  * Recreated on: 04.04.2013 as interface
23  */
24 
25 #include "ibrdtn/data/BundleSet.h"
27 
28 namespace dtn
29 {
30  namespace data
31  {
32  BundleSet::Factory* BundleSet::__factory__ = NULL;
33 
35  {
36  if (__factory__ != NULL) delete __factory__;
37  __factory__ = f;
38  }
39 
41  {
42  }
43 
45  {
46  }
47 
48  BundleSetImpl* BundleSet::__create(Listener* listener, Size bf_size)
49  {
50  if (BundleSet::__factory__ != NULL) {
51  BundleSetImpl *set = BundleSet::__factory__->create(listener,bf_size);
52  if (set != NULL) return set;
53  }
54 
55  // by default, return a memory bundle-set
56  return new MemoryBundleSet(listener, bf_size);
57  }
58 
59  BundleSetImpl* BundleSet::__create(const std::string &name, Listener* listener, Size bf_size)
60  {
61  if (BundleSet::__factory__ != NULL) {
62  BundleSetImpl *set = BundleSet::__factory__->create(name, listener, bf_size);
63  if (set != NULL) return set;
64  }
65 
66  // by default, return a memory bundle-set
67  return new MemoryBundleSet(name, listener, bf_size);
68  }
69 
71  : _set_impl(BundleSet::__create(listener, bf_size))
72  {
73  }
74 
75  BundleSet::BundleSet(const std::string &name, BundleSet::Listener *listener, Size bf_size)
76  : _set_impl(BundleSet::__create(name, listener, bf_size))
77  {
78  }
79 
81  : _set_impl(other._set_impl->copy())
82  {
83  }
84 
86  {
87  }
88 
90  {
91  _set_impl->assign(other._set_impl);
92  return (*this);
93  }
94 
95  void BundleSet::add(const dtn::data::MetaBundle &bundle) throw ()
96  {
97  _set_impl->add(bundle);
98  }
99 
100  void BundleSet::clear() throw ()
101  {
102  _set_impl->clear();
103  }
104 
105  bool BundleSet::has(const dtn::data::BundleID &bundle) const throw ()
106  {
107  return _set_impl->has(bundle);
108  }
109 
110  Size BundleSet::size() const throw ()
111  {
112  return _set_impl->size();
113  }
114 
115  void BundleSet::expire(const Timestamp timestamp) throw ()
116  {
117  _set_impl->expire(timestamp);
118  }
119 
121  {
122  return _set_impl->getBloomFilter();
123  }
124 
125  std::set<dtn::data::MetaBundle> BundleSet::getNotIn(const ibrcommon::BloomFilter &filter) const throw ()
126  {
127  return _set_impl->getNotIn(filter);
128  }
129 
130  void BundleSet::sync() throw ()
131  {
132  return _set_impl->sync();
133  }
134 
135  Length BundleSet::getLength() const throw ()
136  {
137  return _set_impl->getLength();
138  }
139 
140  std::ostream& BundleSet::serialize(std::ostream &stream) const
141  {
142  return _set_impl->serialize(stream);
143  }
144 
145  std::istream& BundleSet::deserialize(std::istream &stream)
146  {
147  return _set_impl->deserialize(stream);
148  }
149 
150  std::ostream &operator<<(std::ostream &stream, const BundleSet &obj)
151  {
152  return obj.serialize(stream);
153  }
154 
155  std::istream &operator>>(std::istream &stream, BundleSet &obj)
156  {
157  return obj.deserialize(stream);
158  }
159  } /* namespace data */
160 } /* namespace dtn */