diff options
author | kumar8600 <kumar8600@gmail.com> | 2014-10-12 21:51:58 +0900 |
---|---|---|
committer | kumar8600 <kumar8600@gmail.com> | 2014-10-12 21:51:58 +0900 |
commit | 212d4ca2273a52bf1a370a0e292e817fe70d4f33 (patch) | |
tree | 1d3e039df3284e3fad617a2f08fa1fe073d00a5e | |
parent | 8f2096ff55c914973e49a296a89e50766244bc24 (diff) |
Get definition of std::size_t and make sizet_t more int
-rw-r--r-- | entityx/Event.h | 5 | ||||
-rw-r--r-- | entityx/help/Pool.h | 31 |
2 files changed, 19 insertions, 17 deletions
diff --git a/entityx/Event.h b/entityx/Event.h index ec048d7..142c758 100644 --- a/entityx/Event.h +++ b/entityx/Event.h @@ -11,6 +11,7 @@ #pragma once #include <stdint.h> +#include <cstddef> #include <vector> #include <list> #include <memory> @@ -164,8 +165,8 @@ class EventManager : entityx::help::NonCopyable { sig->emit(base); } - int connected_receivers() const { - int size = 0; + std::size_t connected_receivers() const { + std::size_t size = 0; for (EventSignalPtr handler : handlers_) { if (handler) size += handler->size(); } diff --git a/entityx/help/Pool.h b/entityx/help/Pool.h index c0283d2..7b1ca19 100644 --- a/entityx/help/Pool.h +++ b/entityx/help/Pool.h @@ -10,6 +10,7 @@ #pragma once +#include <cstddef> #include <cassert> #include <vector> @@ -27,23 +28,23 @@ namespace entityx { */ class BasePool { public: - explicit BasePool(size_t element_size, size_t chunk_size = 8192) + explicit BasePool(std::size_t element_size, std::size_t chunk_size = 8192) : element_size_(element_size), chunk_size_(chunk_size), capacity_(0) {} virtual ~BasePool(); - size_t size() const { return size_; } - size_t capacity() const { return capacity_; } - size_t chunks() const { return blocks_.size(); } + std::size_t size() const { return size_; } + std::size_t capacity() const { return capacity_; } + std::size_t chunks() const { return blocks_.size(); } /// Ensure at least n elements will fit in the pool. - inline void expand(int n) { + inline void expand(std::size_t n) { if (n >= size_) { if (n >= capacity_) reserve(n); size_ = n; } } - inline void reserve(int n) { + inline void reserve(std::size_t n) { while (capacity_ < n) { char *chunk = new char[element_size_ * chunk_size_]; blocks_.push_back(chunk); @@ -51,24 +52,24 @@ class BasePool { } } - inline void *get(int n) { + inline void *get(std::size_t n) { assert(n < size_); return blocks_[n / chunk_size_] + (n % chunk_size_) * element_size_; } - inline const void *get(int n) const { + inline const void *get(std::size_t n) const { assert(n < size_); return blocks_[n / chunk_size_] + (n % chunk_size_) * element_size_; } - virtual void destroy(int n) = 0; + virtual void destroy(std::size_t n) = 0; protected: std::vector<char *> blocks_; - size_t element_size_; - size_t chunk_size_; - size_t size_ = 0; - size_t capacity_; + std::size_t element_size_; + std::size_t chunk_size_; + std::size_t size_ = 0; + std::size_t capacity_; }; @@ -76,13 +77,13 @@ class BasePool { * Implementation of BasePool that provides type-"safe" deconstruction of * elements in the pool. */ -template <typename T, int ChunkSize = 8192> +template <typename T, std::size_t ChunkSize = 8192> class Pool : public BasePool { public: Pool() : BasePool(sizeof(T), ChunkSize) {} virtual ~Pool() {} - virtual void destroy(int n) override { + virtual void destroy(std::size_t n) override { assert(n < size_); T *ptr = static_cast<T*>(get(n)); ptr->~T(); |