chunked_file.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 ********************************************************************/
34 
35 #ifndef ROSBAG_CHUNKED_FILE_H
36 #define ROSBAG_CHUNKED_FILE_H
37 
38 #include <ios>
39 #include <stdint.h>
40 #include <string>
41 #include "macros.h"
42 #include <boost/shared_ptr.hpp>
43 
44 #include <bzlib.h>
45 
46 #include "rosbag/stream.h"
47 
48 namespace rosbag {
49 
52 {
53  friend class Stream;
54 
55 public:
56  ChunkedFile();
57  ~ChunkedFile();
58 
59  void openWrite (std::string const& filename);
60  void openRead (std::string const& filename);
61  void openReadWrite(std::string const& filename);
62 
63  void close();
64 
65  std::string getFileName() const;
66  uint64_t getOffset() const;
67  uint32_t getCompressedBytesIn() const;
68  bool isOpen() const;
69  bool good() const;
70 
71  void setReadMode(CompressionType type);
72  void setWriteMode(CompressionType type);
73 
74  // File I/O
75  void write(std::string const& s);
76  void write(void* ptr, size_t size);
77  void read(void* ptr, size_t size);
78  std::string getline();
79  bool truncate(uint64_t length);
80  void seek(uint64_t offset, int origin = std::ios_base::beg);
81  void decompress(CompressionType compression, uint8_t* dest, unsigned int dest_len, uint8_t* source, unsigned int source_len);
82  void swap(ChunkedFile& other);
83 
84 private:
85  ChunkedFile(const ChunkedFile&);
86  ChunkedFile& operator=(const ChunkedFile&);
87 
88  void open(std::string const& filename, std::string const& mode);
89  void clearUnused();
90 
91 private:
92  std::string filename_;
93  FILE* file_;
94  uint64_t offset_;
95  uint64_t compressed_in_;
96  char* unused_;
97  int nUnused_;
98 
100 
103 };
104 
105 inline void swap(ChunkedFile& a, ChunkedFile& b) {
106  a.swap(b);
107 }
108 
109 } // namespace rosbag
110 
111 #endif
ChunkedFile reads and writes files which contain interleaved chunks of compressed and uncompressed da...
Definition: chunked_file.h:51
void swap(Bag &a, Bag &b)
Definition: bag.h:653
void swap(ChunkedFile &other)
uint64_t offset_
current position in the file
Definition: chunked_file.h:94
int nUnused_
number of bytes of extra data read by compressed stream
Definition: chunked_file.h:97
#define ROSBAG_DECL
Definition: macros.h:42
def decompress(data)
boost::shared_ptr< StreamFactory > stream_factory_
Definition: chunked_file.h:99
boost::shared_ptr< Stream > write_stream_
Definition: chunked_file.h:102
uint64_t compressed_in_
number of bytes written to current compressed stream
Definition: chunked_file.h:95
std::string filename_
path to file
Definition: chunked_file.h:92
Definition: bag.h:78
FILE * file_
file pointer
Definition: chunked_file.h:93
boost::shared_ptr< Stream > read_stream_
Definition: chunked_file.h:101
char * unused_
extra data read by compressed stream
Definition: chunked_file.h:96


rosbag_storage
Author(s):
autogenerated on Sun Feb 3 2019 03:29:47