Changeset 138 for trunk


Ignore:
Timestamp:
06/29/13 19:02:04 (12 years ago)
Author:
epyon
Message:
  • io/std_stream - PROPER std_stream implementation
  • io/std_stream - got rid of memmove
  • formats/obj_loader - no copy on read, properly streamed
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/io/std_stream.hh

    r134 r138  
    1616#include <nv/interface/stream.hh>
    1717#include <streambuf>
     18#include <istream>
    1819#include <vector>
    1920
    2021namespace nv
    2122{
    22         class std_stream : public std::streambuf
     23
     24        class std_streambuf : public std::streambuf
    2325        {
    2426        public:
    25                 explicit std_stream( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 );
    26                 ~std_stream();
     27                explicit std_streambuf( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 );
     28                virtual ~std_streambuf();
    2729        protected:
    2830                stream*           m_stream;
     
    3133                std::size_t       m_put_back;
    3234        private:
    33                 std_stream( const std_stream& );             // dissalow copy
    34                 std_stream *operator =( const std_stream& ); // dissalow assign
     35                std_streambuf( const std_streambuf& );             // dissalow copy
     36                std_streambuf *operator =( const std_streambuf& ); // dissalow assign
    3537                int_type underflow();
     38        };
     39
     40        class std_stream : public std::istream
     41        {
     42        public:
     43                explicit std_stream( stream* source, bool owner = false, std::size_t bsize = 256, std::size_t put_back = 8 )
     44                        : std::istream( &m_streambuf )
     45                        , m_streambuf( source, owner, bsize, put_back )
     46                {}
     47        private:
     48                std_streambuf m_streambuf;
    3649        };
    3750
  • trunk/src/formats/obj_loader.cc

    r136 r138  
    66
    77#include "nv/formats/obj_loader.hh"
     8#include "nv/io/std_stream.hh"
    89#include <sstream>
    910
     
    187188        m_mesh = new mesh();
    188189        mesh_obj_reader reader( m_mesh );
    189         size_t size = source.size();
    190         char* data  = new char[ size ];
    191         source.read( data, 1, size );
    192         std::string cache( data, size );
    193         std::istringstream sstream( cache );
     190        std_stream sstream( &source );
    194191        reader.read_stream( sstream );
    195192        m_size = reader.size;
  • trunk/src/io/std_stream.cc

    r135 r138  
    99#include "nv/io/std_stream.hh"
    1010#include <algorithm>
    11 #include <cstring> // TODO: remove, see below
    1211
    1312using namespace nv;
    1413
    15 std_stream::std_stream( stream* source, bool owner /*= false*/, std::size_t bsize /*= 256*/, std::size_t put_back /*= 8 */ )
     14std_streambuf::std_streambuf( stream* source, bool owner /*= false*/, std::size_t bsize /*= 256*/, std::size_t put_back /*= 8 */ )
    1615        : m_stream( source )
    1716        , m_owner( owner )
     
    2322}
    2423
    25 std_stream::~std_stream()
     24std_streambuf::~std_streambuf()
    2625{
    2726        if ( m_owner )
     
    3130}
    3231
    33 std_stream::int_type std_stream::underflow()
     32std_streambuf::int_type std_streambuf::underflow()
    3433{
    3534        if (gptr() < egptr())
     
    4544        {
    4645                // Make arrangements for putback characters
    47                 // TODO: std::copy( egptr() - m_put_back, egptr(), base ); instead?
    48                 std::memmove(base, egptr() - m_put_back, m_put_back);
     46                std::copy( egptr() - m_put_back, egptr(), base );
    4947                start += m_put_back;
    5048        }
Note: See TracChangeset for help on using the changeset viewer.