DgnHost.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 #include "DgnPlatform.h"
10 
12 
13 //=======================================================================================
14 // A DgnHost is an object that uniquely identifies a usage of the DgnPlatform libraries for a single purpose.
15 // For a given process, there can be more than one DgnHost, but each DgnHost must be on a different thread.
16 // DgnHost holds a collection of key/pointer pairs that are used to store and retrieve host-based data.
17 // @bsiclass Bentley Systems
18 //=======================================================================================
20  {
21 public:
25  struct Key
26  {
27  friend struct DgnHost;
28  private:
29  size_t m_key;
30  public:
31  Key() {m_key=0;}
32  };
33 
35  {
36  protected:
37  virtual ~IHostObject(){}
38  virtual void _OnHostTermination (bool isProgramExit) = 0;
39  public:
40  void OnHostTermination (bool isProgramExit) {_OnHostTermination(isProgramExit);}
41  };
42 
43  struct HostObjectBase : IHostObject {virtual void _OnHostTermination (bool) override {delete this;}};
44 
45  template<typename T>
47  {
48  private:
49  T m_value;
50  public:
51  HostValue (T const& v) : m_value (v) {;}
52  T const& GetValue () const {return m_value;}
53  T& GetValue () {return m_value;}
54  void SetValue (T const& v) {m_value = v;}
55  };
56 
57 public:
58 
64  DGNPLATFORM_EXPORT void* GetHostVariable (Key& key);
65 
70  DGNPLATFORM_EXPORT void SetHostVariable (Key& key, void* val);
71 
77  template <typename INT_TYPE>
78  INT_TYPE GetHostIntVariable (Key& key) {return (INT_TYPE)(intptr_t)GetHostVariable (key);}
79 
84  template <typename INT_TYPE>
85  void SetHostIntVariable (Key& key, INT_TYPE val) {SetHostVariable (key, (void*)(intptr_t)val);}
86 
92  bool GetHostBoolVariable (Key& key) {return 0 != (intptr_t)GetHostVariable (key);}
93 
98  void SetHostBoolVariable (Key& key, bool val) {SetHostVariable (key, (void*)(intptr_t)val);}
99 
105  DGNPLATFORM_EXPORT IHostObject* GetHostObject (Key& key);
106 
111  DGNPLATFORM_EXPORT void SetHostObject (Key& key, IHostObject* val);
112  };
113 
114 /*=================================================================================**/
119 {
120 private:
121  WString m_string;
122  virtual void _OnHostTermination (bool isProgramExit) override {delete this;}
123 
124 public:
125  DgnHostWString (wchar_t const* s) : m_string(s) {;}
126  DgnHostWString (WString const& ws) : m_string(ws) {;}
127 
128  WString& GetWString () {return m_string;}
129  WString const& GetWString () const {return m_string;}
130 };
131 
132 
134 
A host object that holds a string.
Definition: DgnHost.h:118
virtual void _OnHostTermination(bool) override
Definition: DgnHost.h:43
HostValue(T const &v)
Definition: DgnHost.h:51
DgnHostWString(WString const &ws)
Definition: DgnHost.h:126
#define END_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:69
T const & GetValue() const
Definition: DgnHost.h:52
INT_TYPE GetHostIntVariable(Key &key)
Get the value of a host-based integer variable identified by key.
Definition: DgnHost.h:78
WString const & GetWString() const
Definition: DgnHost.h:129
Key()
Definition: DgnHost.h:31
#define DGNPLATFORM_EXPORT
Definition: DgnPlatform/ExportMacros.h:58
WString & GetWString()
Definition: DgnHost.h:128
bool GetHostBoolVariable(Key &key)
Get the value of a host-based boolean variable identified by key.
Definition: DgnHost.h:92
Definition: DgnHost.h:19
void SetValue(T const &v)
Definition: DgnHost.h:54
#define CLRPUBLIC
Definition: DgnPlatform/ExportMacros.h:12
DgnHostWString(wchar_t const *s)
Definition: DgnHost.h:125
Each "type" of data stored on a DgnHost must have a unique key to identify it.
Definition: DgnHost.h:25
Base class to make a class non-copyable.
Definition: NonCopyableClass.h:23
#define BEGIN_BENTLEY_DGNPLATFORM_NAMESPACE
Definition: DgnPlatformBaseType.r.h:68
void OnHostTermination(bool isProgramExit)
Definition: DgnHost.h:40
void SetHostIntVariable(Key &key, INT_TYPE val)
Set the value of a host-based integer variable identified by key.
Definition: DgnHost.h:85
T & GetValue()
Definition: DgnHost.h:53
virtual ~IHostObject()
Definition: DgnHost.h:37
void SetHostBoolVariable(Key &key, bool val)
Set the value of a host-based boolean variable identified by key.
Definition: DgnHost.h:98
A string class that has many of the same capabilities as std::string, plus additional functions such ...
Definition: WString.h:51

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.