IBR-DTNSuite  0.10
BundleList.h
Go to the documentation of this file.
1 /*
2  * BundleList.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef BUNDLELIST_H_
23 #define BUNDLELIST_H_
24 
25 #include <ibrdtn/data/Number.h>
26 #include <ibrdtn/data/MetaBundle.h>
27 #include <set>
28 
29 namespace dtn
30 {
31  namespace data
32  {
33  class BundleList
34  {
35  public:
36  class Listener {
37  public:
38  virtual ~Listener() = 0;
39  virtual void eventBundleExpired(const dtn::data::MetaBundle&) throw () = 0;
40  };
41 
42  BundleList(BundleList::Listener *listener = NULL);
43  virtual ~BundleList();
44 
45  virtual void add(const dtn::data::MetaBundle &bundle) throw ();
46  virtual void remove(const dtn::data::MetaBundle &bundle) throw ();
47  virtual void clear() throw ();
48 
49  virtual void expire(const Timestamp &timestamp) throw ();
50 
51  typedef std::set<dtn::data::MetaBundle> meta_set;
52  typedef meta_set::iterator iterator;
53  typedef meta_set::const_iterator const_iterator;
54 
55  iterator begin() { return _meta_bundles.begin(); }
56  iterator end() { return _meta_bundles.end(); }
57 
58  const_iterator begin() const { return _meta_bundles.begin(); }
59  const_iterator end() const { return _meta_bundles.end(); }
60 
61  template<class T>
62  iterator find(const T &b) { return _meta_bundles.find(b); }
63 
64  template<class T>
65  const_iterator find(const T &b) const { return _meta_bundles.find(b); }
66 
67  bool empty() const { return _meta_bundles.empty(); }
68  Size size() const { return _meta_bundles.size(); }
69 
70  private:
71  class ExpiringBundle
72  {
73  public:
74  ExpiringBundle(const MetaBundle &b);
75  virtual ~ExpiringBundle();
76 
77  bool operator!=(const ExpiringBundle& other) const;
78  bool operator==(const ExpiringBundle& other) const;
79  bool operator<(const ExpiringBundle& other) const;
80  bool operator>(const ExpiringBundle& other) const;
81 
82  const MetaBundle &bundle;
83  };
84 
85  std::set<ExpiringBundle> _bundles;
86  std::set<dtn::data::MetaBundle> _meta_bundles;
87 
88  BundleList::Listener *_listener;
89  };
90 
91  }
92 }
93 
94 #endif /* BUNDLELIST_H_ */