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 not 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
pqxx::binarystring::char_type
unsigned char char_type
Definition: binarystring.hxx:56
pqxx::binarystring::empty
bool empty() const noexcept
Definition: binarystring.hxx:83
pqxx::binarystring::begin
const_iterator begin() const noexcept
Definition: binarystring.hxx:85
pqxx::internal
Private namespace for libpqxx's internal use; do not access.
Definition: connection_base.hxx:43
pqxx::binarystring::rend
const_reverse_iterator rend() const
Definition: binarystring.hxx:97
pqxx::binarystring::const_reference
const value_type & const_reference
Definition: binarystring.hxx:60
pqxx::binarystring::size_type
size_t size_type
Definition: binarystring.hxx:58
pqxx::binarystring::at
const_reference at(size_type) const
Index contained string, checking for valid index.
Definition: binarystring.cxx:122
pqxx::binarystring::value_type
std::char_traits< char_type >::char_type value_type
Definition: binarystring.hxx:57
pqxx::binarystring::operator!=
bool operator!=(const binarystring &rhs) const noexcept
Definition: binarystring.hxx:108
pqxx::binarystring::rbegin
const_reverse_iterator rbegin() const
Definition: binarystring.hxx:94
pqxx::binarystring::end
const_iterator end() const noexcept
Definition: binarystring.hxx:87
pqxx::binarystring::str
std::string str() const
Read as regular C++ string (may include null characters)
Definition: binarystring.cxx:147
pqxx::binarystring::const_iterator
const_pointer const_iterator
Definition: binarystring.hxx:62
pqxx::binarystring::front
const_reference front() const noexcept
Definition: binarystring.hxx:90
pqxx::binarystring::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: binarystring.hxx:63
pqxx::binarystring::crbegin
const_reverse_iterator crbegin() const
Definition: binarystring.hxx:96
pqxx::field
Reference to a field in a result set.
Definition: field.hxx:49
pqxx::binarystring::swap
void swap(binarystring &)
Swap contents with other binarystring.
Definition: binarystring.cxx:136
pqxx::binarystring::binarystring
binarystring(const binarystring &)=default
pqxx::binarystring::size
size_type size() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:80
pqxx::binarystring
Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:53
pqxx::binarystring::operator=
binarystring & operator=(const binarystring &)
Definition: binarystring.cxx:114
pqxx::binarystring::back
const_reference back() const noexcept
Definition: binarystring.hxx:91
pqxx::binarystring::cbegin
const_iterator cbegin() const noexcept
Definition: binarystring.hxx:86
pqxx::binarystring::get
const char * get() const noexcept
Raw character buffer (no terminating zero is added)
Definition: binarystring.hxx:123
pqxx::binarystring::operator==
PQXX_PURE bool operator==(const binarystring &) const noexcept
Definition: binarystring.cxx:107
pqxx::binarystring::operator[]
const_reference operator[](size_type i) const noexcept
Definition: binarystring.hxx:104
pqxx::binarystring::crend
const_reverse_iterator crend() const
Definition: binarystring.hxx:99
pqxx::to_string
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:451
pqxx::binarystring::cend
const_iterator cend() const noexcept
Definition: binarystring.hxx:88
pqxx::binarystring::const_pointer
const value_type * const_pointer
Definition: binarystring.hxx:61
pqxx::binarystring::length
size_type length() const noexcept
Size of converted string in bytes.
Definition: binarystring.hxx:82
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
pqxx::binarystring::data
const value_type * data() const noexcept
Unescaped field contents.
Definition: binarystring.hxx:102
pqxx::binarystring::difference_type
long difference_type
Definition: binarystring.hxx:59