OSVR-Core
ComInit.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_ComInit_h_GUID_87AC03A7_3018_4A82_1716_BE38E2E9D1FC
26 #define INCLUDED_ComInit_h_GUID_87AC03A7_3018_4A82_1716_BE38E2E9D1FC
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <memory>
36 
37 namespace comutils {
38 
39 class ComInit;
40 
42 using ComInstance = std::unique_ptr<ComInit>;
43 
45 class ComInit {
46  public:
47  enum ThreadingModels { ApartmentThreading, Multithreading };
48  ComInit(ThreadingModels model = Multithreading);
49  ~ComInit();
52  static ComInstance init() {
53  auto ret = ComInstance{new ComInit};
54  return ret;
55  }
56 
61  auto ret = ComInstance{new ComInit{Multithreading}};
62  return ret;
63  }
64 
69  auto ret = ComInstance{new ComInit{ApartmentThreading}};
70  return ret;
71  }
72  ComInit(ComInit const &) = delete;
73  ComInit &operator=(ComInit const &) = delete;
74 };
75 
76 } // namespace comutils
77 
78 #endif // INCLUDED_ComInit_h_GUID_87AC03A7_3018_4A82_1716_BE38E2E9D1FC
Simple RAII class for handling COM initialization.
Definition: ComInit.h:45
static ComInstance initMultithreading()
Factory function returning a unique pointer representing a "multithreading" initialization of COM (pa...
Definition: ComInit.h:60
Definition: ComInit.cpp:34
static ComInstance init()
Factory function returning a unique pointer representing a default initialization of COM...
Definition: ComInit.h:52
static ComInstance initApartmentThreading()
Factory function returning a unique pointer representing an "apartment threading" initialization of C...
Definition: ComInit.h:68
std::unique_ptr< ComInit > ComInstance
unique_ptr for holding the lifetime of a ComInit.
Definition: ComInit.h:42