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