/[svn]/linuxsampler/trunk/src/common/Pool.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/common/Pool.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2879 by schoenebeck, Tue Apr 19 14:07:53 2016 UTC revision 3293 by schoenebeck, Tue Jun 27 22:19:19 2017 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6   *   Copyright (C) 2005 - 2016 Christian Schoenebeck                       *   *   Copyright (C) 2005 - 2017 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 38  Line 38 
38  # include <string>  # include <string>
39  #endif // CONFIG_RT_EXCEPTIONS  #endif // CONFIG_RT_EXCEPTIONS
40    
41    #include <iostream>
42    
43  #if CONFIG_DEVMODE  #if CONFIG_DEVMODE
44  # include <string>  # include <string>
 # include <iostream>  
45  const std::string __err_msg_iterator_invalidated = "Pool/RTList iterator invalidated";  const std::string __err_msg_iterator_invalidated = "Pool/RTList iterator invalidated";
46  #endif // CONFIG_DEVMODE  #endif // CONFIG_DEVMODE
47    
# Line 648  class RTList : public RTListBase<T> { Line 649  class RTList : public RTListBase<T> {
649              }              }
650          }          }
651    
652          inline int getID(const T* obj) const {          inline pool_element_id_t getID(const T* obj) const {
653              return pPool->getID(obj);              return pPool->getID(obj);
654          }          }
655    
656          inline int getID(const Iterator& it) const {          inline pool_element_id_t getID(const Iterator& it) const {
657              return pPool->getID(&*it);              return pPool->getID(&*it);
658          }          }
659    
# Line 692  class Pool : public RTList<T> { Line 693  class Pool : public RTList<T> {
693              if (data)  delete[] data;              if (data)  delete[] data;
694          }          }
695    
696            /**
697             * Returns true if there is at least one free element that could be
698             * allocated from the pool with i.e. allocAppend() or allocPreprend().
699             *
700             * @see poolHasFreeElements()
701             */
702          inline bool poolIsEmpty() const {          inline bool poolIsEmpty() const {
703              return freelist.isEmpty();              return freelist.isEmpty();
704          }          }
705    
706          /**          /**
707             * Returns true if at least the requested amount of free @a elements is
708             * currently available for being allocated from the pool with i.e.
709             * allocAppend() or allocPreprend().
710             *
711             * @see poolIsEmpty()
712             */
713            bool poolHasFreeElements(int elements) {
714                for (Iterator it = freelist.first(); it != freelist.end() && elements >= 0; ++it)
715                    --elements;
716                return elements <= 0;
717            }
718    
719            /**
720           * Returns the current size of the pool, that is the amount of           * Returns the current size of the pool, that is the amount of
721           * pre-allocated elements from the operating system. It equals the           * pre-allocated elements from the operating system. It equals the
722           * amount of elements given to the constructor unless resizePool()           * amount of elements given to the constructor unless resizePool()
# Line 782  class Pool : public RTList<T> { Line 802  class Pool : public RTList<T> {
802           */           */
803          pool_element_id_t getID(const T* obj) const {          pool_element_id_t getID(const T* obj) const {
804              if (!poolsize) return 0;              if (!poolsize) return 0;
805              int index = obj - &data[0];              int index = int( obj - &data[0] );
806              if (index < 0 || index >= poolsize) return 0;              if (index < 0 || index >= poolsize) return 0;
807              return ((nodes[index].reincarnation << poolsizebits) | index) + 1;              return ((nodes[index].reincarnation << poolsizebits) | index) + 1;
808          }          }
# Line 790  class Pool : public RTList<T> { Line 810  class Pool : public RTList<T> {
810          /**          /**
811           * Overridden convenience method, behaves like the method above.           * Overridden convenience method, behaves like the method above.
812           */           */
813          int getID(const Iterator& it) const {          pool_element_id_t getID(const Iterator& it) const {
814              return getID(&*it);              return getID(&*it);
815          }          }
816    
# Line 840  class Pool : public RTList<T> { Line 860  class Pool : public RTList<T> {
860           */           */
861          Iterator fromPtr(const T* obj) const {          Iterator fromPtr(const T* obj) const {
862              if (!poolsize) return Iterator(); // invalid iterator              if (!poolsize) return Iterator(); // invalid iterator
863              int index = obj - &data[0];              int index = int( obj - &data[0] );
864              if (index < 0 || index >= poolsize) return Iterator(); // invalid iterator              if (index < 0 || index >= poolsize) return Iterator(); // invalid iterator
865              return Iterator(&nodes[index]);              return Iterator(&nodes[index]);
866          }          }

Legend:
Removed from v.2879  
changed lines
  Added in v.3293

  ViewVC Help
Powered by ViewVC