summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/int-set.h36
-rw-r--r--source/core/list.h98
-rw-r--r--source/core/slang-io.cpp6
-rw-r--r--source/core/slang-string.cpp2
-rw-r--r--source/core/slang-string.h14
-rw-r--r--source/core/smart-pointer.h1
-rw-r--r--source/core/text-io.cpp2
-rw-r--r--source/core/text-io.h2
8 files changed, 80 insertions, 81 deletions
diff --git a/source/core/int-set.h b/source/core/int-set.h
index a56a58d64..6b6f5e7a8 100644
--- a/source/core/int-set.h
+++ b/source/core/int-set.h
@@ -46,7 +46,7 @@ namespace Slang
{
SetMax(maxVal);
}
- int Size() const
+ UInt Size() const
{
return buffer.Count()*32;
}
@@ -57,40 +57,40 @@ namespace Slang
}
void SetAll()
{
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
buffer[i] = 0xFFFFFFFF;
}
- void Resize(int size)
+ void Resize(UInt size)
{
- int oldBufferSize = buffer.Count();
+ UInt oldBufferSize = buffer.Count();
buffer.SetSize((size+31)>>5);
if (buffer.Count() > oldBufferSize)
memset(buffer.Buffer()+oldBufferSize, 0, (buffer.Count()-oldBufferSize) * sizeof(int));
}
void Clear()
{
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
buffer[i] = 0;
}
- void Add(int val)
+ void Add(UInt val)
{
- int id = val>>5;
+ UInt id = val>>5;
if (id < buffer.Count())
buffer[id] |= (1<<(val&31));
else
{
- int oldSize = buffer.Count();
+ UInt oldSize = buffer.Count();
buffer.SetSize(id+1);
memset(buffer.Buffer() + oldSize, 0, (buffer.Count()-oldSize)*sizeof(int));
buffer[id] |= (1<<(val&31));
}
}
- void Remove(int val)
+ void Remove(UInt val)
{
if ((val>>5) < buffer.Count())
buffer[(val>>5)] &= ~(1<<(val&31));
}
- bool Contains(int val) const
+ bool Contains(UInt val) const
{
if ((val>>5) >= buffer.Count())
return false;
@@ -98,7 +98,7 @@ namespace Slang
}
void UnionWith(const IntSet & set)
{
- for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
{
buffer[i] |= set.buffer[i];
}
@@ -109,7 +109,7 @@ namespace Slang
{
if (buffer.Count() != set.buffer.Count())
return false;
- for (int i = 0; i<buffer.Count(); i++)
+ for (UInt i = 0; i<buffer.Count(); i++)
if (buffer[i] != set.buffer[i])
return false;
return true;
@@ -122,7 +122,7 @@ namespace Slang
{
if (set.buffer.Count() < buffer.Count())
memset(buffer.Buffer() + set.buffer.Count(), 0, (buffer.Count()-set.buffer.Count())*sizeof(int));
- for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++)
{
buffer[i] &= set.buffer[i];
}
@@ -131,26 +131,26 @@ namespace Slang
{
rs.buffer.SetSize(Math::Max(set1.buffer.Count(), set2.buffer.Count()));
rs.Clear();
- for (int i = 0; i<set1.buffer.Count(); i++)
+ for (UInt i = 0; i<set1.buffer.Count(); i++)
rs.buffer[i] |= set1.buffer[i];
- for (int i = 0; i<set2.buffer.Count(); i++)
+ for (UInt i = 0; i<set2.buffer.Count(); i++)
rs.buffer[i] |= set2.buffer[i];
}
static void Intersect(IntSet & rs, const IntSet & set1, const IntSet & set2)
{
rs.buffer.SetSize(Math::Min(set1.buffer.Count(), set2.buffer.Count()));
- for (int i = 0; i<rs.buffer.Count(); i++)
+ for (UInt i = 0; i<rs.buffer.Count(); i++)
rs.buffer[i] = set1.buffer[i] & set2.buffer[i];
}
static void Subtract(IntSet & rs, const IntSet & set1, const IntSet & set2)
{
rs.buffer.SetSize(set1.buffer.Count());
- for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
rs.buffer[i] = set1.buffer[i] & (~set2.buffer[i]);
}
static bool HasIntersection(const IntSet & set1, const IntSet & set2)
{
- for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
+ for (UInt i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++)
{
if (set1.buffer[i] & set2.buffer[i])
return true;
diff --git a/source/core/list.h b/source/core/list.h
index 5315f788f..aeba9557f 100644
--- a/source/core/list.h
+++ b/source/core/list.h
@@ -34,19 +34,19 @@ namespace Slang
class AllocateMethod
{
public:
- static inline T* Alloc(int size)
+ static inline T* Alloc(UInt size)
{
TAllocator allocator;
T * rs = (T*)allocator.Alloc(size*sizeof(T));
Initializer<T, std::is_pod<T>::value>::Initialize(rs, size);
return rs;
}
- static inline void Free(T * ptr, int bufferSize)
+ static inline void Free(T * ptr, UInt bufferSize)
{
TAllocator allocator;
if (!std::is_trivially_destructible<T>::value)
{
- for (int i = 0; i<bufferSize; i++)
+ for (UInt i = 0; i<bufferSize; i++)
ptr[i].~T();
}
allocator.Free(ptr);
@@ -57,11 +57,11 @@ namespace Slang
class AllocateMethod<T, StandardAllocator>
{
public:
- static inline T* Alloc(int size)
+ static inline T* Alloc(UInt size)
{
return new T[size];
}
- static inline void Free(T* ptr, int /*bufferSize*/)
+ static inline void Free(T* ptr, UInt /*bufferSize*/)
{
delete [] ptr;
}
@@ -83,7 +83,7 @@ namespace Slang
{
private:
- inline T * Allocate(int size)
+ inline T * Allocate(UInt size)
{
return AllocateMethod<T, TAllocator>::Alloc(size);
@@ -92,9 +92,9 @@ namespace Slang
static const int InitialSize = 16;
TAllocator allocator;
private:
- T * buffer;
- int _count;
- int bufferSize;
+ T* buffer;
+ UInt _count;
+ UInt bufferSize;
void FreeBuffer()
{
AllocateMethod<T, TAllocator>::Free(buffer, bufferSize);
@@ -239,7 +239,7 @@ namespace Slang
{
if (bufferSize < _count + 1)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
if (bufferSize)
newBufferSize = (bufferSize << 1);
@@ -252,7 +252,7 @@ namespace Slang
{
if (bufferSize < _count + 1)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
if (bufferSize)
newBufferSize = (bufferSize << 1);
@@ -262,7 +262,7 @@ namespace Slang
}
- int Count() const
+ UInt Count() const
{
return _count;
}
@@ -272,21 +272,21 @@ namespace Slang
return buffer;
}
- int Capacity() const
+ UInt Capacity() const
{
return bufferSize;
}
- void Insert(int id, const T & val)
+ void Insert(UInt id, const T & val)
{
InsertRange(id, &val, 1);
}
- void InsertRange(int id, const T * vals, int n)
+ void InsertRange(UInt id, const T * vals, UInt n)
{
if (bufferSize < _count + n)
{
- int newBufferSize = InitialSize;
+ UInt newBufferSize = InitialSize;
while (newBufferSize < _count + n)
newBufferSize = newBufferSize << 1;
@@ -300,9 +300,9 @@ namespace Slang
}
else*/
{
- for (int i = 0; i < id; i++)
+ for (UInt i = 0; i < id; i++)
newBuffer[i] = buffer[i];
- for (int i = id; i < _count; i++)
+ for (UInt i = id; i < _count; i++)
newBuffer[i + n] = T(static_cast<T&&>(buffer[i]));
}
FreeBuffer();
@@ -316,14 +316,14 @@ namespace Slang
memmove(buffer + id + n, buffer + id, sizeof(T) * (_count - id));
else*/
{
- for (int i = _count - 1; i >= id; i--)
- buffer[i + n] = static_cast<T&&>(buffer[i]);
+ for (UInt i = _count; i > id; i--)
+ buffer[i + n - 1] = static_cast<T&&>(buffer[i - 1]);
}
}
/*if (std::has_trivial_copy_assign<T>::value && std::has_trivial_destructor<T>::value)
memcpy(buffer + id, vals, sizeof(T) * n);
else*/
- for (int i = 0; i < n; i++)
+ for (UInt i = 0; i < n; i++)
buffer[id + i] = vals[i];
_count += n;
@@ -345,7 +345,7 @@ namespace Slang
InsertRange(_count, list.Buffer(), list.Count());
}
- void AddRange(const T * vals, int n)
+ void AddRange(const T * vals, UInt n)
{
InsertRange(_count, vals, n);
}
@@ -355,21 +355,19 @@ namespace Slang
InsertRange(_count, list.buffer, list._count);
}
- void RemoveRange(int id, int deleteCount)
+ void RemoveRange(UInt id, UInt deleteCount)
{
#if _DEBUG
- if (id >= _count || id < 0)
+ if (id >= _count)
throw "Remove: Index out of range.";
- if(deleteCount < 0)
- throw "Remove: deleteCount smaller than zero.";
#endif
- int actualDeleteCount = ((id + deleteCount) >= _count)? (_count - id) : deleteCount;
- for (int i = id + actualDeleteCount; i < _count; i++)
+ UInt actualDeleteCount = ((id + deleteCount) >= _count)? (_count - id) : deleteCount;
+ for (UInt i = id + actualDeleteCount; i < _count; i++)
buffer[i - actualDeleteCount] = static_cast<T&&>(buffer[i]);
_count -= actualDeleteCount;
}
- void RemoveAt(int id)
+ void RemoveAt(UInt id)
{
RemoveRange(id, 1);
}
@@ -395,7 +393,7 @@ namespace Slang
FastRemoveAt(idx);
}
- void FastRemoveAt(int idx)
+ void FastRemoveAt(UInt idx)
{
if (idx != -1 && _count - 1 != idx)
{
@@ -409,7 +407,7 @@ namespace Slang
_count = 0;
}
- void Reserve(int size)
+ void Reserve(UInt size)
{
if(size > bufferSize)
{
@@ -420,7 +418,7 @@ namespace Slang
memcpy(newBuffer, buffer, _count * sizeof(T));
else*/
{
- for (int i = 0; i < _count; i++)
+ for (UInt i = 0; i < _count; i++)
newBuffer[i] = static_cast<T&&>(buffer[i]);
}
FreeBuffer();
@@ -430,9 +428,9 @@ namespace Slang
}
}
- void GrowToSize(int size)
+ void GrowToSize(UInt size)
{
- int newBufferSize = 1<<Math::Log2Ceil(size);
+ UInt newBufferSize = UInt(1) << Math::Log2Ceil(size);
if (bufferSize < newBufferSize)
{
Reserve(newBufferSize);
@@ -440,13 +438,13 @@ namespace Slang
this->_count = size;
}
- void SetSize(int size)
+ void SetSize(UInt size)
{
Reserve(size);
_count = size;
}
- void UnsafeShrinkToSize(int size)
+ void UnsafeShrinkToSize(UInt size)
{
_count = size;
}
@@ -472,19 +470,19 @@ namespace Slang
#endif
#endif
- FORCE_INLINE T & operator [](int id) const
+ FORCE_INLINE T & operator [](UInt id) const
{
#if _DEBUG
- if(id >= _count || id < 0)
+ if(id >= _count)
throw IndexOutofRangeException("Operator[]: Index out of Range.");
#endif
return buffer[id];
}
template<typename Func>
- int FindFirst(const Func & predicate) const
+ UInt FindFirst(const Func & predicate) const
{
- for (int i = 0; i < _count; i++)
+ for (UInt i = 0; i < _count; i++)
{
if (predicate(buffer[i]))
return i;
@@ -493,18 +491,18 @@ namespace Slang
}
template<typename Func>
- int FindLast(const Func & predicate) const
+ UInt FindLast(const Func & predicate) const
{
- for (int i = _count - 1; i >= 0; i--)
+ for (UInt i = _count; i > 0; i--)
{
- if (predicate(buffer[i]))
- return i;
+ if (predicate(buffer[i-1]))
+ return i-1;
}
return -1;
}
template<typename T2>
- int IndexOf(const T2 & val) const
+ UInt IndexOf(const T2 & val) const
{
for (int i = 0; i < _count; i++)
{
@@ -515,12 +513,12 @@ namespace Slang
}
template<typename T2>
- int LastIndexOf(const T2 & val) const
+ UInt LastIndexOf(const T2 & val) const
{
- for (int i = _count - 1; i >= 0; i--)
+ for (int i = _count; i > 0; i--)
{
- if(buffer[i] == val)
- return i;
+ if(buffer[i-1] == val)
+ return i-1;
}
return -1;
}
@@ -532,7 +530,7 @@ namespace Slang
bool Contains(const T & val)
{
- for (int i = 0; i<_count; i++)
+ for (UInt i = 0; i<_count; i++)
if (buffer[i] == val)
return true;
return false;
diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp
index 684fed0a1..24d5aa412 100644
--- a/source/core/slang-io.cpp
+++ b/source/core/slang-io.cpp
@@ -23,7 +23,7 @@ namespace Slang
String Path::TruncateExt(const String & path)
{
- int dotPos = path.LastIndexOf('.');
+ UInt dotPos = path.LastIndexOf('.');
if (dotPos != -1)
return path.SubString(0, dotPos);
else
@@ -32,7 +32,7 @@ namespace Slang
String Path::ReplaceExt(const String & path, const char * newExt)
{
StringBuilder sb(path.Length()+10);
- int dotPos = path.LastIndexOf('.');
+ UInt dotPos = path.LastIndexOf('.');
if (dotPos == -1)
dotPos = path.Length();
sb.Append(path.Buffer(), dotPos);
@@ -72,7 +72,7 @@ namespace Slang
String Path::GetFileNameWithoutEXT(const String & path)
{
String fileName = GetFileName(path);
- int dotPos = fileName.LastIndexOf('.');
+ UInt dotPos = fileName.LastIndexOf('.');
if (dotPos == -1)
return fileName;
return fileName.SubString(0, dotPos);
diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp
index 3b9bcc87f..8938db595 100644
--- a/source/core/slang-string.cpp
+++ b/source/core/slang-string.cpp
@@ -149,7 +149,7 @@ namespace Slang
return String(buf);
}
- OSString String::ToWString(int* outLength) const
+ OSString String::ToWString(UInt* outLength) const
{
if (!buffer)
{
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 8294d4bc3..ba68e405e 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -452,7 +452,7 @@ namespace Slang
return getData();
}
- OSString ToWString(int* len = 0) const;
+ OSString ToWString(UInt* len = 0) const;
bool Equals(const String & str, bool caseSensitive = true)
{
@@ -636,13 +636,13 @@ namespace Slang
class StringBuilder : public String
{
private:
- static const int InitialSize = 1024;
+ enum { InitialSize = 1024 };
public:
- explicit StringBuilder(int bufferSize = InitialSize)
+ explicit StringBuilder(UInt bufferSize = InitialSize)
{
ensureUniqueStorageWithCapacity(bufferSize);
}
- void EnsureCapacity(int size)
+ void EnsureCapacity(UInt size)
{
ensureUniqueStorageWithCapacity(size);
}
@@ -678,7 +678,7 @@ namespace Slang
}
StringBuilder & operator << (const char * str)
{
- Append(str, (int)strlen(str));
+ Append(str, strlen(str));
return *this;
}
StringBuilder & operator << (const String & str)
@@ -736,9 +736,9 @@ namespace Slang
}
void Append(const char * str)
{
- Append(str, (int)strlen(str));
+ Append(str, strlen(str));
}
- void Append(const char * str, int strLen)
+ void Append(const char * str, UInt strLen)
{
append(str, str + strLen);
}
diff --git a/source/core/smart-pointer.h b/source/core/smart-pointer.h
index c31cdefe0..19ddde931 100644
--- a/source/core/smart-pointer.h
+++ b/source/core/smart-pointer.h
@@ -9,6 +9,7 @@ namespace Slang
{
// TODO: Need to centralize these typedefs
typedef uintptr_t UInt;
+ typedef intptr_t Int;
// Base class for all reference-counted objects
class RefObject
diff --git a/source/core/text-io.cpp b/source/core/text-io.cpp
index 7815d7422..ec41b8d7d 100644
--- a/source/core/text-io.cpp
+++ b/source/core/text-io.cpp
@@ -215,7 +215,7 @@ namespace Slang
{
#ifdef _WIN32
int flag = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_ASCII16;
- int rs = IsTextUnicode(buffer.Buffer(), buffer.Count(), &flag);
+ int rs = IsTextUnicode(buffer.Buffer(), (int) buffer.Count(), &flag);
if (rs)
{
if (flag & (IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_STATISTICS))
diff --git a/source/core/text-io.h b/source/core/text-io.h
index 9519d51f1..c914e340a 100644
--- a/source/core/text-io.h
+++ b/source/core/text-io.h
@@ -273,7 +273,7 @@ namespace Slang
RefPtr<Stream> stream;
List<char> buffer;
Encoding * encoding;
- int ptr;
+ UInt ptr;
char ReadBufferChar();
void ReadBuffer();