Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #ifndef CGENERICCREATOR_H
  2. #define CGENERICCREATOR_H
  3.  
  4. template<class FType, class Ident>
  5. class IGenericCreator
  6. {
  7.     public:
  8.         IGenericCreator(const Ident& ident)
  9.         {
  10.             Name = ident;
  11.             Counter = 0;
  12.         }
  13.         virtual ~IGenericCreator()
  14.         {
  15.             Counter = -1;
  16.         }
  17.  
  18.         virtual bool checkIdent(const Ident& ident)
  19.         {
  20.             return getIdent() == ident;
  21.         }
  22.  
  23.         virtual bool checkIdent(const Ident& ident) const
  24.         {
  25.             return getIdent() == ident;
  26.         }
  27.  
  28.         const Ident& getIdent(void) const
  29.         {
  30.             return Name;
  31.         }
  32.  
  33.         virtual FType create(void)
  34.         {
  35.             return FType();
  36.         }
  37.  
  38.         void grab(void)
  39.         {
  40.             Counter++;
  41.         }
  42.  
  43.         bool drop(void)
  44.         {
  45.             Counter--;
  46.             if (Counter == 0)
  47.             {
  48.                 delete this;
  49.                 return true;
  50.             }
  51.             return false;
  52.         }
  53.     protected:
  54.         Ident Name;
  55.         int Counter;
  56.     private:
  57. };
  58.  
  59. template<class FTypeIn, class FType, class Ident>
  60. class CGenericCreatorPointer : public IGenericCreator<FType, Ident>
  61. {
  62.     public:
  63.         CGenericCreatorPointer(const Ident& ident) : IGenericCreator<FType, Ident>(ident)
  64.         {
  65.         }
  66.         virtual FType create(void)
  67.         {
  68.             return new FTypeIn;
  69.         }
  70. };
  71.  
  72. #endif // CGENERICCREATOR_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement