OSVR-Core
PropertyBagHelper.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_PropertyBagHelper_h_GUID_BAA9AA5B_2879_4CA0_04F3_9B90F3BAC871
26 #define INCLUDED_PropertyBagHelper_h_GUID_BAA9AA5B_2879_4CA0_04F3_9B90F3BAC871
27 
28 // Internal Includes
29 #include "comutils/ComPtr.h"
30 #include "comutils/ComVariant.h"
31 
32 // Library/third-party includes
33 #include <ObjIdl.h> // for IMonkider
34 #include <OAIdl.h> // for IPropertyBag, IID_IPropertyBag
35 
36 // Standard includes
37 #include <string>
38 
42  public:
43  explicit PropertyBagHelper(IMoniker &mon) {
44  mon.BindToStorage(nullptr, nullptr, IID_IPropertyBag,
45  AttachPtr(m_propBag));
46  }
47 
49  explicit operator bool() const { return bool(m_propBag); }
50 
52  IPropertyBag &getPropertyBag() { return *m_propBag; }
53 
55  IPropertyBag const &getPropertyBag() const { return *m_propBag; }
56 
58  std::wstring read(const wchar_t propName[]) const {
59  using namespace comutils::variant;
60 
61  auto ret = std::wstring{};
62  auto val = Variant{};
63  m_propBag->Read(propName, AttachVariant(val), nullptr);
64  if (contains<std::wstring>(val)) {
65  ret = get<std::wstring>(val);
66  }
67  return ret;
68  }
69 
70  private:
72 };
73 #endif // INCLUDED_PropertyBagHelper_h_GUID_BAA9AA5B_2879_4CA0_04F3_9B90F3BAC871
Header with a template alias for the desired COM smart pointer.
Assists in retrieving string properties from a property bag associated with a moniker.
Definition: PropertyBagHelper.h:41
Header defining a wrapper for COM&#39;s VARIANT type.
IPropertyBag & getPropertyBag()
Accessor for underlying object reference.
Definition: PropertyBagHelper.h:52
boost::intrusive_ptr< T > Ptr
Template alias for our desired COM smart pointer.
Definition: ComPtr.h:40
IPropertyBag const & getPropertyBag() const
Const accessor for underlying object reference.
Definition: PropertyBagHelper.h:55
std::wstring read(const wchar_t propName[]) const
Reads a (wide-string) property, returning an empty string if failed.
Definition: PropertyBagHelper.h:58