KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bbb_traj_set.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Ernesto Brau
17  * =========================================================================== */
18 
19 /* $Id$ */
20 
21 #ifndef B3_TRAJ_SET_H
22 #define B3_TRAJ_SET_H
23 
24 #include <bbb_cpp/bbb_data.h>
25 #include <set>
26 #include <boost/foreach.hpp>
27 
28 namespace kjb {
29 namespace bbb {
30 
37 class Traj_set
38 {
39 private:
40  typedef std::set<size_t> Iset;
41 
42 public:
43  typedef Iset::const_iterator const_iterator;
44  typedef Iset::const_reverse_iterator const_reverse_iterator;
45  typedef Iset::value_type value_type;
46 
47 public:
49  Traj_set() {}
50 
52  template<class TrIt>
53  Traj_set(TrIt first, TrIt last) : trajectories_(first, last) {}
54 
56  template<class SizeType>
57  void insert(const SizeType& j) { trajectories_.insert(j); }
58 
60  template<class TrIt>
61  void insert(TrIt first, TrIt last) { trajectories_.insert(first, last); }
62 
64  void clear() { trajectories_.clear(); }
65 
67  const_iterator begin() const { return trajectories_.begin(); }
68 
70  const_iterator end() const { return trajectories_.end(); }
71 
73  const_reverse_iterator rbegin() const { return trajectories_.rbegin(); }
74 
76  const_reverse_iterator rend() const { return trajectories_.rend(); }
77 
79  size_t size() const { return trajectories_.size(); }
80 
85  template<class OutIt>
86  void trajectories(const Data& data, OutIt output) const;
87 
88 private:
89  Iset trajectories_;
90 };
91 
92 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
93 
94 template<class OutIt>
95 void Traj_set::trajectories(const Data& data, OutIt output) const
96 {
97  size_t N = data.size();
98  BOOST_FOREACH(size_t j, trajectories_)
99  {
100  IFT(j < N, Runtime_error,
101  "Cannot get trajectories; invalid association.");
102 
103  *output++ = &data.trajectory(j);
104  }
105 }
106 
107 }} // namespace kjb::bbb
108 
109 #endif /*B3_TRAJ_SET_H */
110 
const_reverse_iterator rend() const
Iterator to reverse one-past-the-end index.
Definition: bbb_traj_set.h:76
Traj_set()
Construct an empty trajectory seet.
Definition: bbb_traj_set.h:49
Iset::const_reverse_iterator const_reverse_iterator
Definition: bbb_traj_set.h:44
void insert(TrIt first, TrIt last)
Add a sequence of indices to this association.
Definition: bbb_traj_set.h:61
Traj_set(TrIt first, TrIt last)
Construct a trajectory set from the given trajectory indices.
Definition: bbb_traj_set.h:53
const Trajectory & trajectory(size_t k) const
Get kth trajectory.
Definition: bbb_data.h:79
#define IFT(a, ex, msg)
Definition: l_exception.h:101
Definition: bbb_traj_set.h:37
void clear()
Clear this trajectory set.
Definition: bbb_traj_set.h:64
const_iterator begin() const
Iterator to first index.
Definition: bbb_traj_set.h:67
Definition: bbb_data.h:37
void trajectories(const Data &data, OutIt output) const
Get a set of pointers to trajectory. OutIt must point to const Trajectory*.
Definition: bbb_traj_set.h:95
size_t size() const
Number of trajectories in this set.
Definition: bbb_traj_set.h:79
const_reverse_iterator rbegin() const
Iterator to reverse first index.
Definition: bbb_traj_set.h:73
void insert(const SizeType &j)
Add trajectory to this association.
Definition: bbb_traj_set.h:57
size_t size() const
Number of trajectories.
Definition: bbb_data.h:73
Iset::const_iterator const_iterator
Definition: bbb_traj_set.h:43
Object thrown when computation fails somehow during execution.
Definition: l_exception.h:321
Iset::value_type value_type
Definition: bbb_traj_set.h:45
const_iterator end() const
Iterator to one-past-the-end index.
Definition: bbb_traj_set.h:70