aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--entityx/Event.h17
-rw-r--r--entityx/help/Pool.h31
2 files changed, 25 insertions, 23 deletions
diff --git a/entityx/Event.h b/entityx/Event.h
index f238497..53afd7d 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>
@@ -26,7 +27,7 @@ namespace entityx {
/// Used internally by the EventManager.
class BaseEvent {
public:
- typedef size_t Family;
+ typedef std::size_t Family;
virtual ~BaseEvent() {}
@@ -75,8 +76,8 @@ class BaseReceiver {
}
// Return number of signals connected to this receiver.
- int connected_signals() const {
- size_t size = 0;
+ std::size_t connected_signals() const {
+ std::size_t size = 0;
for (auto connection : connections_) {
if (!connection.first.expired()) {
size++;
@@ -87,7 +88,7 @@ class BaseReceiver {
private:
friend class EventManager;
- std::list<std::pair<EventSignalWeakPtr, size_t>> connections_;
+ std::list<std::pair<EventSignalWeakPtr, std::size_t>> connections_;
};
@@ -159,13 +160,13 @@ class EventManager : entityx::help::NonCopyable {
template <typename E, typename ... Args>
void emit(Args && ... args) {
E event(std::forward<Args>(args) ...);
- auto sig = signal_for(size_t(E::family()));
+ auto sig = signal_for(std::size_t(E::family()));
BaseEvent *base = &event;
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();
}
@@ -173,7 +174,7 @@ class EventManager : entityx::help::NonCopyable {
}
private:
- EventSignalPtr &signal_for(size_t id) {
+ EventSignalPtr &signal_for(std::size_t id) {
if (id >= handlers_.size())
handlers_.resize(id + 1);
if (!handlers_[id])
diff --git a/entityx/help/Pool.h b/entityx/help/Pool.h
index ac959d2..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(int element_size, int 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();
- int size() const { return size_; }
- int capacity() const { return capacity_; }
- int 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_;
- int element_size_;
- int chunk_size_;
- int size_ = 0;
- int 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();