ProteoWizard
BinaryDataEncoder.hpp
Go to the documentation of this file.
1 //
2 // $Id: BinaryDataEncoder.hpp 5084 2013-10-28 23:32:24Z pcbrefugee $
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2007 Spielberg Family Center for Applied Proteomics
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #ifndef _BINARYDATAENCODER_HPP_
25 #define _BINARYDATAENCODER_HPP_
26 
27 
29 #include "boost/shared_ptr.hpp"
30 #include <string>
31 #include <vector>
32 #include <map>
33 #include "pwiz/data/common/cv.hpp"
34 
35 
36 namespace pwiz {
37 namespace msdata {
38 
39 const double BinaryDataEncoder_default_numpressSlofErrorTolerance = 0.0002; // 2/100th of one percent
41 const double BinaryDataEncoder_default_numpressPicErrorTolerance = 0.5; // rounds to nearest integer
42 
43 /// binary-to-text encoding
45 {
46  public:
47 
48  enum Precision {Precision_32, Precision_64};
49  enum ByteOrder {ByteOrder_LittleEndian, ByteOrder_BigEndian};
50  enum Compression {Compression_None, Compression_Zlib};
51  enum Numpress {Numpress_None, Numpress_Linear, Numpress_Pic, Numpress_Slof}; // lossy numerical representations
52 
53  /// encoding/decoding configuration
55  {
58  Compression compression; // zlib or none
59  Numpress numpress; // lossy numerical compression
60  double numpressFixedPoint; // for Numpress_* use, 0=derive best value
61  double numpressLinearErrorTolerance; // guarantee abs(1.0-(encoded/decoded)) <= this, 0=do not guarantee anything
62  double numpressSlofErrorTolerance; // guarantee abs(1.0-(encoded/decoded)) <= this, 0=do not guarantee anything
63 
64  std::map<cv::CVID, Precision> precisionOverrides;
65  std::map<cv::CVID, Numpress> numpressOverrides;
66 
68  : precision(Precision_64),
69  byteOrder(ByteOrder_LittleEndian),
70  compression(Compression_None),
71  numpress(Numpress_None),
72  numpressFixedPoint(0.0),
73  numpressLinearErrorTolerance(BinaryDataEncoder_default_numpressLinearErrorTolerance),
74  numpressSlofErrorTolerance(BinaryDataEncoder_default_numpressSlofErrorTolerance)
75  {}
76  };
77 
78  BinaryDataEncoder(const Config& config = Config());
79 
80  const Config& getConfig() const; // get the config actually used - may differ from input for numpress use
81 
82  /// encode binary data as a text string
83  void encode(const std::vector<double>& data, std::string& result, size_t* binaryByteCount = NULL) const;
84 
85  /// encode binary data as a text string
86  void encode(const double* data, size_t dataSize, std::string& result, size_t* binaryByteCount = NULL) const;
87 
88  /// decode text-encoded data as binary
89  void decode(const char *encodedData, size_t len, std::vector<double>& result) const;
90  void decode(const std::string& encodedData, std::vector<double>& result) const
91  {
92  decode(encodedData.c_str(),encodedData.length(),result);
93  }
94 
95  private:
96  class Impl;
97  boost::shared_ptr<Impl> impl_;
99  BinaryDataEncoder& operator=(const BinaryDataEncoder&);
100 };
101 
102 
103 PWIZ_API_DECL std::ostream& operator<<(std::ostream& os, const BinaryDataEncoder::Config& config);
104 
105 
106 } // namespace msdata
107 } // namespace pwiz
108 
109 
110 #endif // _BINARYDATAENCODER_HPP_
111 
std::map< cv::CVID, Numpress > numpressOverrides
const double BinaryDataEncoder_default_numpressSlofErrorTolerance
PWIZ_API_DECL std::ostream & operator<<(std::ostream &os, const BinaryDataEncoder::Config &config)
boost::shared_ptr< Impl > impl_
#define PWIZ_API_DECL
Definition: Export.hpp:32
std::map< cv::CVID, Precision > precisionOverrides
encoding/decoding configuration
void decode(const std::string &encodedData, std::vector< double > &result) const
const double BinaryDataEncoder_default_numpressLinearErrorTolerance
const double BinaryDataEncoder_default_numpressPicErrorTolerance