Merge changes from The Witness.

This commit is contained in:
Ignacio
2015-10-28 23:53:08 -07:00
parent a382ea5b21
commit c0ad0f4d31
43 changed files with 890 additions and 136 deletions

View File

@ -115,7 +115,8 @@ namespace nv
Array<T> & append( const T & val );
Array<T> & operator<< ( T & t );
void pop_back();
void popBack();
void popBack(uint count = 1);
void popFront(uint count = 1);
const T & back() const;
T & back();
const T & front() const;

View File

@ -91,11 +91,32 @@ namespace nv
resize( m_size - 1 );
}
template <typename T>
NV_FORCEINLINE void Array<T>::popBack()
NV_FORCEINLINE void Array<T>::popBack(uint count)
{
pop_back();
nvDebugCheck(m_size >= count);
resize(m_size - count);
}
template <typename T>
NV_FORCEINLINE void Array<T>::popFront(uint count)
{
nvDebugCheck(m_size >= count);
//resize(m_size - count);
if (m_size == count) {
clear();
}
else {
destroy_range(m_buffer, 0, count);
memmove(m_buffer, m_buffer + count, sizeof(T) * (m_size - count));
m_size -= count;
}
}
// Get back element.
template <typename T>
NV_FORCEINLINE const T & Array<T>::back() const

View File

@ -25,6 +25,10 @@
#if _MSC_VER < 1500
# define vsnprintf _vsnprintf
#endif
#if _MSC_VER < 1700
# define strtoll _strtoi64
# define strtoull _strtoui64
#endif
#define chdir _chdir
#define getcwd _getcwd

View File

@ -160,6 +160,20 @@ void nv::strCat(char * dst, uint size, const char * src)
#endif
}
NVCORE_API const char * nv::strSkipWhiteSpace(const char * str)
{
nvDebugCheck(str != NULL);
while (*str == ' ') str++;
return str;
}
NVCORE_API char * nv::strSkipWhiteSpace(char * str)
{
nvDebugCheck(str != NULL);
while (*str == ' ') str++;
return str;
}
/** Pattern matching routine. I don't remember where did I get this. */
bool nv::strMatch(const char * str, const char * pat)
@ -252,7 +266,9 @@ StringBuilder::StringBuilder( const StringBuilder & s ) : m_size(0), m_str(NULL)
/** Copy string. */
StringBuilder::StringBuilder(const char * s) : m_size(0), m_str(NULL)
{
copy(s);
if (s != NULL) {
copy(s);
}
}
/** Copy string. */
@ -514,6 +530,21 @@ bool StringBuilder::beginsWith(const char * str) const
return strncmp(m_str, str, l) == 0;
}
// Find given char starting from the end.
char * StringBuilder::reverseFind(char c)
{
int length = (int)strlen(m_str) - 1;
while (length >= 0 && m_str[length] != c) {
length--;
}
if (length >= 0) {
return m_str + length;
}
else {
return NULL;
}
}
/** Reset the string. */
void StringBuilder::reset()
@ -553,15 +584,20 @@ const char * Path::extension() const
}
/*static */void Path::translatePath(char * path, char pathSeparator/*= NV_PATH_SEPARATOR*/) {
nvCheck(path != NULL);
for (int i = 0;; i++) {
if (path[i] == '\0') break;
if (path[i] == '\\' || path[i] == '/') path[i] = pathSeparator;
}
}
/// Toggles path separators (ie. \\ into /).
void Path::translatePath(char pathSeparator/*=NV_PATH_SEPARATOR*/)
{
nvCheck( m_str != NULL );
for (int i = 0; ; i++) {
if (m_str[i] == '\0') break;
if (m_str[i] == '\\' || m_str[i] == '/') m_str[i] = pathSeparator;
}
nvCheck(!isNull());
translatePath(m_str, pathSeparator);
}
void Path::appendSeparator(char pathSeparator/*=NV_PATH_SEPARATOR*/)

View File

@ -54,6 +54,9 @@ namespace nv
NVCORE_API void strCpy(char * dst, uint size, const char * src, uint len);
NVCORE_API void strCat(char * dst, uint size, const char * src);
NVCORE_API const char * strSkipWhiteSpace(const char * str);
NVCORE_API char * strSkipWhiteSpace(char * str);
NVCORE_API bool strMatch(const char * str, const char * pat) NV_PURE;
NVCORE_API bool isNumber(const char * str) NV_PURE;
@ -123,6 +126,8 @@ namespace nv
bool endsWith(const char * str) const;
bool beginsWith(const char * str) const;
char * reverseFind(char c);
void reset();
bool isNull() const { return m_size == 0; }
@ -195,6 +200,8 @@ namespace nv
NVCORE_API static char separator();
NVCORE_API static const char * fileName(const char *);
NVCORE_API static const char * extension(const char *);
NVCORE_API static void translatePath(char * path, char pathSeparator = NV_PATH_SEPARATOR);
};

View File

@ -136,6 +136,14 @@ namespace nv
return (b < a) ? a : b;
}
/// Return the maximum of the four arguments.
template <typename T>
//inline const T & max4(const T & a, const T & b, const T & c)
inline T max4(const T & a, const T & b, const T & c, const T & d)
{
return max(max(a, b), max(c, d));
}
/// Return the maximum of the three arguments.
template <typename T>
//inline const T & max3(const T & a, const T & b, const T & c)

View File

@ -133,7 +133,7 @@
#endif
#if NV_CC_MSVC
#define NV_CC_CPP11 (__cplusplus > 199711L)
#define NV_CC_CPP11 (__cplusplus > 199711L || _MSC_VER >= 1800) // Visual Studio 2013 has all the features we use, but doesn't advertise full C++11 support yet.
#else
// @@ IC: This works in CLANG, about GCC?
// @@ ES: Doesn't work in gcc. These 3 features are available in GCC >= 4.4.