Tawara  0.1.0
element.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_ELEMENT_H_)
40 #define TAWARA_ELEMENT_H_
41 
42 #include <tawara/el_ids.h>
43 #include <tawara/win_dll.h>
44 
45 #include <ios>
46 #include <iostream>
47 #include <stdint.h>
48 
49 
52 
53 namespace tawara
54 {
67  {
68  public:
76 
78  virtual ~Element() {};
79 
104  uint32_t id() const { return id_; }
105 
117  std::streampos offset() const { return offset_; }
118 
126  virtual std::streamsize size() const;
127 
137  virtual std::streamsize write(std::ostream& output);
138 
163  virtual std::streamsize read(std::istream& input);
164 
165  protected:
167  std::streampos offset_;
168 
179  virtual std::streamsize body_size() const = 0;
180 
190  std::streamsize write_id(std::ostream& output);
191 
200  virtual std::streamsize write_size(std::ostream& output);
201 
210  virtual std::streamsize write_body(std::ostream& output) = 0;
211 
238  virtual std::streamsize read_body(std::istream& input,
239  std::streamsize size) = 0;
240 
241  }; // class Element
242 
243 
256  std::streamsize skip_read(std::istream& input, bool and_id);
257 
258 
271  std::streamsize skip_write(std::iostream& stream, bool and_id);
272 }; // namespace tawara
273 
276 
277 #endif // TAWARA_ELEMENT_H_
278 
std::streamsize write(ID id, std::ostream &output)
Write an ID to an output stream.
std::streamsize skip_write(std::iostream &stream, bool and_id)
Skip an element in an input/output stream.
std::streampos offset_
Definition: element.h:167
virtual ~Element()
Destructor.
Definition: element.h:78
std::streamsize size(ID id)
Get the number of bytes required by an ID.
#define TAWARA_EXPORT
Definition: win_dll.h:51
std::streampos offset() const
Get the element&#39;s offset in the byte stream.
Definition: element.h:117
uint32_t id() const
Get the element&#39;s ID.
Definition: element.h:104
ReadResult read(std::istream &input)
Read an ID from an input stream.
uint32_t ID
Definition: el_ids.h:60
tawara::ids::ID id_
Definition: element.h:166
std::streamsize skip_read(std::istream &input, bool and_id)
Skip an element in an input stream.
The Element interface, a basic interface to an element object.
Definition: element.h:66