OSDN Git Service

リセット
[momiji/momiji_main.git] / Core / Momiji.Core.Buffer.h
1 /*
2 [momiji music component library]
3 ---------------------------------------------------------------------
4 Momiji.Core.Buffer.h
5
6 ---------------------------------------------------------------------
7 Copyright (C) 2011 tyiki badwell {miria@users.sourceforge.jp}.
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/gpl-3.0.html>.
21 ---------------------------------------------------------------------
22 */
23 #pragma once
24
25 #using <mscorlib.dll>
26 //#include "Momiji.Core.Interface.h"
27
28 using namespace System::Runtime;
29
30 namespace Momiji{
31 namespace Core {
32 namespace Buffer {
33
34         generic<typename DATA_TYPE>
35         public ref class BufferPool
36         {
37         public:
38                 delegate DATA_TYPE Allocator();
39
40                 ref class Buffer
41                 {
42                 private:
43                         DATA_TYPE _buffer;
44                         InteropServices::GCHandle _bufferHandle;
45                         Allocator^ _allocator;
46
47                 public:
48                         Buffer(Allocator^ allocator);
49                         virtual ~Buffer();
50
51                 protected:
52                         !Buffer();
53
54                 private:
55                         void Alloc();
56                         void Free();
57
58                 public:
59                         System::IntPtr GetBufferIntPtr();
60                         DATA_TYPE% GetBuffer();
61                 };
62
63         private:
64                 System::Collections::Generic::List<Buffer^>^                                            _buffers;               //開放用の集合
65                 System::Collections::Generic::Dictionary<System::IntPtr, Buffer^>^      _idleBuffers;   //暇になっているバッファの集合
66                 System::Collections::Generic::Dictionary<System::IntPtr, Buffer^>^      _busyBuffers;   //再生中のバッファの集合
67
68                 System::UInt32 _defaultPoolSize;
69                 Allocator^ _allocator;
70
71         public:
72                 BufferPool(
73                         System::UInt32 defaultPoolSize,
74                         Allocator^ allocator
75                 );
76                 ~BufferPool();
77
78         protected:
79                 !BufferPool();
80
81         public:
82                 Buffer^ Get();
83                 Buffer^ GetBusy(System::IntPtr bufferPtr);
84                 void Release(Buffer^ buffer);
85                 System::Boolean IsBusy();
86
87         private:
88                 Buffer^ MakeBuffer();
89
90         };
91
92 }
93 }
94 }