binary.h
Go to the documentation of this file.
1 #ifndef BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
7 
8 #include <string>
9 #include <vector>
10 
11 namespace YAML_PM
12 {
13  class Node;
14 
15  std::string EncodeBase64(const unsigned char *data, std::size_t size);
16  std::vector<unsigned char> DecodeBase64(const std::string& input);
17 
18  class Binary {
19  public:
21  Binary(const unsigned char *data, std::size_t size): m_unownedData(data), m_unownedSize(size) {}
22 
23  bool owned() const { return !m_unownedData; }
24  std::size_t size() const { return owned() ? m_data.size() : m_unownedSize; }
25  const unsigned char *data() const { return owned() ? &m_data[0] : m_unownedData; }
26 
27  void swap(std::vector<unsigned char>& rhs) {
28  if(m_unownedData) {
29  m_data.swap(rhs);
30  rhs.clear();
31  rhs.resize(m_unownedSize);
32  std::copy(m_unownedData, m_unownedData + m_unownedSize, &rhs[0]);
33  m_unownedData = 0;
34  m_unownedSize = 0;
35  } else {
36  m_data.swap(rhs);
37  }
38  }
39 
40  bool operator == (const Binary& rhs) const {
41  const std::size_t s = size();
42  if(s != rhs.size())
43  return false;
44  const unsigned char *d1 = data();
45  const unsigned char *d2 = rhs.data();
46  for(std::size_t i=0;i<s;i++) {
47  if(*d1++ != *d2++)
48  return false;
49  }
50  return true;
51  }
52 
53  bool operator != (const Binary& rhs) const {
54  return !(*this == rhs);
55  }
56 
57  private:
58  std::vector<unsigned char> m_data;
59  const unsigned char *m_unownedData;
60  std::size_t m_unownedSize;
61  };
62 
63  void operator >> (const Node& node, Binary& binary);
64 }
65 
66 #endif // BASE64_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
std::size_t m_unownedSize
Definition: binary.h:60
std::vector< unsigned char > DecodeBase64(const std::string &input)
Definition: binary.cpp:66
bool owned() const
Definition: binary.h:23
::std::string string
Definition: gtest.h:1979
data
Definition: icp.py:50
std::vector< unsigned char > m_data
Definition: binary.h:58
const unsigned char * m_unownedData
Definition: binary.h:59
void operator>>(const Node &node, Binary &binary)
Definition: binary.cpp:95
std::size_t size() const
Definition: binary.h:24
bool operator!=(const Binary &rhs) const
Definition: binary.h:53
bool operator==(const Binary &rhs) const
Definition: binary.h:40
std::string EncodeBase64(const unsigned char *data, std::size_t size)
Definition: binary.cpp:8
void swap(std::vector< unsigned char > &rhs)
Definition: binary.h:27
const unsigned char * data() const
Definition: binary.h:25
Binary(const unsigned char *data, std::size_t size)
Definition: binary.h:21


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:36:30