]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Get definition of std::size_t and make sizet_t more int
authorkumar8600 <kumar8600@gmail.com>
Sun, 12 Oct 2014 12:51:58 +0000 (21:51 +0900)
committerkumar8600 <kumar8600@gmail.com>
Sun, 12 Oct 2014 12:51:58 +0000 (21:51 +0900)
entityx/Event.h
entityx/help/Pool.h

index ec048d7c37b49202b6335c345f327c3dde45097d..142c7584e85bf4d2e053f0b5e812f3475ed7e958 100644 (file)
@@ -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();
     }
index c0283d2e2c6020f36ca43de3a32ab70432e89136..7b1ca1917d523ef2fd17eb5c66966b3853ff6b51 100644 (file)
@@ -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();