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 
51 class ROSBAG_STORAGE_DECL ChunkedFile
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 
99  boost::shared_ptr<StreamFactory> stream_factory_;
100 
101  boost::shared_ptr<Stream> read_stream_;
102  boost::shared_ptr<Stream> write_stream_;
103 };
104 
105 inline void swap(ChunkedFile& a, ChunkedFile& b) {
106  a.swap(b);
107 }
108 
109 } // namespace rosbag
110 
111 #endif
rosbag::ChunkedFile
ChunkedFile reads and writes files which contain interleaved chunks of compressed and uncompressed da...
Definition: chunked_file.h:83
boost::shared_ptr
decompress
def decompress(data)
macros.h
rosbag::swap
void swap(Bag &a, Bag &b)
Definition: bag.h:674
stream.h
ROSBAG_STORAGE_DECL
#define ROSBAG_STORAGE_DECL
Definition: macros.h:50
rosbag::CompressionType
compression::CompressionType CompressionType
Definition: stream.h:94
rosbag::ChunkedFile::swap
void swap(ChunkedFile &other)
Definition: chunked_file.cpp:230
rosbag
Definition: aes_encryptor.h:43


rosbag_storage
Author(s): Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:52