Tawara  0.1.0
tracks.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 2012, Geoffrey Biggs, geoffrey.biggs@aist.go.jp
5  * RT-Synthesis Research Group
6  * Intelligent Systems Research Institute,
7  * National Institute of Advanced Industrial Science and Technology (AIST),
8  * Japan
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of Geoffrey Biggs nor AIST, nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #if !defined(TAWARA_TRACKS_H_)
40 #define TAWARA_TRACKS_H_
41 
42 #include <boost/operators.hpp>
43 #include <map>
44 #include <tawara/master_element.h>
45 #include <tawara/track_entry.h>
46 #include <tawara/uint_element.h>
47 #include <tawara/win_dll.h>
48 
51 
52 namespace tawara
53 {
62  public boost::equality_comparable<Tracks>
63  {
64  public:
66  typedef uint64_t key_type;
69 
70  protected:
72  typedef std::map<key_type, mapped_type> storage_type_;
73 
74  public:
80  Tracks();
81 
83  virtual ~Tracks() {};
84 
86  typedef storage_type_::value_type value_type;
88  typedef storage_type_::size_type size_type;
90  typedef storage_type_::reference reference;
92  typedef storage_type_::const_reference const_reference;
94  typedef storage_type_::iterator iterator;
96  typedef storage_type_::const_iterator const_iterator;
98  typedef storage_type_::reverse_iterator reverse_iterator;
100  typedef storage_type_::const_reverse_iterator
102 
108  mapped_type& at(key_type const& pos)
109  { return entries_.at(pos); }
115  mapped_type const& at(key_type const& pos) const
116  { return entries_.at(pos); }
117 
124  mapped_type& operator[](key_type const& key);
131  mapped_type const& operator[](key_type const& key) const;
132 
134  iterator begin() { return entries_.begin(); }
136  const_iterator begin() const { return entries_.begin(); }
138  iterator end() { return entries_.end(); }
140  const_iterator end() const { return entries_.end(); }
142  reverse_iterator rbegin() { return entries_.rbegin(); }
144  const_reverse_iterator rbegin() const { return entries_.rbegin(); }
148  reverse_iterator rend() { return entries_.rend(); }
152  const_reverse_iterator rend() const { return entries_.rend(); }
153 
155  bool empty() const { return entries_.empty(); }
157  size_type count() const { return entries_.size(); }
159  size_type max_count() const { return entries_.max_size(); }
160 
162  void clear() { entries_.clear(); }
180  std::pair<iterator, bool> insert(mapped_type const& value);
190  void insert(const_iterator first, const_iterator last);
195  void erase(iterator position)
196  { entries_.erase(position); }
202  void erase(iterator first, iterator last)
203  { entries_.erase(first, last); }
209  size_type erase(key_type const& number)
210  { return entries_.erase(number); }
215  void swap(Tracks& other)
216  { entries_.swap(other.entries_); }
217 
224  iterator find(key_type const& number)
225  { return entries_.find(number); }
232  const_iterator find(key_type const& number) const
233  { return entries_.find(number); }
234 
236  friend bool operator==(Tracks const& lhs, Tracks const& rhs);
237 
238  protected:
243  storage_type_ entries_;
244 
246  virtual std::streamsize body_size() const;
247 
255  virtual std::streamsize write_body(std::ostream& output);
256 
264  virtual std::streamsize read_body(std::istream& input,
265  std::streamsize size);
266 
274  void validate_entries() const;
275 
290  void verify_not_duplicate(TrackEntry::Ptr entry) const;
291  }; // class Tracks
292 
293  bool operator==(Tracks const& lhs, Tracks const& rhs);
294 }; // namespace tawara
295 
297 // group elements
298 
299 #endif // TAWARA_TRACKS_H_
300 
boost::shared_ptr< TrackEntry > Ptr
The type of a shared pointer to a TrackEntry.
Definition: track_entry.h:324
const ID Tracks(0x1654AE6B)
storage_type_::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
Definition: tracks.h:101
storage_type_::reference reference
The reference type.
Definition: tracks.h:90
mapped_type const & at(key_type const &pos) const
Get the TrackEntry with the given track number.
Definition: tracks.h:115
uint64_t key_type
The key type (Key) of this container.
Definition: tracks.h:66
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
void clear()
Remove all TrackElements.
Definition: tracks.h:162
std::map< key_type, mapped_type > storage_type_
The type of the internal storage.
Definition: tracks.h:72
The MasterElement interface.
virtual ~Tracks()
Destructor.
Definition: tracks.h:83
storage_type_::size_type size_type
The size type of this container.
Definition: tracks.h:88
const_reverse_iterator rbegin() const
Get a reverse iterator to the last TrackEntry.
Definition: tracks.h:144
storage_type_ entries_
The track entry store.
Definition: tracks.h:243
bool empty() const
Check if there are no TrackElements.
Definition: tracks.h:155
bool operator==(AttachedFile const &lhs, AttachedFile const &rhs)
Equality operator for the AttachedFile object.
iterator begin()
Get an iterator to the first TrackEntry.
Definition: tracks.h:134
The Tracks element, listing all tracks in the segment.
Definition: tracks.h:61
iterator find(key_type const &number)
Search for the TrackEntry with the given track number.
Definition: tracks.h:224
TrackEntry::Ptr mapped_type
The mapped type (T) of this container.
Definition: tracks.h:68
storage_type_::const_iterator const_iterator
The constant random access iterator type.
Definition: tracks.h:96
iterator end()
Get an iterator to the position past the last TrackEntry.
Definition: tracks.h:138
void swap(Tracks &other)
Swaps the contents of this Tracks element with another.
Definition: tracks.h:215
const_iterator begin() const
Get an iterator to the first TrackEntry.
Definition: tracks.h:136
reverse_iterator rbegin()
Get a reverse iterator to the last TrackEntry.
Definition: tracks.h:142
storage_type_::const_reference const_reference
The constant reference type.
Definition: tracks.h:92
size_type max_count() const
Get the maximum number of TrackElements.
Definition: tracks.h:159
const_iterator end() const
Get an iterator to the position past the last TrackEntry.
Definition: tracks.h:140
const_reverse_iterator rend() const
Get a reverse iterator to the position before the first TrackEntry.
Definition: tracks.h:152
mapped_type & at(key_type const &pos)
Get the TrackEntry with the given track number.
Definition: tracks.h:108
storage_type_::reverse_iterator reverse_iterator
The reversed random access iterator type.
Definition: tracks.h:98
storage_type_::iterator iterator
The random access iterator type.
Definition: tracks.h:94
const_iterator find(key_type const &number) const
Search for the TrackEntry with the given track number.
Definition: tracks.h:232
void erase(iterator first, iterator last)
Erase a range of TrackEntries.
Definition: tracks.h:202
size_type count() const
Get the number of TrackElements.
Definition: tracks.h:157
size_type erase(key_type const &number)
Erase the TrackEntry with the given track number.
Definition: tracks.h:209
reverse_iterator rend()
Get a reverse iterator to the position before the first TrackEntry.
Definition: tracks.h:148
void erase(iterator position)
Erase the TrackEntry at the specified iterator.
Definition: tracks.h:195