stub_analytics_plugin  1.6
Network Optix Video Analytics SDK
interface.h
1 #pragma once
2 
3 #include <cstring>
4 
5 #include <nx/sdk/uuid.h>
6 
7 #include "i_ref_countable.h"
8 
9 namespace nx {
10 namespace sdk {
11 
25 template<class DerivedInterface, class BaseInterface = IRefCountable>
26 class Interface: public BaseInterface
27 {
28 private:
29  static_assert(std::is_base_of<IRefCountable, BaseInterface>::value,
30  "Template parameter BaseInterface should be derived from IRefCountable");
31 
32  // Statically assure that DerivedInterface is inherited from this class.
33  Interface() = default;
34  friend DerivedInterface;
35 
36 public:
37  using IRefCountable::queryInterface; //< Enable const overload.
38 
39  virtual IRefCountable* queryInterface(IRefCountable::InterfaceId id) override
40  {
41  return doQueryInterface(id);
42  }
43 
44 protected:
48  const Uuid& deprecatedInterfaceId)
49  {
50  if (memcmp(id.value, deprecatedInterfaceId.data(), Uuid::kSize) == 0)
51  {
52  this->addRef();
53  return static_cast<DerivedInterface*>(this);
54  }
55  return doQueryInterface(id);
56  }
57 
58 private:
59  IRefCountable* doQueryInterface(IRefCountable::InterfaceId id)
60  {
61  if (id == DerivedInterface::interfaceId())
62  {
63  this->addRef();
64  return static_cast<DerivedInterface*>(this);
65  }
66  return BaseInterface::queryInterface(id);
67  }
68 };
69 
70 } // namespace sdk
71 } // namespace nx
Definition: i_ref_countable.h:55
Definition: interface.h:26
Definition: uuid.h:17
Definition: debug.cpp:12
Definition: i_ref_countable.h:43
IRefCountable * queryInterfaceSupportingDeprecatedId(IRefCountable::InterfaceId id, const Uuid &deprecatedInterfaceId)
Definition: interface.h:46