Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnCompressionBuffer.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnCompressionBuffer.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <vector>
16 #include "Eigen/Core"
17 
18 using namespace std;
19 using namespace Eigen;
20 
21 // drwnCompressionBuffer ----------------------------------------------------
46 
48  protected:
49  unsigned char *_data;
50  unsigned int _bytesAllocated;
51  unsigned int _bytesOriginal;
52  unsigned int _bytesCompressed;
53 
54 #ifdef DRWN_DEBUG_STATISTICS
55  static unsigned _dbRefCount;
56  static unsigned _dbOriginalBytes;
57  static unsigned _dbCompressedBytes;
58 #endif
59 
60  public:
63 
65  unsigned int originalBytes() const { return _bytesOriginal; }
67  unsigned int compressedBytes() const { return _bytesCompressed; }
68 
70  void compress(const unsigned char *data, unsigned int size);
72  void decompress(unsigned char *data) const;
73 
75  size_t numBytesOnDisk() const;
77  bool write(ostream& os) const;
79  bool read(istream& is);
80 
82  drwnCompressionBuffer clone() const;
84  void free();
85 };
86 
87 // compression utility functions --------------------------------------------
88 
90 drwnCompressionBuffer drwnCompressVector(const VectorXd& x);
92 drwnCompressionBuffer drwnCompressMatrix(const MatrixXd& x);
94 VectorXd drwnDecompressVector(const drwnCompressionBuffer& buffer, int rows);
96 MatrixXd drwnDecompressMatrix(const drwnCompressionBuffer& buffer, int rows, int cols);
97 
unsigned int originalBytes() const
number of uncompressed bytes
Definition: drwnCompressionBuffer.h:65
unsigned int compressedBytes() const
number of compressed bytes
Definition: drwnCompressionBuffer.h:67
Utility class for compressing data using the zlib library.
Definition: drwnCompressionBuffer.h:47