00001 // -*- c++ -*- 00002 //------------------------------------------------------------------------------ 00003 // xdrIOBuffer.h 00004 //------------------------------------------------------------------------------ 00005 // Copyright (c) 2000,2005 by Vladislav Grinchenko 00006 // 00007 // This library is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU Library General Public 00009 // License as published by the Free Software Foundation; either 00010 // version 2 of the License, or (at your option) any later version. 00011 //------------------------------------------------------------------------------ 00012 // Created: 04/03/2000 00013 //------------------------------------------------------------------------------ 00014 00015 #ifndef XDR_IO_BUFFER_H 00016 #define XDR_IO_BUFFER_H 00017 00018 #include "assa/Assure.h" 00019 #include "assa/Socket.h" 00020 #include "assa/IPv4Socket.h" 00021 00022 #include <string> 00023 00024 namespace ASSA { 00025 00055 class xdrIOBuffer 00056 { 00057 public: 00060 enum state_t { 00061 waiting, 00062 xmitted, 00063 parsed, 00064 error 00065 }; 00066 00069 xdrIOBuffer (u_int len_); 00070 00073 ~xdrIOBuffer (); 00074 00077 xdrIOBuffer (const xdrIOBuffer& rhs_); 00078 00081 xdrIOBuffer& operator= (const xdrIOBuffer& rhs_); 00082 00086 friend Socket& operator>>(Socket& src_, xdrIOBuffer& dest_); 00087 00090 xdrIOBuffer& operator>>(std::string&); 00091 00094 xdrIOBuffer& operator>>(int&); 00095 00098 xdrIOBuffer& operator>>(float&); 00099 00102 operator void*() const; 00103 00106 string get_state () const; 00107 00112 int size () const; 00113 00116 int buffer_size () const; 00117 00120 const char* str () const; 00121 00125 void reset (); 00126 00129 void dump () const; 00130 00131 protected: 00133 void copy (const xdrIOBuffer&); 00134 00135 private: 00137 char* m_buf; 00138 00140 int m_sz; 00141 00143 char* m_ptr; 00144 00146 state_t m_state; 00147 }; 00148 00149 inline 00150 xdrIOBuffer:: 00151 xdrIOBuffer (const xdrIOBuffer& rhs_) 00152 { 00153 trace_with_mask("xdrIOBuffer::xdrIOBuffer(xdrIOBuffer&)", XDRBUFTRACE); 00154 00155 copy (rhs_); 00156 } 00157 00158 inline 00159 xdrIOBuffer:: 00160 operator void*() const 00161 { 00162 trace_with_mask("xdrIOBuffer::opt void*()", XDRBUFTRACE); 00163 00164 return (m_state == waiting || m_state == parsed) 00165 ? (void *)0 // bad state 00166 : (void *)(-1); // good state 00167 } 00168 00169 inline int 00170 xdrIOBuffer:: 00171 size () const 00172 { 00173 return (m_ptr - m_buf); 00174 } 00175 00176 inline int 00177 xdrIOBuffer:: 00178 buffer_size () const 00179 { 00180 return (m_sz); 00181 } 00182 00183 inline const char* 00184 xdrIOBuffer:: 00185 str () const 00186 { 00187 return ((const char*) m_buf); 00188 } 00189 00190 } // end namespace ASSA 00191 00192 #endif /* XDR_IO_BUFFER_H */