OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / ComObject.h
1 /*\r
2 * Copyright (c) 2007-2010 SlimDX Group\r
3\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
5 * of this software and associated documentation files (the "Software"), to deal\r
6 * in the Software without restriction, including without limitation the rights\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
8 * copies of the Software, and to permit persons to whom the Software is\r
9 * furnished to do so, subject to the following conditions:\r
10\r
11 * The above copyright notice and this permission notice shall be included in\r
12 * all copies or substantial portions of the Software.\r
13\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
20 * THE SOFTWARE.\r
21 */\r
22 #pragma once\r
23 \r
24 #include "ObjectTable.h"\r
25 #include "Configuration.h"\r
26 #include "Result.h"\r
27 #include "Utilities.h"\r
28 #include "InternalHelpers.h"\r
29 \r
30 #ifdef XMLDOCS\r
31 using System::IntPtr;\r
32 using System::Diagnostics::StackTrace;\r
33 #endif\r
34 \r
35 #include "ComObjectMacros.h"\r
36 \r
37 namespace SlimDX\r
38 {       \r
39         [System::Flags]\r
40         enum class ComObjectFlags\r
41         {\r
42                 None = 0,\r
43                 IsAncillary = 1,\r
44                 IsExternal = 2\r
45         };\r
46         \r
47         public interface struct IComObject : System::IDisposable\r
48         {\r
49         public:\r
50                 property System::IntPtr ComPointer\r
51                 {\r
52                         virtual System::IntPtr get() = 0;\r
53                 }\r
54         };\r
55 \r
56         /// <summary>\r
57         /// The base class for all SlimDX types which represent COM interfaces.\r
58         /// </summary>\r
59         /// <unmanaged>IUnknown</unmanaged>\r
60         public ref class ComObject abstract : IComObject\r
61         {\r
62         private:\r
63                 IUnknown* m_Unknown;\r
64                 ComObject^ m_Owner;\r
65                 ComObjectFlags m_Flags;\r
66                 System::Diagnostics::StackTrace^ m_Source;\r
67                 int m_CreationTime;\r
68 \r
69         private protected:\r
70                 ComObject();\r
71                 \r
72                 void Construct( IUnknown* pointer );\r
73                 void Construct( IUnknown* pointer, ComObject^ owner );\r
74                 void Construct( System::IntPtr pointer, System::Guid guid );\r
75                 void Destruct();\r
76                 \r
77                 template< typename M, typename N >\r
78                 static M^ ConstructFromPointer( N* pointer, ComObject^ owner, ComObjectFlags flags ) \r
79                 {\r
80                         // Since this method is called internally by SlimDX to essentially translate the results of native\r
81                         // API calls to their managed counterparts via the object table, we expect that a null pointer\r
82                         // might be passed, and that's okay. This differs from ConstructFromUserPointer.\r
83                         if( pointer == 0 )\r
84                                 return nullptr;\r
85                         \r
86                         M^ tableEntry = safe_cast<M^>( SlimDX::ObjectTable::Find( static_cast<System::IntPtr>( pointer ) ) );\r
87                         if( tableEntry != nullptr )\r
88                         {\r
89                                 if( static_cast<int>( flags & ComObjectFlags::IsAncillary ) == 0 ) \r
90                                         pointer->Release();\r
91                                 return tableEntry;\r
92                         }\r
93 \r
94                         M^ result = gcnew M( pointer, owner );\r
95                         result->SetFlags( flags );\r
96                         return result;\r
97                 }\r
98                 \r
99                 template< typename M >\r
100                 static M^ ConstructFromUserPointer( System::IntPtr pointer ) \r
101                 {\r
102                         // This method gets called as a result of the user invoking the IntPtr overload of FromPointer\r
103                         // to create a SlimDX object from an externally-tracked native object. In this scenario, a\r
104                         // null pointer is a failure, so we throw.\r
105                         if( pointer == System::IntPtr::Zero )\r
106                                 throw gcnew System::ArgumentNullException( "pointer" );\r
107 \r
108                         M^ tableEntry = safe_cast<M^>( SlimDX::ObjectTable::Find( static_cast<System::IntPtr>( pointer ) ) );\r
109                         if( tableEntry != nullptr )\r
110                         {\r
111                                 return tableEntry;\r
112                         }\r
113 \r
114                         M^ result = gcnew M( pointer );\r
115                         result->SetFlags( ComObjectFlags::IsExternal );\r
116                         return result;\r
117                 }\r
118                 \r
119         internal:\r
120                 property IUnknown* UnknownPointer\r
121                 {\r
122                         IUnknown* get();\r
123                 }\r
124 \r
125                 property IUnknown* InternalPointer\r
126                 {\r
127                         IUnknown* get();\r
128                 }\r
129 \r
130                 property ComObject^ Owner \r
131                 {\r
132                         ComObject^ get();\r
133                         void set( ComObject^ value );\r
134                 }\r
135                 \r
136                 void SetFlags( ComObjectFlags flags );\r
137                 void SetSource( System::Diagnostics::StackTrace^ stack );\r
138                 void SetCreationTime( int time );\r
139                 \r
140         public:\r
141                 /// <summary>\r
142                 /// Gets a value that indicates whether the object has been disposed.\r
143                 /// </summary>\r
144                 property bool Disposed\r
145                 {\r
146                         bool get();\r
147                 }\r
148                 \r
149                 /// <summary>\r
150                 /// Gets an <see cref="IntPtr">IntPtr</see> to the underlying native COM interface.\r
151                 /// </summary>\r
152                 property System::IntPtr ComPointer\r
153                 {\r
154                         virtual System::IntPtr get();\r
155                 }\r
156                 \r
157                 /// <summary>\r
158                 /// Gets a <see cref="StackTrace"/> to the location where the object was created.\r
159                 /// </summary>\r
160                 property System::Diagnostics::StackTrace^ CreationSource\r
161                 {\r
162                         System::Diagnostics::StackTrace^ get();\r
163                 }\r
164                 \r
165                 /// <summary>\r
166                 /// Gets the timestamp, in milliseconds, of the object'ss creation.\r
167                 /// </summary>\r
168                 property int CreationTime\r
169                 {\r
170                         int get();\r
171                 }\r
172                 \r
173                 /// <summary>\r
174                 /// Gets or sets a value indicating whether or not the object is in the default allocation pool.\r
175                 /// </summary>\r
176                 property bool IsDefaultPool;\r
177                 \r
178                 /// <summary>\r
179                 /// Extra tag data stored along with the object. This member is intended for use by users of SlimDX\r
180                 /// and has no internal meaning to the library.\r
181                 /// </summary>\r
182                 property Object^ Tag;\r
183 \r
184                 /// <summary>\r
185                 /// Releases all resources used by the <see cref="SlimDX::ComObject"/>.\r
186                 /// </summary>\r
187                 virtual ~ComObject();\r
188         };\r
189 }