Guest User

Untitled

a guest
Jan 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. template <class C>
  2. class Singleton {
  3. /*! class Singleton
  4. * brief Singleton Template
  5. */
  6. public:
  7. /*!
  8. * brief Public access interface
  9. * return Singleton instance
  10. */
  11. static C *getInstance (){
  12. // Create new instance if not initialised
  13. if (_singleton == NULL){
  14. _singleton = new C;
  15. }
  16. return (static_cast<C*> (_singleton));
  17. }
  18.  
  19. /*!
  20. * brief Public access destructor
  21. */
  22. static void kill(){
  23. // Clean Singleton object and free memory
  24. if (_singleton != NULL){
  25. delete _singleton;
  26. _singleton = NULL;
  27. }
  28. }
  29. protected:
  30. /*!
  31. * brief Empty constructor
  32. */
  33. Singleton() = default;
  34. /*!
  35. * brief Destructor
  36. */
  37. virtual ~Singleton() = default;
  38.  
  39. private:
  40. static C *_singleton; /*!< Unique instance */
  41. };
  42.  
  43. template <class C>
  44. C *Singleton<C>::_singleton = NULL;
  45.  
  46. class TextureManager : public Singleton<TextureManager> {
  47. friend class Singleton<TextureManager>;
  48. /*! class TextureManager
  49. * brief Textures Container
  50. */
  51. public:
  52. protected:
  53. /*!
  54. * brief Empty constructor
  55. */
  56. TextureManager();
  57. /*!
  58. * brief Destructor
  59. */
  60. ~TextureManager() override;
  61. private:
  62. };
  63.  
  64. build/main.o: In function `Singleton<TextureManager>::getInstance()':
  65. main.cpp (.text._ZN9SingletonI14TextureManagerE11getInstanceEv[_ZN9SingletonI14TextureManagerE11getInstanceEv]+0x24): undefined reference to `TextureManager::TextureManager()'
  66.  
  67. TextureManager::TextureManager() = default;
  68. TextureManager::~TextureManager() = default;
  69.  
  70. INCLUDE = -I/usr/X11R6/include/
  71. LIBDIR = -L/usr/X11R6/lib
  72.  
  73. SRCDIR := sources
  74. BUILDDIR := build
  75. TARGET := bin/game
  76.  
  77. SRCEXT := cpp
  78. SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
  79. OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
  80.  
  81. FLAGS = -std=c++11 -Wall
  82. CC = g++
  83. CFLAGS = $(FLAGS) $(INCLUDE)
  84. LIBS = -lglut -lGL -lGLU -lGLEW -lm
  85.  
  86. $(TARGET): $(OBJECTS)
  87. @echo "Linking..."
  88. @echo "$(CC) $(CFLAGS) $^ -o $@ $(LIBDIR) $< $(LIBS)"; $(CC) $(CFLAGS) -o $@ $(LIBDIR) $< $(LIBS)
  89.  
  90. $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
  91. @mkdir -p $(@D)
  92. @echo "$(CC) $(CFLAGS) -o $@ $(LIBDIR) $< $(LIBS)"; $(CC) $(CFLAGS) -c -o $@ $(LIBDIR) $< $(LIBS)
  93.  
  94. clean:
  95. @echo "Cleaning..."
  96. @echo "$(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
  97.  
  98. .PHONY: clean
Add Comment
Please, Sign In to add comment