libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DynamicallyLoadableClass.hpp
Go to the documentation of this file.
1 #ifndef DYNAMICALLY_LOADABLE_CLASS_HPP
2 #define DYNAMICALLY_LOADABLE_CLASS_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include <iostream>
22 
23 namespace AlgAudio{
24 
30  void (*deleter)(void*) = nullptr;
31 public:
32  DynamicallyLoadableClass(void (*d)(void*)) : deleter(d) {}
34  void SetDeleter(void (*d)(void*)){ deleter = d; }
35  void SelfDestruct(){
36  if(deleter == nullptr){
37  // This case shouldn't happen. Local objects do not use SelfDestruct.
38  // std::cout << "Deleting a locally created object. " << std::endl;
39  delete this;
40  }else{
41  // std::cout << "Deleting a foreign object. " << std::endl;
42  deleter(this);
43  }
44  };
46 };
47 
48 } //namespace AlgAudio
49 #endif //DYNAMICALLY_LOADABLE_CLASS_HPP
DynamicallyLoadableClass(void(*d)(void *))
Definition: DynamicallyLoadableClass.hpp:32
DynamicallyLoadableClass()
Definition: DynamicallyLoadableClass.hpp:33
Definition: Alertable.hpp:26
virtual ~DynamicallyLoadableClass()
Definition: DynamicallyLoadableClass.hpp:45
Definition: DynamicallyLoadableClass.hpp:29
void SetDeleter(void(*d)(void *))
Definition: DynamicallyLoadableClass.hpp:34
void SelfDestruct()
Definition: DynamicallyLoadableClass.hpp:35