siostream.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <siostream.hpp>
  2. #include <algorithm>
  3. using std::size_t;
  4. socket_ostream::socket_ostream() : std::ostream(), buffer(1024){}
  5. circular_buffer::circular_buffer(size_t size) : m_data(size), m_begin(m_data.data(), size, 0), m_end(m_data.data(), size, 0){
  6. }
  7. circular_buffer::iterator::iterator(char* _source, size_t _period, size_t _offset):source(_source),period(_period), offset(_offset){
  8. }
  9. circular_buffer::const_iterator::const_iterator(const char* _source, size_t _period, size_t _offset):source(_source),period(_period), offset(_offset){
  10. }
  11. void circular_buffer::resize(size_t size){
  12. std::vector<char> newdata(size);
  13. size_t os = m_end - m_begin;
  14. if(size >= (m_begin - m_end))
  15. std::copy(m_begin, m_begin, newdata.begin());
  16. else
  17. std::copy(m_begin, m_begin + size, newdata.begin());
  18. std::swap(m_data, newdata);
  19. m_begin = iterator(m_data.data(),size,0);
  20. m_end = iterator(m_data.data(),size,os);
  21. }
  22. char& circular_buffer::iterator::operator*()const{
  23. return *(source + offset);
  24. }
  25. const char& circular_buffer::const_iterator::operator*()const {
  26. return *(source + offset);
  27. }
  28. circular_buffer::iterator& circular_buffer::iterator::operator++(){
  29. ++offset;
  30. if(offset == size)offset = 0;
  31. return *this;
  32. }
  33. circular_buffer::const_iterator& circular_buffer::const_iterator::operator++(){
  34. }
  35. circular_buffer::iterator circular_buffer::iterator::operator+(size_t leap)const{
  36. }
  37. std::ptrdiff_t circular_buffer::iterator::operator-(const iterator& o)const{
  38. }
  39. std::ptrdiff_t circular_buffer::iterator::operator-(const const_iterator& o)const{
  40. }
  41. std::ptrdiff_t circular_buffer::const_iterator::operator-(const iterator& o)const{
  42. }
  43. std::ptrdiff_t circular_buffer::const_iterator::operator-(const const_iterator& o)const{
  44. }
  45. circular_buffer::const_iterator circular_buffer::const_iterator::operator+(size_t leap)const{
  46. }
  47. circular_buffer::iterator& circular_buffer::iterator::operator=(const circular_buffer::iterator& o){
  48. source = o.source;
  49. period = o.period;
  50. offset = o.offset;
  51. }
  52. circular_buffer::const_iterator& circular_buffer::const_iterator::operator=(const circular_buffer::const_iterator& o){
  53. source = o.source;
  54. period = o.period;
  55. offset = o.offset;
  56. }
  57. circular_buffer::iterator circular_buffer::begin(){
  58. }
  59. circular_buffer::const_iterator circular_buffer::begin() const{
  60. }
  61. circular_buffer::iterator circular_buffer::end(){
  62. }
  63. circular_buffer::const_iterator circular_buffer::end()const{
  64. }
  65. socket_ostream& socket_ostream::put(char_type c){
  66. }
  67. socket_ostream& socket_ostream::operator<<(char*){
  68. }
  69. socket_ostream& socket_ostream::operator<<(const std::string&){
  70. }
  71. socket_ostream& socket_ostream::operator<<(int){
  72. }