vsl_binary_loader_base.cxx
Go to the documentation of this file.
1 // This is core/vsl/vsl_binary_loader_base.cxx
2 //:
3 // \file
4 
5 #include <vector>
7 #ifdef _MSC_VER
8 # include <vcl_msvc_warnings.h>
9 #endif
10 #include <vsl/vsl_indent.h>
11 
12 // List of all loaders register_this()'ed
13 // Create on heap so that it can be cleaned up itself
14 static std::vector<vsl_binary_loader_base*> *loader_list_ = nullptr;
15 
16 
17 typedef void (*clear_func_ptr) ();
18 // List of all extra loaders clear funcs registered()'ed
19 // Create on heap so that it can be cleaned up itself
20 static std::vector<clear_func_ptr> *extra_loader_clear_list_ = nullptr;
21 
22 
24 {
26  {
28  // Clear all indent data
30  }
31 };
32 
33 static vsl_binary_loader_base_auto_clearup clearup_object;
34 
35 //=======================================================================
36 //: Register this, so it can be deleted by vsl_delete_all_loaders();
38 {
39  if (loader_list_==nullptr) loader_list_ = new std::vector<vsl_binary_loader_base*>;
40  loader_list_->push_back(this);
41 }
42 
43 
44 //: Allows other loader scheme to piggy back on the clearing of vsl loaders
45 // This is useful for getting rid of spurious memory leaks.
47 {
48  if (extra_loader_clear_list_ ==nullptr)
49  extra_loader_clear_list_ = new std::vector<clear_func_ptr>;
50 
51  extra_loader_clear_list_->push_back(func);
52 }
53 
54 
55 //=======================================================================
56 //: Deletes all the loaders
57 // Deletes every loader for which register_this() has been called
59 {
60 // Deletes every vsl loader for which register_this() has been called
61  if (loader_list_!=nullptr)
62  {
63  const auto n = (unsigned int)(loader_list_->size());
64  for (unsigned i=0;i<n;++i)
65  delete loader_list_->operator[](i);
66  loader_list_->clear();
67 
68  // Clean up the list itself
69  delete loader_list_;
70  loader_list_=nullptr;
71  }
72 }
void register_this()
Register this, so it can be deleted by vsl_delete_all_loaders();.
void vsl_register_new_loader_clear_func(clear_func_ptr func)
Allows other loader scheme to piggy back on the clearing of vsl loaders.
void vsl_indent_clear_all_data()
Tidy up the internal indent map to remove potential memory leaks.
Definition: vsl_indent.cxx:85
void vsl_delete_all_loaders()
Deletes all the loaders.
void(* clear_func_ptr)()