• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

buffer.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 //
00018 
00019 #ifndef __BUFFER_H__
00020 #define __BUFFER_H__ 1
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025 
00026 #include <vector>
00027 #include <boost/cstdint.hpp>
00028 #include <boost/scoped_array.hpp>
00029 #include <boost/shared_ptr.hpp>
00030 #include <iostream> // for output operator
00031 #include <string>
00032 
00033 #include "getclocktime.hpp"
00034 #include "amf.h"
00035 #include "element.h"
00036 #include "dsodefs.h"
00037 
00038 // _definst_ is the default instance name
00039 
00043 namespace cygnal
00044 {
00045 
00046 // Adjust for the constant size
00047 const size_t NETBUFSIZE = 1448; // 1500 appears to be the default size as used by FMS
00048 //const size_t NETBUFSIZE = 1357*2;     // 1500 appears to be the default size as used by FMS
00049 
00056 class DSOEXPORT Buffer 
00057 {
00058 public:
00060     Buffer();
00062     Buffer(size_t nbytes);
00063 
00069     Buffer(const std::string &str);
00070 
00072     ~Buffer();
00073 
00081     int corrupt();
00082     int corrupt(int factor);
00083     
00092     Buffer &hex2mem(const std::string &str);
00093 
00105     std::string hexify();
00106     std::string hexify(bool ascii);
00107     std::string hexify(Buffer &buf, bool ascii);
00108     
00113     void clear();
00114     
00118     bool empty() { return (_seekptr) ? false : true; };
00119 
00129     Buffer &resize();
00139     Buffer &resize(size_t nbytes);
00140 
00150     Buffer &copy(boost::uint8_t *data, size_t nbytes);
00151     
00158     Buffer &operator=(Buffer &buf);
00159     Buffer &operator=(boost::shared_ptr<Buffer>& buf);
00167     Buffer &operator=(const std::string &str);
00168     Buffer &operator=(const char *str);
00175     Buffer &operator=(double num);
00182     Buffer &operator=(boost::uint16_t length);
00189     Buffer &operator=(boost::uint8_t byte);
00196     Buffer &operator=(boost::uint8_t *byte);
00203     Buffer &operator=(cygnal::Element::amf0_type_e type);
00210     Buffer &operator=(bool flag);
00211     
00220     Buffer &append(boost::uint8_t *data, size_t nbytes);
00221 
00227     Buffer &operator+=(Buffer &buf);
00228     Buffer &operator+=(boost::shared_ptr<Buffer> &buf);
00229 
00236     Buffer &operator+=(const std::string &str);
00237     Buffer &operator+=(const char *str);
00243     Buffer &operator+=(double num);
00244 
00250     Buffer &operator+=(boost::uint32_t length);
00256     Buffer &operator+=(boost::uint16_t length);
00262     Buffer &operator+=(boost::uint8_t byte);
00263     Buffer &operator+=(char byte);
00269     Buffer &operator+=(cygnal::Element::amf0_type_e type);
00275     Buffer &operator+=(bool);
00276     
00285     boost::uint8_t *remove(boost::uint8_t c);
00295     boost::uint8_t *remove(int index);
00310     boost::uint8_t *remove(int start, int range);
00311 //    Network::byte_t *remove(char c);
00312     
00316     boost::uint8_t *begin() { return _data.get() ; };
00317     boost::uint8_t *reference() { return _data.get(); }
00318     const boost::uint8_t *reference() const { return _data.get(); }
00319 
00325     boost::uint8_t *end() { return _seekptr; };
00326 
00330     size_t size() { return _nbytes; }
00331     
00341     void setSize(size_t nbytes) { _nbytes = nbytes; };
00342 
00344     void setPointer(boost::uint8_t *ptr) { _data.reset(ptr); };
00345     
00354     bool operator==(Buffer &buf);
00355 
00362     boost::uint8_t operator[](int index) { return _data[index]; };
00363 
00370     boost::uint8_t *at(int index) { return _data.get() + index; };
00371 
00377     size_t spaceLeft() { return (_nbytes - (_seekptr - _data.get())); };
00378     
00384     size_t allocated() { return (_seekptr - _data.get()); };
00385 
00391     void setSeekPointer(boost::uint8_t *ptr) { _seekptr = ptr; };
00392     void setSeekPointer(off_t offset) { _seekptr = _data.get() + offset; };
00393     
00396     void dump() const { dump(std::cerr); }
00398     void dump(std::ostream& os) const;
00399     
00400   protected:
00404     boost::uint8_t *_seekptr;
00405     
00409     boost::scoped_array<boost::uint8_t> _data;
00410     
00413     size_t         _nbytes;
00418 #ifdef USE_STATS_BUFFERS
00419     struct timespec _stamp;     // used for timing how long data stays in the queue.
00420 #endif
00421     
00422   private:
00430     Buffer &init(size_t nbytes);
00431     
00437     boost::uint8_t hex2digit (boost::uint8_t digit);
00438 };
00439 
00441 inline std::ostream& operator << (std::ostream& os, const Buffer& buf)
00442 {
00443         buf.dump(os);
00444         return os;
00445 }
00446 
00447 } // end of namespace cygnal
00448 
00449 #endif // end of __BUFFER_H__
00450 
00451 // local Variables:
00452 // mode: C++
00453 // indent-tabs-mode: nil
00454 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1