SmartCGMS developer zone

Object model and interface

Each entity within the interoperable context of SmartCGMS also implements the refcnt::IReferenced interface. This interface is a custom variant of a standard IUnknown interface, which is a basic interface of a COM (Component Object Model). The SmartCGMS architecture follows the COM model and expects the entities to behave in such way. If the developer develops the component using the C++ language, most of the COM-related functionality can be achieved by a proper inheritance of SDK classes).

SmartCGMS SDK offer the interface definition and partial implementation within the refcnt namespace:

  • refcnt::IReferenced - the base interface, usually known as IUnknown; defines three methods (and also the following vtable layout):
    • QueryInterface - a method used to ask the component, if it supports the requested interface
    • AddRef - increments the object reference count
    • Release - decrements the object reference count; if the count reaches zero, the object gets deallocated
  • refcnt::CReferenced - base implementation of an object, which should maintain reference counting (AddRef and Release changes the value of the reference count attribute)
  • refcnt::CNot_Referenced - base implementation of an object, which does not participate in a reference-counted context, i.e. something else manages the object lifetime
Every entity, apart from its entity-specific interface, must also correctly implement the refcnt::IReferenced interface, or inherit from either refcnt::CReferenced or refcnt::CNot_Referenced SDK implementation.

The following figure depicts the possible class diagram of a custom filter:

Filter inheritance diagram

Though it is much more convenient to use the intermediate class scgms::CBase_Filter, also present in SDK:

Filter inheritance diagram

Throughout the SmartCGMS, reference-counted vectors are often used. A common interface refcnt::IVector_Container is defined in the SDK. This interface defines a set of methods:

  • set - sets the content of this container to a given range (begin to end)
  • add - adds a range of elements
  • get - retrieves the range of contained elements
  • pop - removes and returns exactly one element from the container
  • remove - removes one given item from the container
  • move - moves the element of the container from source index to destination index
  • empty - determines, if the container is empty
The underlying implementation should therefore maintain a continuous memory, which might be resized during container lifetime. In C++ environment, std::vector complies with given requirements. The SmartCGMS SDK offers the generic refcnt::CVector_Container implementation and its variants.

Each object implementing the refcnt::IReferenced interface is required to implement the QueryInterface method. This method is used to declare support for a GUID-identified interface. If the interface is supported, the QueryInterface method sets typecasted this pointer to the interface and S_OK. Otherwise, it returns E_NOINTERFACE.

This is often used to support entity inspection interfaces.