Giri's C++ Support Library
C++ library providing everything you need to quickly create awesome applications.
giri::Key< T > Class Template Reference

Key class implementing passkey idiom. More...

#include <PassKey.h>

Inheritance diagram for giri::Key< T >:
Collaboration diagram for giri::Key< T >:

Additional Inherited Members

- Public Types inherited from giri::Object< Key< T > >
using SPtr = std::shared_ptr< Key< T > >
 
using UPtr = std::unique_ptr< Key< T > >
 
using WPtr = std::weak_ptr< Key< T > >
 

Detailed Description

template<typename T>
class giri::Key< T >

Key class implementing passkey idiom.

Can be used for instance to lock pure virtual function implementations to be only called from base class.

Example Usage:

#include <PassKey.h>
#include <iostream>
class MyClass : public giri::Object<MyClass>
{
public:
MyClass() {
Locked(m_Key); // Can be called
};
// Can only be called from this class, because only
// MyClass can create Key<MyClass> Objects.
void Locked(giri::Key<MyClass>&){
std::cout<<"Secret, Hello World. \n";
};
virtual void SayHiAndDoWork() final {
std::cout << "Hi!\n";
DoWork(m_Key); // Can only be called within tis class
}
protected:
// inherit to implement
virtual void DoWork(giri::Key<MyClass>&) = 0;
private:
};
class MyClassImpl : public MyClass
{
public:
MyClassImpl(){
//Key<MyClass> key; // cannot be created
//Locked(key); // cannot be called
//DoWork(key); // cannot be called aswell
SayHiAndDoWork(); // can be called
}
protected:
virtual void DoWork(giri::Key<MyClass>&) override
{
std::cout << "Doing hard work\n";
}
};
int main()
{
MyClassImpl cl;
cl.SayHiAndDoWork(); // only callable function
return EXIT_SUCCESS;
}
Passkey idiom implementation.
Key class implementing passkey idiom.
Definition: PassKey.h:76
Base Class of all classes.
Definition: Object.h:33

The documentation for this class was generated from the following file: