From 6cbc3929a54d37bd23cb5efa8e3320ba02f78b2f Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 31 May 2019 17:20:37 -0400 Subject: Use slang- prefix on slang compiler and core source (#973) * Prefixing source files in source/slang with slang- * Prefix source in source/slang with slang- prefix. * Rename core source files with slang- prefix. * Update project files. * Fix problems from automatic merge. --- source/core/slang-array.h | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 source/core/slang-array.h (limited to 'source/core/slang-array.h') diff --git a/source/core/slang-array.h b/source/core/slang-array.h new file mode 100644 index 000000000..d4bb7386f --- /dev/null +++ b/source/core/slang-array.h @@ -0,0 +1,135 @@ +#ifndef SLANG_CORE_ARRAY_H +#define SLANG_CORE_ARRAY_H + +#include "slang-exception.h" +#include "slang-array-view.h" + +namespace Slang +{ + template + class Array + { + private: + T m_buffer[COUNT]; + int m_count = 0; + public: + T* begin() { return m_buffer; } + const T* begin() const { return m_buffer; } + + const T* end() const { return m_buffer + m_count; } + T* end() { return m_buffer + m_count; } + + public: + inline int getCapacity() const { return COUNT; } + inline int getCount() const { return m_count; } + inline const T& getFirst() const + { + SLANG_ASSERT(m_count > 0); + return m_buffer[0]; + } + inline T& getFirst() + { + SLANG_ASSERT(m_count > 0); + return m_buffer[0]; + } + inline const T& getLast() const + { + SLANG_ASSERT(m_count > 0); + return m_buffer[m_count - 1]; + } + inline T& getLast() + { + SLANG_ASSERT(m_count > 0); + return m_buffer[m_count - 1]; + } + inline void setCount(int newCount) + { + SLANG_ASSERT(newCount >= 0 && newCount <= COUNT); + m_count = newCount; + } + inline void add(const T & item) + { + SLANG_ASSERT(m_count < COUNT); + m_buffer[m_count++] = item; + } + inline void add(T && item) + { + SLANG_ASSERT(m_count < COUNT); + m_buffer[m_count++] = _Move(item); + } + + inline const T& operator [](int idx) const + { + SLANG_ASSERT(idx >= 0 && idx < m_count); + return m_buffer[idx]; + } + inline T& operator [](int idx) + { + SLANG_ASSERT(idx >= 0 && idx < m_count); + return m_buffer[idx]; + } + + inline const T* getBuffer() const { return m_buffer; } + inline T* getBuffer() { return m_buffer; } + + inline void clear() { m_count = 0; } + + template + int indexOf(const T2& val) const + { + for (int i = 0; i < m_count; i++) + { + if (m_buffer[i] == val) + return i; + } + return -1; + } + + template + int lastIndexOf(const T2& val) const + { + for (int i = m_count - 1; i >= 0; i--) + { + if (m_buffer[i] == val) + return i; + } + return -1; + } + + inline ArrayView getArrayView() const + { + return ArrayView((T*)m_buffer, m_count); + } + inline ArrayView getArrayView(int start, int count) const + { + return ArrayView((T*)m_buffer + start, count); + } + }; + + template + struct FirstType + { + typedef T Type; + }; + + + template + void insertArray(Array&) {} + + template + void insertArray(Array& arr, const T& val, TArgs... args) + { + arr.add(val); + insertArray(arr, args...); + } + + template + auto makeArray(TArgs ...args) -> Array::Type, sizeof...(args)> + { + Array::Type, sizeof...(args)> rs; + insertArray(rs, args...); + return rs; + } +} + +#endif -- cgit v1.2.3