00001 // This is core/vsl/vsl_binary_loader_base.cxx 00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00003 #pragma implementation 00004 #endif 00005 //: 00006 // \file 00007 00008 #include "vsl_binary_loader_base.h" 00009 #include <vcl_vector.h> 00010 #include <vcl_vector.txx> 00011 #include <vsl/vsl_indent.h> 00012 00013 // List of all loaders register_this()'ed 00014 // Create on heap so that it can be cleaned up itself 00015 static vcl_vector<vsl_binary_loader_base*> *loader_list_ = 0; 00016 00017 00018 typedef void (*clear_func_ptr) (); 00019 // List of all extra loaders clear funcs registered()'ed 00020 // Create on heap so that it can be cleaned up itself 00021 static vcl_vector<clear_func_ptr> *extra_loader_clear_list_ = 0; 00022 00023 00024 struct vsl_binary_loader_base_auto_clearup 00025 { 00026 ~vsl_binary_loader_base_auto_clearup() 00027 { 00028 vsl_delete_all_loaders(); 00029 // Clear all indent data 00030 vsl_indent_clear_all_data(); 00031 } 00032 }; 00033 00034 static vsl_binary_loader_base_auto_clearup clearup_object; 00035 00036 //======================================================================= 00037 //: Register this, so it can be deleted by vsl_delete_all_loaders(); 00038 void vsl_binary_loader_base::register_this() 00039 { 00040 if (loader_list_==0) loader_list_ = new vcl_vector<vsl_binary_loader_base*>; 00041 loader_list_->push_back(this); 00042 } 00043 00044 00045 //: Allows other loader scheme to piggy back on the clearing of vsl loaders 00046 // This is useful for getting rid of spurious memory leaks. 00047 void vsl_register_new_loader_clear_func(clear_func_ptr func) 00048 { 00049 if (extra_loader_clear_list_ ==0) 00050 extra_loader_clear_list_ = new vcl_vector<clear_func_ptr>; 00051 00052 extra_loader_clear_list_->push_back(func); 00053 } 00054 00055 00056 //======================================================================= 00057 //: Deletes all the loaders 00058 // Deletes every loader for which register_this() has been called 00059 void vsl_delete_all_loaders() 00060 { 00061 // Deletes every vsl loader for which register_this() has been called 00062 if (loader_list_!=0) 00063 { 00064 const unsigned int n = (unsigned int)(loader_list_->size()); 00065 for (unsigned i=0;i<n;++i) 00066 delete loader_list_->operator[](i); 00067 loader_list_->clear(); 00068 00069 // Clean up the list itself 00070 delete loader_list_; 00071 loader_list_=0; 00072 } 00073 }