binarystring.hxx

00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/binarystring.hxx
00005  *
00006  *   DESCRIPTION
00007  *      Representation for raw, binary data.
00008  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead.
00009  *
00010  * Copyright (c) 2003-2015, Jeroen T. Vermeulen <jtv@xs4all.nl>
00011  *
00012  * See COPYING for copyright license.  If you did not receive a file called
00013  * COPYING with this source code, please notify the distributor of this mistake,
00014  * or contact the author.
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef PQXX_H_BINARYSTRING
00019 #define PQXX_H_BINARYSTRING
00020 
00021 #include "pqxx/compiler-public.hxx"
00022 #include "pqxx/compiler-internal-pre.hxx"
00023 
00024 #include <string>
00025 
00026 #include "pqxx/result"
00027 
00028 
00029 namespace pqxx
00030 {
00031 
00033 
00059 class PQXX_LIBEXPORT binarystring
00060 {
00061 public:
00062   typedef unsigned char char_type;
00063   typedef std::char_traits<char_type>::char_type value_type;
00064   typedef size_t size_type;
00065   typedef long difference_type;
00066   typedef const value_type &const_reference;
00067   typedef const value_type *const_pointer;
00068   typedef const_pointer const_iterator;
00069   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
00070 
00071 public:
00072   binarystring(const binarystring &);
00073 
00075 
00078   explicit binarystring(const field &);                                 //[t62]
00079 
00081   explicit binarystring(const std::string &);
00082 
00084   binarystring(const void *, size_t);
00085 
00086   ~binarystring() { delete &m_buf; }
00087 
00089   size_type size() const PQXX_NOEXCEPT { return m_size; }               //[t62]
00091   size_type length() const PQXX_NOEXCEPT { return size(); }             //[t62]
00092   bool empty() const PQXX_NOEXCEPT { return size()==0; }                //[t62]
00093 
00094   const_iterator begin() const PQXX_NOEXCEPT { return data(); }         //[t62]
00095   const_iterator cbegin() const PQXX_NOEXCEPT { return begin(); }
00096   const_iterator end() const PQXX_NOEXCEPT { return data()+m_size; }    //[t62]
00097   const_iterator cend() const PQXX_NOEXCEPT { return end(); }
00098 
00099   const_reference front() const PQXX_NOEXCEPT { return *begin(); }      //[t62]
00100   const_reference back() const PQXX_NOEXCEPT                            //[t62]
00101         { return *(data()+m_size-1); }
00102 
00103   const_reverse_iterator rbegin() const                                 //[t62]
00104         { return const_reverse_iterator(end()); }
00105   const_reverse_iterator crbegin() const { return rbegin(); }
00106   const_reverse_iterator rend() const                                   //[t62]
00107         { return const_reverse_iterator(begin()); }
00108   const_reverse_iterator crend() const { return rend(); }
00109 
00111   const value_type *data() const PQXX_NOEXCEPT {return m_buf.get();}    //[t62]
00112 
00113   const_reference operator[](size_type i) const PQXX_NOEXCEPT           //[t62]
00114         { return data()[i]; }
00115 
00116   PQXX_PURE bool operator==(const binarystring &) const PQXX_NOEXCEPT;  //[t62]
00117   bool operator!=(const binarystring &rhs) const PQXX_NOEXCEPT          //[t62]
00118         { return !operator==(rhs); }
00119 
00120   binarystring &operator=(const binarystring &);
00121 
00123   const_reference at(size_type) const;                                  //[t62]
00124 
00126   void swap(binarystring &);                                            //[t62]
00127 
00129 
00132   const char *get() const PQXX_NOEXCEPT                                 //[t62]
00133                         { return reinterpret_cast<const char *>(m_buf.get()); }
00134 
00136 
00142   std::string str() const;                                              //[t62]
00143 
00144 private:
00145   typedef internal::PQAlloc<
00146         value_type,
00147         pqxx::internal::freemallocmem_templated<unsigned char> >
00148     smart_pointer_type;
00149 
00150   /* Using a reference to a smart pointer.  It's wasteful, but it hides the
00151    * different implementations of PQAlloc: the compiler needs to know PQAlloc's
00152    * memory layout in order to include an instance inside binarystring.
00153    * Once shared_ptr is widespread enough, we can just have a shared_ptr and
00154    * forget about PQAlloc altogether.
00155    */
00156   smart_pointer_type &m_buf;
00157   size_type m_size;
00158 };
00159 }
00160 
00161 #include "pqxx/compiler-internal-post.hxx"
00162 
00163 #endif

Generated on 17 Mar 2017 for libpqxx by  doxygen 1.6.1