libpqxx
binarystring.hxx
1 
11 #ifndef PQXX_H_BINARYSTRING
12 #define PQXX_H_BINARYSTRING
13 
14 #include "pqxx/compiler-public.hxx"
15 #include "pqxx/compiler-internal-pre.hxx"
16 
17 #include <memory>
18 #include <string>
19 
20 #include "pqxx/result.hxx"
21 
22 
23 namespace pqxx
24 {
25 
27 
53 class PQXX_LIBEXPORT binarystring
54 {
55 public:
56  using char_type = unsigned char;
57  using value_type = std::char_traits<char_type>::char_type;
58  using size_type = size_t;
59  using difference_type = long;
60  using const_reference = const value_type &;
61  using const_pointer = const value_type *;
63  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
64 
65  binarystring(const binarystring &) =default;
66 
68 
71  explicit binarystring(const field &); //[t62]
72 
74  explicit binarystring(const std::string &);
75 
77  binarystring(const void *, size_t);
78 
80  size_type size() const noexcept { return m_size; } //[t62]
82  size_type length() const noexcept { return size(); } //[t62]
83  bool empty() const noexcept { return size()==0; } //[t62]
84 
85  const_iterator begin() const noexcept { return data(); } //[t62]
86  const_iterator cbegin() const noexcept { return begin(); }
87  const_iterator end() const noexcept { return data()+m_size; } //[t62]
88  const_iterator cend() const noexcept { return end(); }
89 
90  const_reference front() const noexcept { return *begin(); } //[t62]
91  const_reference back() const noexcept //[t62]
92  { return *(data()+m_size-1); }
93 
95  { return const_reverse_iterator(end()); }
96  const_reverse_iterator crbegin() const { return rbegin(); }
97  const_reverse_iterator rend() const //[t62]
98  { return const_reverse_iterator(begin()); }
99  const_reverse_iterator crend() const { return rend(); }
100 
102  const value_type *data() const noexcept {return m_buf.get();} //[t62]
103 
104  const_reference operator[](size_type i) const noexcept //[t62]
105  { return data()[i]; }
106 
107  PQXX_PURE bool operator==(const binarystring &) const noexcept; //[t62]
108  bool operator!=(const binarystring &rhs) const noexcept //[t62]
109  { return !operator==(rhs); }
110 
111  binarystring &operator=(const binarystring &);
112 
114  const_reference at(size_type) const; //[t62]
115 
117  void swap(binarystring &); //[t62]
118 
120 
123  const char *get() const noexcept //[t62]
124  { return reinterpret_cast<const char *>(m_buf.get()); }
125 
127 
133  std::string str() const; //[t62]
134 
135 private:
136  using smart_pointer_type = std::shared_ptr<value_type>;
137 
139  static smart_pointer_type make_smart_pointer(unsigned char *buf=nullptr)
140  {
141  return smart_pointer_type(
142  buf,
143  internal::freemallocmem_templated<unsigned char>);
144  }
145 
146  smart_pointer_type m_buf;
147  size_type m_size;
148 };
149 }
150 
151 #include "pqxx/compiler-internal-post.hxx"
152 
153 #endif
const_reverse_iterator rbegin() const
Definition: binarystring.hxx:94
Binary data corresponding to PostgreSQL&#39;s "BYTEA" binary-string type.
Definition: binarystring.hxx:53
const_pointer const_iterator
Definition: binarystring.hxx:62
size_type length() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:82
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: binarystring.hxx:63
bool empty() const noexcept
Definition: binarystring.hxx:83
const_iterator begin() const noexcept
Definition: binarystring.hxx:85
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
const_reference operator[](size_type i) const noexcept
Definition: binarystring.hxx:104
const value_type * const_pointer
Definition: binarystring.hxx:61
std::char_traits< char_type >::char_type value_type
Definition: binarystring.hxx:57
const_reference front() const noexcept
Definition: binarystring.hxx:90
const_reference back() const noexcept
Definition: binarystring.hxx:91
long difference_type
Definition: binarystring.hxx:59
const_iterator cend() const noexcept
Definition: binarystring.hxx:88
const value_type * data() const noexcept
Unescaped field contents.
Definition: binarystring.hxx:102
size_t size_type
Definition: binarystring.hxx:58
size_type size() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:80
bool operator!=(const binarystring &rhs) const noexcept
Definition: binarystring.hxx:108
const value_type & const_reference
Definition: binarystring.hxx:60
const_reverse_iterator crend() const
Definition: binarystring.hxx:99
unsigned char char_type
Definition: binarystring.hxx:56
const_reverse_iterator rend() const
Definition: binarystring.hxx:97
const_reverse_iterator crbegin() const
Definition: binarystring.hxx:96
const_iterator end() const noexcept
Definition: binarystring.hxx:87
const_iterator cbegin() const noexcept
Definition: binarystring.hxx:86
Reference to a field in a result set.
Definition: field.hxx:41