binarystring.hxx

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/binarystring.hxx
00005  *
00006  *   DESCRIPTION
00007  *      declarations for bytea (binary string) conversions
00008  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/binarystring instead.
00009  *
00010  * Copyright (c) 2003-2008, 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 
00060 class PQXX_LIBEXPORT binarystring : internal::PQAlloc<unsigned char>
00061 {
00062   // TODO: Templatize on character type?
00063 public:
00064   typedef content_type char_type;
00065   typedef PGSTD::char_traits<char_type>::char_type value_type;
00066   typedef size_t size_type;
00067   typedef long difference_type;
00068   typedef const value_type &const_reference;
00069   typedef const value_type *const_pointer;
00070   typedef const_pointer const_iterator;
00071 
00072 #ifdef PQXX_HAVE_REVERSE_ITERATOR
00073   typedef PGSTD::reverse_iterator<const_iterator> const_reverse_iterator;
00074 #endif
00075 
00076 private:
00077   typedef internal::PQAlloc<value_type> super;
00078 
00079 public:
00081 
00084   explicit binarystring(const result::field &F);                        //[t62]
00085 
00087   size_type size() const throw () { return m_size; }                    //[t62]
00089   size_type length() const throw () { return size(); }                  //[t62]
00090   bool empty() const throw () { return size()==0; }                     //[t62]
00091 
00092   const_iterator begin() const throw () { return data(); }              //[t62]
00093   const_iterator end() const throw () { return data()+m_size; }         //[t62]
00094 
00095   const_reference front() const throw () { return *begin(); }           //[t62]
00096   const_reference back() const throw () { return *(data()+m_size-1); }  //[t62]
00097 
00098 #ifdef PQXX_HAVE_REVERSE_ITERATOR
00099   const_reverse_iterator rbegin() const                                 //[t62]
00100         { return const_reverse_iterator(end()); }
00101   const_reverse_iterator rend() const                                   //[t62]
00102         { return const_reverse_iterator(begin()); }
00103 #endif
00104 
00106   const value_type *data() const throw () {return super::c_ptr();}      //[t62]
00107 
00108   const_reference operator[](size_type i) const throw ()                //[t62]
00109         { return data()[i]; }
00110 
00111   bool operator==(const binarystring &) const throw ();                 //[t62]
00112   bool operator!=(const binarystring &rhs) const throw ()               //[t62]
00113         { return !operator==(rhs); }
00114 
00116   const_reference at(size_type) const;                                  //[t62]
00117 
00119   void swap(binarystring &);                                            //[t62]
00120 
00122 
00125   const char *c_ptr() const throw ()                                    //[t62]
00126   {
00127     return reinterpret_cast<char *>(super::c_ptr());
00128   }
00129 
00131 
00138   const PGSTD::string &str() const;                                     //[t62]
00139 
00140 private:
00141   size_type m_size;
00142   mutable PGSTD::string m_str;
00143 };
00144 
00145 
00152 
00153 
00157 PGSTD::string PQXX_LIBEXPORT escape_binary(const PGSTD::string &bin);
00159 
00163 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[]);
00165 
00169 PGSTD::string PQXX_LIBEXPORT escape_binary(const char bin[], size_t len);
00171 
00175 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[]);
00177 
00181 PGSTD::string PQXX_LIBEXPORT escape_binary(const unsigned char bin[], size_t len);
00182 
00188 }
00189 
00190 #include "pqxx/compiler-internal-post.hxx"
00191 
00192 #endif
00193 

Generated on Sun Nov 2 08:25:40 2008 for libpqxx by  doxygen 1.5.5