Merge changes from private tree.

Eliminate files that are not needed for NVTT.
This commit is contained in:
castano
2009-03-01 00:18:47 +00:00
parent 6fb29816a2
commit 88fc5ca18e
93 changed files with 837 additions and 6561 deletions

View File

@ -1,5 +1,4 @@
PROJECT(nvcore)
ADD_SUBDIRECTORY(poshlib)
SET(CORE_SRCS
nvcore.h
@ -18,14 +17,6 @@ SET(CORE_SRCS
Containers.h
StrLib.h
StrLib.cpp
Stream.h
StdStream.h
TextReader.h
TextReader.cpp
TextWriter.h
TextWriter.cpp
Tokenizer.h
Tokenizer.cpp
Radix.h
Radix.cpp
CpuInfo.h
@ -34,6 +25,14 @@ SET(CORE_SRCS
Timer.h
Library.h
Library.cpp
Stream.h
StdStream.h
TextReader.h
TextReader.cpp
TextWriter.h
TextWriter.cpp
Tokenizer.h
Tokenizer.cpp
FileSystem.h
FileSystem.cpp)
@ -66,7 +65,7 @@ IF(MSVC AND NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
ARGS /nologo /Fo ${VSSCANF_ASM_OBJ} /c /Cx ${VSSCANF_ASM_SRC}
)
ENDIF(MSVC AND NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
# targets
ADD_DEFINITIONS(-DNVCORE_EXPORTS)

View File

@ -179,20 +179,29 @@ namespace nv
}
/// Const and save vector access.
/// Const element access.
const T & operator[]( uint index ) const
{
nvDebugCheck(index < m_size);
return m_buffer[index];
}
/// Safe vector access.
const T & at( uint index ) const
{
nvDebugCheck(index < m_size);
return m_buffer[index];
}
/// Element access.
T & operator[] ( uint index )
{
nvDebugCheck(index < m_size);
return m_buffer[index];
}
T & at( uint index )
{
nvDebugCheck(index < m_size);
return m_buffer[index];
}
/// Get vector size.
uint size() const { return m_size; }
@ -285,15 +294,22 @@ namespace nv
return m_buffer[0];
}
/// Check if the given element is contained in the array.
bool contains(const T & e) const
/// Return index of the
bool find(const T & element, uint * index)
{
for (uint i = 0; i < m_size; i++) {
if (m_buffer[i] == e) return true;
if (index != NULL) *index = i;
return true;
}
return false;
}
/// Check if the given element is contained in the array.
bool contains(const T & e) const
{
return find(e, NULL);
}
/// Remove the element at the given index. This is an expensive operation!
void removeAt( uint index )
{
@ -479,9 +495,10 @@ namespace nv
}
/// Assignment operator.
void operator=( const Array<T> & a )
Array<T> & operator=( const Array<T> & a )
{
copy( a.m_buffer, a.m_size );
return *this;
}
/*

View File

@ -405,7 +405,7 @@ namespace
{
void * trace[64];
int size = backtrace(trace, 64);
nvPrintStackTrace(trace, size, 3);
nvPrintStackTrace(trace, size, 2);
}
# endif

View File

@ -3,17 +3,18 @@
#ifndef NV_CORE_FILESYSTEM_H
#define NV_CORE_FILESYSTEM_H
#include <nvcore/nvcore.h>
namespace nv
{
namespace FileSystem
{
namespace FileSystem
{
bool exists(const char * path);
bool createDirectory(const char * path);
NVCORE_API bool exists(const char * path);
NVCORE_API bool createDirectory(const char * path);
} // FileSystem namespace
} // FileSystem namespace
} // nv namespace

View File

@ -8,10 +8,6 @@
#include <stdio.h> // NULL
#define NV_DECLARE_PTR(Class) \
typedef SmartPtr<class Class> Class ## Ptr; \
typedef SmartPtr<const class Class> ClassConst ## Ptr
namespace nv
{
@ -55,6 +51,15 @@ public:
}
}
template <class Q>
void operator=( Q * p ) {
if (p != m_ptr)
{
delete m_ptr;
m_ptr = static_cast<T *>(p);
}
}
/** Member access. */
T * operator -> () const {
nvDebugCheck(m_ptr != NULL);

View File

@ -6,6 +6,11 @@
#include <nvcore/nvcore.h>
#include <nvcore/Debug.h>
#define NV_DECLARE_PTR(Class) \
template <class T> class SmartPtr; \
typedef SmartPtr<class Class> Class ## Ptr; \
typedef SmartPtr<const class Class> Class ## ConstPtr
namespace nv
{

View File

@ -1,5 +1,7 @@
#ifndef NV_STDSTREAM_H
#define NV_STDSTREAM_H
// This code is in the public domain -- castano@gmail.com
#ifndef NV_CORE_STDSTREAM_H
#define NV_CORE_STDSTREAM_H
#include <nvcore/Stream.h>
@ -366,4 +368,4 @@ private:
} // nv namespace
#endif // NV_STDSTREAM_H
#endif // NV_CORE_STDSTREAM_H

View File

@ -137,9 +137,9 @@ namespace nv
void stripExtension();
// statics
static char separator();
static const char * fileName(const char *);
static const char * extension(const char *);
NVCORE_API static char separator();
NVCORE_API static const char * fileName(const char *);
NVCORE_API static const char * extension(const char *);
};

View File

@ -1,7 +1,7 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#ifndef NVCORE_STREAM_H
#define NVCORE_STREAM_H
#ifndef NV_CORE_STREAM_H
#define NV_CORE_STREAM_H
#include <nvcore/nvcore.h>
#include <nvcore/Debug.h>
@ -9,152 +9,152 @@
namespace nv
{
/// Base stream class.
class NVCORE_CLASS Stream {
public:
/// Base stream class.
class NVCORE_CLASS Stream {
public:
enum ByteOrder {
LittleEndian = false,
BigEndian = true,
};
enum ByteOrder {
LittleEndian = false,
BigEndian = true,
};
/// Get the byte order of the system.
static ByteOrder getSystemByteOrder() {
# if NV_LITTLE_ENDIAN
return LittleEndian;
# else
return BigEndian;
# endif
}
/// Ctor.
Stream() : m_byteOrder(LittleEndian) { }
/// Virtual destructor.
virtual ~Stream() {}
/// Set byte order.
void setByteOrder(ByteOrder bo) { m_byteOrder = bo; }
/// Get byte order.
ByteOrder byteOrder() const { return m_byteOrder; }
/// Serialize the given data.
virtual uint serialize( void * data, uint len ) = 0;
/// Move to the given position in the archive.
virtual void seek( uint pos ) = 0;
/// Return the current position in the archive.
virtual uint tell() const = 0;
/// Return the current size of the archive.
virtual uint size() const = 0;
/// Determine if there has been any error.
virtual bool isError() const = 0;
/// Clear errors.
virtual void clearError() = 0;
/// Return true if the stream is at the end.
virtual bool isAtEnd() const = 0;
/// Return true if the stream is seekable.
virtual bool isSeekable() const = 0;
/// Return true if this is an input stream.
virtual bool isLoading() const = 0;
/// Return true if this is an output stream.
virtual bool isSaving() const = 0;
// friends
friend Stream & operator<<( Stream & s, bool & c ) {
# if NV_OS_DARWIN
nvStaticCheck(sizeof(bool) == 4);
uint8 b = c ? 1 : 0;
s.serialize( &b, 1 );
c = (b == 1);
# else
nvStaticCheck(sizeof(bool) == 1);
s.serialize( &c, 1 );
# endif
return s;
}
friend Stream & operator<<( Stream & s, char & c ) {
nvStaticCheck(sizeof(char) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, uint8 & c ) {
nvStaticCheck(sizeof(uint8) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, int8 & c ) {
nvStaticCheck(sizeof(int8) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, uint16 & c ) {
nvStaticCheck(sizeof(uint16) == 2);
return s.byteOrderSerialize( &c, 2 );
}
friend Stream & operator<<( Stream & s, int16 & c ) {
nvStaticCheck(sizeof(int16) == 2);
return s.byteOrderSerialize( &c, 2 );
}
friend Stream & operator<<( Stream & s, uint32 & c ) {
nvStaticCheck(sizeof(uint32) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, int32 & c ) {
nvStaticCheck(sizeof(int32) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, uint64 & c ) {
nvStaticCheck(sizeof(uint64) == 8);
return s.byteOrderSerialize( &c, 8 );
}
friend Stream & operator<<( Stream & s, int64 & c ) {
nvStaticCheck(sizeof(int64) == 8);
return s.byteOrderSerialize( &c, 8 );
}
friend Stream & operator<<( Stream & s, float & c ) {
nvStaticCheck(sizeof(float) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, double & c ) {
nvStaticCheck(sizeof(double) == 8);
return s.byteOrderSerialize( &c, 8 );
}
protected:
/// Serialize in the stream byte order.
Stream & byteOrderSerialize( void * v, uint len ) {
if( m_byteOrder == getSystemByteOrder() ) {
serialize( v, len );
/// Get the byte order of the system.
static ByteOrder getSystemByteOrder() {
#if NV_LITTLE_ENDIAN
return LittleEndian;
#else
return BigEndian;
#endif
}
else {
for( uint i = len; i > 0; i-- ) {
serialize( (uint8 *)v + i - 1, 1 );
/// Ctor.
Stream() : m_byteOrder(LittleEndian) { }
/// Virtual destructor.
virtual ~Stream() {}
/// Set byte order.
void setByteOrder(ByteOrder bo) { m_byteOrder = bo; }
/// Get byte order.
ByteOrder byteOrder() const { return m_byteOrder; }
/// Serialize the given data.
virtual uint serialize( void * data, uint len ) = 0;
/// Move to the given position in the archive.
virtual void seek( uint pos ) = 0;
/// Return the current position in the archive.
virtual uint tell() const = 0;
/// Return the current size of the archive.
virtual uint size() const = 0;
/// Determine if there has been any error.
virtual bool isError() const = 0;
/// Clear errors.
virtual void clearError() = 0;
/// Return true if the stream is at the end.
virtual bool isAtEnd() const = 0;
/// Return true if the stream is seekable.
virtual bool isSeekable() const = 0;
/// Return true if this is an input stream.
virtual bool isLoading() const = 0;
/// Return true if this is an output stream.
virtual bool isSaving() const = 0;
// friends
friend Stream & operator<<( Stream & s, bool & c ) {
#if NV_OS_DARWIN
nvStaticCheck(sizeof(bool) == 4);
uint8 b = c ? 1 : 0;
s.serialize( &b, 1 );
c = (b == 1);
#else
nvStaticCheck(sizeof(bool) == 1);
s.serialize( &c, 1 );
#endif
return s;
}
friend Stream & operator<<( Stream & s, char & c ) {
nvStaticCheck(sizeof(char) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, uint8 & c ) {
nvStaticCheck(sizeof(uint8) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, int8 & c ) {
nvStaticCheck(sizeof(int8) == 1);
s.serialize( &c, 1 );
return s;
}
friend Stream & operator<<( Stream & s, uint16 & c ) {
nvStaticCheck(sizeof(uint16) == 2);
return s.byteOrderSerialize( &c, 2 );
}
friend Stream & operator<<( Stream & s, int16 & c ) {
nvStaticCheck(sizeof(int16) == 2);
return s.byteOrderSerialize( &c, 2 );
}
friend Stream & operator<<( Stream & s, uint32 & c ) {
nvStaticCheck(sizeof(uint32) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, int32 & c ) {
nvStaticCheck(sizeof(int32) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, uint64 & c ) {
nvStaticCheck(sizeof(uint64) == 8);
return s.byteOrderSerialize( &c, 8 );
}
friend Stream & operator<<( Stream & s, int64 & c ) {
nvStaticCheck(sizeof(int64) == 8);
return s.byteOrderSerialize( &c, 8 );
}
friend Stream & operator<<( Stream & s, float & c ) {
nvStaticCheck(sizeof(float) == 4);
return s.byteOrderSerialize( &c, 4 );
}
friend Stream & operator<<( Stream & s, double & c ) {
nvStaticCheck(sizeof(double) == 8);
return s.byteOrderSerialize( &c, 8 );
}
protected:
/// Serialize in the stream byte order.
Stream & byteOrderSerialize( void * v, uint len ) {
if( m_byteOrder == getSystemByteOrder() ) {
serialize( v, len );
}
else {
for( uint i = len; i > 0; i-- ) {
serialize( (uint8 *)v + i - 1, 1 );
}
}
return *this;
}
return *this;
}
private:
private:
ByteOrder m_byteOrder;
ByteOrder m_byteOrder;
};
};
} // nv namespace
#endif // NV_STREAM_H
#endif // NV_CORE_STREAM_H

View File

@ -1,6 +1,6 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#include <nvcore/TextReader.h>
#include "TextReader.h"
using namespace nv;

View File

@ -1,11 +1,10 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#ifndef NVCORE_TEXTREADER_H
#define NVCORE_TEXTREADER_H
#ifndef NV_CORE_TEXTREADER_H
#define NV_CORE_TEXTREADER_H
#include <nvcore/nvcore.h>
#include <nvcore/Stream.h>
#include <nvcore/Containers.h>
#include <nvcore/Stream.h>
namespace nv
{
@ -35,4 +34,4 @@ private:
} // nv namespace
#endif // NVCORE_TEXTREADER_H
#endif // NV_CORE_TEXTREADER_H

View File

@ -1,6 +1,6 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#include <nvcore/TextWriter.h>
#include "TextWriter.h"
using namespace nv;

View File

@ -1,11 +1,10 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#ifndef NVCORE_TEXTWRITER_H
#define NVCORE_TEXTWRITER_H
#ifndef NV_CORE_TEXTWRITER_H
#define NV_CORE_TEXTWRITER_H
#include <nvcore/nvcore.h>
#include <nvcore/Stream.h>
#include <nvcore/StrLib.h>
#include <nvcore/Stream.h>
namespace nv
{

View File

@ -1,73 +0,0 @@
// This code is in the public domain -- castanyo@yahoo.es
#ifndef NV_CORE_THREADLOCALSTORAGE_H
#define NV_CORE_THREADLOCALSTORAGE_H
#include <nvcore/nvcore.h>
// ThreadLocal<Context> context;
//
// context.allocate();
//
// context = new Context();
// context->member();
// context = NULL;
//
// context.free();
#if NV_CC_GNUC
#elif NV_CC_MSVC
template <class T>
class ThreadLocal
{
public:
ThreadLocal() : index(0) {}
~ThreadLocal() { nvCheck(index == 0); }
void allocate()
{
index = TlsAlloc();
}
void free()
{
delete ptr();
TlsFree(index);
index = 0;
}
bool isValid()
{
return index != 0;
}
void operator=( T * p )
{
if (p != ptr())
{
delete ptr();
TlsSetValue(index, p);
}
}
T * operator -> () const
{
return ptr();
}
T & operator*() const
{
return *ptr();
}
T * ptr() const {
return static_cast<T *>(TlsGetValue(index));
}
DWORD index;
};
#endif // NV_CC_MSVC
#endif // NV_CORE_THREADLOCALSTORAGE_H

View File

@ -1,6 +1,6 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#include <nvcore/Tokenizer.h>
#include "Tokenizer.h"
#include <nvcore/StrLib.h>
#include <stdio.h> // vsscanf

View File

@ -1,12 +1,11 @@
// This code is in the public domain -- castanyo@yahoo.es
// This code is in the public domain -- castano@gmail.com
#ifndef NV_CORE_TOKENIZER_H
#define NV_CORE_TOKENIZER_H
#include <nvcore/nvcore.h>
#include <nvcore/StrLib.h>
#include <nvcore/Stream.h>
#include <nvcore/TextReader.h>
#include <nvcore/StrLib.h>
namespace nv
{

View File

@ -22,7 +22,7 @@
// Platform definitions
#include "poshlib/posh.h"
#include <posh.h>
// OS:
// NV_OS_WIN32
@ -126,6 +126,9 @@
#define NV_DO_STRING_JOIN2(arg1, arg2) arg1 ## arg2
#define NV_STRING_JOIN3(arg1, arg2, arg3) NV_DO_STRING_JOIN3(arg1, arg2, arg3)
#define NV_DO_STRING_JOIN3(arg1, arg2, arg3) arg1 ## arg2 ## arg3
#define NV_STRING2(x) #x
#define NV_STRING(x) NV_STRING2(x)
#define NV_FILE_LINE __FILE__ "(" NV_STRING(__LINE__) ") : "
// Startup initialization macro.
#define NV_AT_STARTUP(some_code) \

View File

@ -1,7 +0,0 @@
SET(POSHLIB_SRCS
posh.c
posh.h)
ADD_LIBRARY(posh STATIC ${POSHLIB_SRCS})

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff