Tawara  0.1.0
metaseek.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_METASEEK_H_)
40 #define TAWARA_METASEEK_H_
41 
42 #include <boost/operators.hpp>
43 #include <map>
44 #include <tawara/el_ids.h>
45 #include <tawara/master_element.h>
46 #include <tawara/seek_element.h>
47 #include <tawara/win_dll.h>
48 
51 
52 namespace tawara
53 {
68  public boost::equality_comparable<SeekHead>
69  {
70  public:
72  typedef ids::ID key_type;
74  typedef std::streamoff mapped_type;
75 
76  protected:
78  typedef std::multimap<key_type, mapped_type> storage_type_;
79 
80  public:
85  SeekHead();
86 
88  typedef storage_type_::value_type value_type;
90  typedef storage_type_::size_type size_type;
92  typedef storage_type_::reference reference;
94  typedef storage_type_::const_reference const_reference;
96  typedef storage_type_::iterator iterator;
98  typedef storage_type_::const_iterator const_iterator;
100  typedef storage_type_::reverse_iterator reverse_iterator;
102  typedef storage_type_::const_reverse_iterator
104 
108  SeekHead& operator=(SeekHead const& other)
109  { index_ = other.index_; return *this; }
110 
112  iterator begin() { return index_.begin(); }
114  const_iterator begin() const { return index_.begin(); }
118  iterator end() { return index_.end(); }
122  const_iterator end() const { return index_.end(); }
124  reverse_iterator rbegin() { return index_.rbegin(); }
126  const_reverse_iterator rbegin() const { return index_.rbegin(); }
130  reverse_iterator rend() { return index_.rend(); }
134  const_reverse_iterator rend() const { return index_.rend(); }
135 
137  bool empty() const { return index_.empty(); }
139  size_type count() const { return index_.size(); }
141  size_type max_count() const { return index_.max_size(); }
142 
144  void clear() { index_.clear(); }
155  iterator insert(value_type const& value)
156  { return index_.insert(value); }
162  void insert(const_iterator first, const_iterator last)
163  { index_.insert(first, last); }
168  void erase(iterator position) { index_.erase(position); }
174  void erase(iterator first, iterator last)
175  { index_.erase(first, last); }
181  size_type erase(key_type const& id)
182  { return index_.erase(id); }
187  void swap(SeekHead& other)
188  { index_.swap(other.index_); }
189 
199  iterator find(key_type const& id) { return index_.find(id); }
206  const_iterator find(key_type const& id) const
207  { return index_.find(id); }
208 
210  friend bool operator==(SeekHead const& lhs, SeekHead const& rhs);
211 
212  protected:
213  storage_type_ index_;
214 
216  virtual std::streamsize body_size() const;
217 
219  virtual std::streamsize write_body(std::ostream& output);
220 
222  virtual std::streamsize read_body(std::istream& input,
223  std::streamsize size);
224  }; // class SeekHead
225 
227  bool operator==(SeekHead const& lhs, SeekHead const& rhs);
228 }; // namespace Tawara
229 
231 // group elements
232 
233 #endif // TAWARA_METASEEK_H_
234 
size_type count() const
Get the number of index entries.
Definition: metaseek.h:139
size_type erase(key_type const &id)
Erase all index entries with the given ID.
Definition: metaseek.h:181
ids::ID key_type
The key type (Key) of this container.
Definition: metaseek.h:72
void erase(iterator position)
Erase the index entry at the specified iterator.
Definition: metaseek.h:168
const_iterator end() const
Get an iterator to the position past the last index entry.
Definition: metaseek.h:122
storage_type_::const_iterator const_iterator
The constant random access iterator type.
Definition: metaseek.h:98
iterator insert(value_type const &value)
Insert a new index entry.
Definition: metaseek.h:155
reverse_iterator rend()
Get a reverse iterator to the position before the first index entry.
Definition: metaseek.h:130
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
const_iterator begin() const
Get an iterator to the first index entry.
Definition: metaseek.h:114
const_reverse_iterator rend() const
Get a reverse iterator to the position before the first index entry.
Definition: metaseek.h:134
std::streamoff mapped_type
The mapped type (T) of this container.
Definition: metaseek.h:74
storage_type_::value_type value_type
The value type of this container.
Definition: metaseek.h:88
iterator end()
Get an iterator to the position past the last index entry.
Definition: metaseek.h:118
bool empty() const
Check if there are no index entries.
Definition: metaseek.h:137
iterator find(key_type const &id)
Search for the index entry with the given ID.
Definition: metaseek.h:199
The MasterElement interface.
storage_type_::iterator iterator
The random access iterator type.
Definition: metaseek.h:96
void clear()
Remove all index entries.
Definition: metaseek.h:144
storage_type_::reverse_iterator reverse_iterator
The reversed random access iterator type.
Definition: metaseek.h:100
storage_type_::const_reference const_reference
The constant reference type.
Definition: metaseek.h:94
size_type max_count() const
Get the maximum number of index entries.
Definition: metaseek.h:141
bool operator==(AttachedFile const &lhs, AttachedFile const &rhs)
Equality operator for the AttachedFile object.
iterator begin()
Get an iterator to the first index entry.
Definition: metaseek.h:112
uint32_t ID
Definition: el_ids.h:60
void swap(SeekHead &other)
Swaps the contents of this SeekHead with another.
Definition: metaseek.h:187
const_iterator find(key_type const &id) const
Search for the index entry with the given ID.
Definition: metaseek.h:206
storage_type_::size_type size_type
The size type of this container.
Definition: metaseek.h:90
reverse_iterator rbegin()
Get a reverse iterator to the last index entry.
Definition: metaseek.h:124
storage_type_::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
Definition: metaseek.h:103
storage_type_ index_
Definition: metaseek.h:213
std::multimap< key_type, mapped_type > storage_type_
The type of the internal storage.
Definition: metaseek.h:78
void erase(iterator first, iterator last)
Erase a range of index entries.
Definition: metaseek.h:174
SeekHead & operator=(SeekHead const &other)
Replace the stored offsets with those from another SeekHead element.
Definition: metaseek.h:108
const ID SeekHead(0x114D9B74)
void insert(const_iterator first, const_iterator last)
Insert a range of offsets.
Definition: metaseek.h:162
storage_type_::reference reference
The reference type.
Definition: metaseek.h:92
The SeekHead element, used as an index for a Tawara file.
Definition: metaseek.h:67
const_reverse_iterator rbegin() const
Get a reverse iterator to the last index entry.
Definition: metaseek.h:126