Content


NTL
Core
CFeature

CFeature


Base class for features.

class CFeature :public virtual IFeature, public CReleasable
{
protected:
    CFeature(const String &name);
};

The feature is just a class instance that is available globally. Let's say we need access to the user login and password in multiple places in an application. In this case we can create a feature like following.

class CUserConfig :public CFeature
{
private:
    String m_sLogin;
    String m_sPassword;
public:
    String const &Login{ m_sLogin };
    String const &Password{ m_sPassword };
        
    CUserConfig(const String &login, const String &password) :
        CFeature(L"UserConfig"),
        m_sLogin{ login },
        m_sPassword{ password }
    {
        
    }
};

After it we can register a new feature at the application start.

int main()
{
    CApplication app;
    app.RegisterFeature(new CUserConfig(L"root", L"password"));
    // ...
        
    return 0;
}

Now at any place in the application we can get access to user login and password in the following way.

String login{ cast<CUserConfig*>(Application->getFeature(L"UserConfig"))->Login };
Namespace: nitisa
Include: Nitisa/Package/Core/Feature.h