Tawara  0.1.0
block_additions.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_BLOCK_ADDITIONS_H_)
40 #define TAWARA_BLOCK_ADDITIONS_H_
41 
42 #include <boost/operators.hpp>
43 #include <boost/shared_ptr.hpp>
44 #include <stdint.h>
45 #include <tawara/master_element.h>
46 #include <vector>
47 #include <tawara/win_dll.h>
48 
51 
52 namespace tawara
53 {
61  public boost::equality_comparable<BlockAdditions>
62  {
63  public:
65  typedef std::pair<uint64_t, std::vector<char> > Addition;
67  typedef boost::shared_ptr<Addition> AdditionPtr;
69  typedef std::vector<AdditionPtr>::value_type value_type;
71  typedef std::vector<AdditionPtr>::size_type size_type;
73  typedef std::vector<AdditionPtr>::reference reference;
75  typedef std::vector<AdditionPtr>::const_reference const_reference;
77  typedef std::vector<AdditionPtr>::iterator iterator;
79  typedef std::vector<AdditionPtr>::const_iterator const_iterator;
81  typedef std::vector<AdditionPtr>::reverse_iterator reverse_iterator;
83  typedef std::vector<AdditionPtr>::const_reverse_iterator
85 
88 
92  value_type& at(size_type pos)
93  { return additions_.at(pos); }
97  value_type const& at(size_type pos) const
98  { return additions_.at(pos); }
99 
103  value_type& operator[](size_type pos)
104  { return additions_[pos]; }
108  value_type const& operator[](size_type pos) const
109  { return additions_[pos]; }
110 
112  iterator begin() { return additions_.begin(); }
114  const_iterator begin() const { return additions_.begin(); }
116  iterator end() { return additions_.end(); }
118  const_iterator end() const { return additions_.end(); }
120  reverse_iterator rbegin() { return additions_.rbegin(); }
123  { return additions_.rbegin(); }
127  reverse_iterator rend() { return additions_.rend(); }
131  const_reverse_iterator rend() const { return additions_.rend(); }
132 
134  bool empty() const { return additions_.empty(); }
136  size_type count() const { return additions_.size(); }
138  size_type max_count() const { return additions_.max_size(); }
139 
141  void clear() { additions_.clear(); }
142 
144  void erase(iterator position)
145  { additions_.erase(position); }
147  void erase(iterator first, iterator last)
148  { additions_.erase(first, last); }
149 
151  void push_back(value_type const& value);
152 
154  void resize(size_type count)
155  { additions_.resize(count); }
156 
158  void swap(BlockAdditions& other)
159  { additions_.swap(other.additions_); }
160 
162  friend bool operator==(BlockAdditions const& lhs,
163  BlockAdditions const& rhs);
164 
165  protected:
166  std::vector<AdditionPtr> additions_;
167 
169  virtual std::streamsize body_size() const;
170 
172  virtual std::streamsize write_body(std::ostream& output);
173 
175  virtual std::streamsize read_body(std::istream& input,
176  std::streamsize size);
177 
179  std::streamsize read_addition(std::istream& input,
180  std::streamsize size);
181  }; // class BlockAdditions
182 
184  bool operator==(BlockAdditions const& lhs, BlockAdditions const& rhs);
185 }; // namespace tawara
186 
188 // group elements
189 
190 #endif // TAWARA_BLOCK_ADDITIONS_H_
191 
void erase(iterator position)
Erase the addition at the specified iterator.
value_type const & operator[](size_type pos) const
Get a reference to an addition.
std::vector< AdditionPtr > additions_
std::pair< uint64_t, std::vector< char > > Addition
The type of a single block addition of data.
const_reverse_iterator rbegin() const
Get a reverse iterator to the last addition.
boost::shared_ptr< Addition > AdditionPtr
A pointer to an addition.
void erase(iterator first, iterator last)
Erase a range of additions.
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
void swap(BlockAdditions &other)
Swaps the contents of this BlockAdditions with another.
bool empty() const
Check if there are no additions.
reverse_iterator rend()
Get a reverse iterator to the position before the first addition.
iterator end()
Get an iterator to the position past the last addition.
The MasterElement interface.
bool operator==(AttachedFile const &lhs, AttachedFile const &rhs)
Equality operator for the AttachedFile object.
const_iterator begin() const
Get an iterator to the first addition.
reverse_iterator rbegin()
Get a reverse iterator to the last addition.
value_type const & at(size_type pos) const
Get the addition at the given position, with bounds checking.
value_type & at(size_type pos)
Get the addition at the given position, with bounds checking.
size_type max_count() const
Get the maximum number of additions.
value_type & operator[](size_type pos)
Get a reference to an addition.
std::vector< AdditionPtr >::value_type value_type
The value type of this container.
std::vector< AdditionPtr >::const_iterator const_iterator
The constant random access iterator type.
This element is used to specify reference blocks.
std::vector< AdditionPtr >::reverse_iterator reverse_iterator
The reversed random access iterator type.
const_reverse_iterator rend() const
Get a reverse iterator to the position before the first addition.
size_type count() const
Get the number of additions.
const_iterator end() const
Get an iterator to the position past the last addition.
void resize(size_type count)
Resizes the additions storage.
iterator begin()
Get an iterator to the first addition.
std::vector< AdditionPtr >::reference reference
The reference type.
void clear()
Remove all additions.
std::vector< AdditionPtr >::size_type size_type
The size type of this container.
std::vector< AdditionPtr >::const_reference const_reference
The constant reference type.
std::vector< AdditionPtr >::const_reverse_iterator const_reverse_iterator
The constant reversed random access iterator type.
const ID BlockAdditions(0x75A1)
std::vector< AdditionPtr >::iterator iterator
The random access iterator type.