Merge changes from trunk. Fix bugs and warnings under gcc 4.3.2.

2.0
castano 16 years ago
parent bd7013a37b
commit 92f76113e5

@ -47,25 +47,25 @@ public:
/** @name Stream implementation. */ /** @name Stream implementation. */
//@{ //@{
virtual void seek( int pos ) virtual void seek( uint pos )
{ {
nvDebugCheck(m_fp != NULL); nvDebugCheck(m_fp != NULL);
nvDebugCheck(pos >= 0 && pos < size()); nvDebugCheck(pos < size());
fseek(m_fp, pos, SEEK_SET); fseek(m_fp, pos, SEEK_SET);
} }
virtual int tell() const virtual uint tell() const
{ {
nvDebugCheck(m_fp != NULL); nvDebugCheck(m_fp != NULL);
return ftell(m_fp); return ftell(m_fp);
} }
virtual int size() const virtual uint size() const
{ {
nvDebugCheck(m_fp != NULL); nvDebugCheck(m_fp != NULL);
int pos = ftell(m_fp); uint pos = ftell(m_fp);
fseek(m_fp, 0, SEEK_END); fseek(m_fp, 0, SEEK_END);
int end = ftell(m_fp); uint end = ftell(m_fp);
fseek(m_fp, pos, SEEK_SET); fseek(m_fp, pos, SEEK_SET);
return end; return end;
} }
@ -117,11 +117,11 @@ public:
/** @name Stream implementation. */ /** @name Stream implementation. */
//@{ //@{
/// Write data. /// Write data.
virtual void serialize( void * data, int len ) virtual uint serialize( void * data, uint len )
{ {
nvDebugCheck(data != NULL); nvDebugCheck(data != NULL);
nvDebugCheck(m_fp != NULL); nvDebugCheck(m_fp != NULL);
fwrite(data, len, 1, m_fp); return (uint)fwrite(data, 1, len, m_fp);
} }
virtual bool isLoading() const virtual bool isLoading() const
@ -156,11 +156,11 @@ public:
/** @name Stream implementation. */ /** @name Stream implementation. */
//@{ //@{
/// Read data. /// Read data.
virtual void serialize( void * data, int len ) virtual uint serialize( void * data, uint len )
{ {
nvDebugCheck(data != NULL); nvDebugCheck(data != NULL);
nvDebugCheck(m_fp != NULL); nvDebugCheck(m_fp != NULL);
fread(data, len, 1, m_fp); return (uint)fread(data, 1, len, m_fp);
} }
virtual bool isLoading() const virtual bool isLoading() const
@ -184,33 +184,40 @@ class NVCORE_CLASS MemoryInputStream : public Stream
public: public:
/// Ctor. /// Ctor.
MemoryInputStream( const uint8 * mem, int size ) : MemoryInputStream( const uint8 * mem, uint size ) :
m_mem(mem), m_ptr(mem), m_size(size) { } m_mem(mem), m_ptr(mem), m_size(size) { }
/** @name Stream implementation. */ /** @name Stream implementation. */
//@{ //@{
/// Read data. /// Read data.
virtual void serialize( void * data, int len ) virtual uint serialize( void * data, uint len )
{ {
nvDebugCheck(data != NULL); nvDebugCheck(data != NULL);
nvDebugCheck(!isError()); nvDebugCheck(!isError());
uint left = m_size - tell();
if (len > left) len = left;
memcpy( data, m_ptr, len ); memcpy( data, m_ptr, len );
m_ptr += len; m_ptr += len;
return len;
} }
virtual void seek( int pos ) virtual void seek( uint pos )
{ {
nvDebugCheck(!isError()); nvDebugCheck(!isError());
m_ptr = m_mem + pos; m_ptr = m_mem + pos;
nvDebugCheck(!isError()); nvDebugCheck(!isError());
} }
virtual int tell() const virtual uint tell() const
{ {
return int(m_ptr - m_mem); nvDebugCheck(m_ptr >= m_mem);
return uint(m_ptr - m_mem);
} }
virtual int size() const virtual uint size() const
{ {
return m_size; return m_size;
} }
@ -252,7 +259,7 @@ private:
const uint8 * m_mem; const uint8 * m_mem;
const uint8 * m_ptr; const uint8 * m_ptr;
int m_size; uint m_size;
}; };
@ -286,17 +293,19 @@ public:
/** @name Stream implementation. */ /** @name Stream implementation. */
//@{ //@{
/// Read data. /// Read data.
virtual void serialize( void * data, int len ) virtual uint serialize( void * data, uint len )
{ {
nvDebugCheck(data != NULL); nvDebugCheck(data != NULL);
m_s->serialize( data, len ); len = m_s->serialize( data, len );
if( m_s->isError() ) { if( m_s->isError() ) {
throw std::exception(); throw std::exception();
} }
return len;
} }
virtual void seek( int pos ) virtual void seek( uint pos )
{ {
m_s->seek( pos ); m_s->seek( pos );
@ -305,12 +314,12 @@ public:
} }
} }
virtual int tell() const virtual uint tell() const
{ {
return m_s->tell(); return m_s->tell();
} }
virtual int size() const virtual uint size() const
{ {
return m_s->size(); return m_s->size();
} }

@ -209,48 +209,11 @@ StringBuilder::StringBuilder( const StringBuilder & s ) : m_size(0), m_str(NULL)
} }
/** Copy string. */ /** Copy string. */
StringBuilder::StringBuilder( const char * s ) StringBuilder::StringBuilder( const char * s ) : m_size(0), m_str(NULL)
{ {
copy(s); copy(s);
} }
/** Allocate and copy string. */
StringBuilder::StringBuilder( int size_hint, const StringBuilder & s) : m_size(size_hint), m_str(NULL)
{
nvDebugCheck(m_size > 0);
m_str = strAlloc(m_size);
copy(s);
}
/** Allocate and format string. */
StringBuilder::StringBuilder( const char * fmt, ... ) : m_size(0), m_str(NULL)
{
nvDebugCheck(fmt != NULL);
va_list arg;
va_start( arg, fmt );
format( fmt, arg );
va_end( arg );
}
/** Allocate and format string. */
StringBuilder::StringBuilder( int size_hint, const char * fmt, ... ) : m_size(size_hint), m_str(NULL)
{
nvDebugCheck(m_size > 0);
nvDebugCheck(fmt != NULL);
m_str = strAlloc(m_size);
va_list arg;
va_start( arg, fmt );
format( fmt, arg );
va_end( arg );
}
/** Delete the string. */ /** Delete the string. */
StringBuilder::~StringBuilder() StringBuilder::~StringBuilder()
{ {
@ -278,8 +241,7 @@ StringBuilder & StringBuilder::format( const char * fmt, ... )
/** Format a string safely. */ /** Format a string safely. */
StringBuilder & StringBuilder::format( const char * fmt, va_list arg ) StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
{ {
nvCheck(fmt != NULL); nvDebugCheck(fmt != NULL);
nvCheck(m_size >= 0);
if( m_size == 0 ) { if( m_size == 0 ) {
m_size = 64; m_size = 64;
@ -327,8 +289,7 @@ StringBuilder & StringBuilder::format( const char * fmt, va_list arg )
/** Append a string. */ /** Append a string. */
StringBuilder & StringBuilder::append( const char * s ) StringBuilder & StringBuilder::append( const char * s )
{ {
nvCheck(s != NULL); nvDebugCheck(s != NULL);
nvCheck(m_size >= 0);
const uint slen = uint(strlen( s )); const uint slen = uint(strlen( s ));
@ -475,31 +436,6 @@ void StringBuilder::reset()
} }
Path::Path(const char * fmt, ...)
{
nvDebugCheck( fmt != NULL );
va_list arg;
va_start( arg, fmt );
format( fmt, arg );
va_end( arg );
}
Path::Path(int size_hint, const char * fmt, ...) : StringBuilder(size_hint)
{
nvDebugCheck( fmt != NULL );
va_list arg;
va_start( arg, fmt );
format( fmt, arg );
va_end( arg );
}
/// Get the file name from a path. /// Get the file name from a path.
const char * Path::fileName() const const char * Path::fileName() const
{ {

@ -47,9 +47,6 @@ namespace nv
explicit StringBuilder( int size_hint ); explicit StringBuilder( int size_hint );
StringBuilder( const char * str ); StringBuilder( const char * str );
StringBuilder( const StringBuilder & ); StringBuilder( const StringBuilder & );
StringBuilder( int size_hint, const StringBuilder & );
StringBuilder( const char * format, ... ) __attribute__((format (printf, 2, 3)));
StringBuilder( int size_hint, const char * format, ... ) __attribute__((format (printf, 3, 4)));
~StringBuilder(); ~StringBuilder();
@ -120,18 +117,16 @@ namespace nv
char * m_str; char * m_str;
}; };
/// Path string.
/// Path string. @@ This should be called PathBuilder.
class NVCORE_CLASS Path : public StringBuilder class NVCORE_CLASS Path : public StringBuilder
{ {
public: public:
Path() : StringBuilder() {} Path() : StringBuilder() {}
explicit Path(int size_hint) : StringBuilder(size_hint) {} explicit Path(int size_hint) : StringBuilder(size_hint) {}
Path(const StringBuilder & str) : StringBuilder(str) {} Path(const char * str) : StringBuilder(str) {}
Path(int size_hint, const StringBuilder & str) : StringBuilder(size_hint, str) {} Path(const Path & path) : StringBuilder(path) {}
Path(const char * format, ...) __attribute__((format (printf, 2, 3)));
Path(int size_hint, const char * format, ...) __attribute__((format (printf, 3, 4)));
const char * fileName() const; const char * fileName() const;
const char * extension() const; const char * extension() const;
@ -140,11 +135,11 @@ namespace nv
void stripFileName(); void stripFileName();
void stripExtension(); void stripExtension();
// statics // statics
NVCORE_API static char separator(); static char separator();
NVCORE_API static const char * fileName(const char *); static const char * fileName(const char *);
NVCORE_API static const char * extension(const char *); static const char * extension(const char *);
}; };

@ -41,17 +41,17 @@ public:
ByteOrder byteOrder() const { return m_byteOrder; } ByteOrder byteOrder() const { return m_byteOrder; }
/// Serialize the given data. @@ Should return bytes serialized? /// Serialize the given data.
virtual void serialize( void * data, int len ) = 0; virtual uint serialize( void * data, uint len ) = 0;
/// Move to the given position in the archive. /// Move to the given position in the archive.
virtual void seek( int pos ) = 0; virtual void seek( uint pos ) = 0;
/// Return the current position in the archive. /// Return the current position in the archive.
virtual int tell() const = 0; virtual uint tell() const = 0;
/// Return the current size of the archive. /// Return the current size of the archive.
virtual int size() const = 0; virtual uint size() const = 0;
/// Determine if there has been any error. /// Determine if there has been any error.
virtual bool isError() const = 0; virtual bool isError() const = 0;
@ -136,13 +136,13 @@ public:
protected: protected:
/// Serialize in the stream byte order. /// Serialize in the stream byte order.
Stream & byteOrderSerialize( void * v, int len ) { Stream & byteOrderSerialize( void * v, uint len ) {
if( m_byteOrder == getSystemByteOrder() ) { if( m_byteOrder == getSystemByteOrder() ) {
serialize( v, len ); serialize( v, len );
} }
else { else {
for( int i=len-1; i>=0; i-- ) { for( uint i = len; i > 0; i-- ) {
serialize( (uint8 *)v + i, 1 ); serialize( (uint8 *)v + i - 1, 1 );
} }
} }
return *this; return *this;

Loading…
Cancel
Save