VISR  0.11.1
Versatile Interactive Scene Renderer
object_channel_allocator.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_LIBRBBL_OBJECT_CHANNEL_ALLOCATOR_HPP_INCLUDED
4 #define VISR_LIBRBBL_OBJECT_CHANNEL_ALLOCATOR_HPP_INCLUDED
5 
6 #include "export_symbols.hpp"
7 
9 
10 #include <exception>
11 #include <map>
12 #include <vector>
13 
14 namespace visr
15 {
16 namespace rbbl
17 {
18 
25 class VISR_RBBL_LIBRARY_SYMBOL ObjectChannelAllocator
26 {
27 public:
32  explicit ObjectChannelAllocator( std::size_t numChannels );
33 
41  void setObjects( std::vector<objectmodel::ObjectId > const & objectIds );
42 
46  std::size_t maxChannels( ) const { return mMaxChannels; }
47 
51  std::size_t numberUsedChannels( ) const;
52 
59  objectmodel::ObjectId getObjectForChannel( std::size_t channelId ) const;
60 
61 private:
67  std::size_t getUnusedChannel( )
68  {
69  if( mUnusedChannels.empty( ) )
70  {
71  throw std::runtime_error( "ObjectChannelAllocator::getUnusedChannel(): Maximum channel number exceeded." );
72  }
73  std::size_t nextChannel = mUnusedChannels.back( );
74  mUnusedChannels.pop_back( );
75  return nextChannel;
76  }
77 
81  void releaseChannel( std::size_t channel )
82  {
83  mUnusedChannels.push_back( channel );
84  }
85 
89  std::size_t const mMaxChannels;
90 
94  using ObjectChannelLookup = std::map< objectmodel::ObjectId, std::size_t>;
95 
99  ObjectChannelLookup mLookup;
100 
104  std::vector<std::size_t> mUnusedChannels;
105 
109  mutable std::vector<objectmodel::ObjectId> mSortedIds;
110 };
111 
112 } // namespace rbbl
113 } // namespace visr
114 
115 #endif // #ifndef VISR_LIBRBBL_OBJECT_CHANNEL_ALLOCATOR_HPP_INCLUDED
std::size_t const numChannels
Definition: delay_vector.cpp:21
unsigned int ObjectId
Definition: object.hpp:23
Definition: options.cpp:10
Definition: object_channel_allocator.hpp:25
std::size_t maxChannels() const
Definition: object_channel_allocator.hpp:46