init.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "base/init.h"
00012 #include "lib/Mathematics.h"
00013 #include "lib/memory.h"
00014 #include "lib/Set.h"
00015 #include "base/Parallel.h"
00016 #include "base/Version.h"
00017
00018 namespace shogun
00019 {
00020 CParallel* sg_parallel=NULL;
00021 CIO* sg_io=NULL;
00022 CVersion* sg_version=NULL;
00023 CMath* sg_math=NULL;
00024 #ifdef TRACE_MEMORY_ALLOCS
00025 CSet<CMemoryBlock>* sg_mallocs=NULL;
00026 #endif
00027
00029 void (*sg_print_message)(FILE* target, const char* str) = NULL;
00030
00032 void (*sg_print_warning)(FILE* target, const char* str) = NULL;
00033
00035 void (*sg_print_error)(FILE* target, const char* str) = NULL;
00036
00038 void (*sg_cancel_computations)(bool &delayed, bool &immediately)=NULL;
00039
00040 void init_shogun(void (*print_message)(FILE* target, const char* str),
00041 void (*print_warning)(FILE* target, const char* str),
00042 void (*print_error)(FILE* target, const char* str),
00043 void (*cancel_computations)(bool &delayed, bool &immediately))
00044 {
00045 if (!sg_io)
00046 sg_io = new shogun::CIO();
00047 if (!sg_parallel)
00048 sg_parallel=new shogun::CParallel();
00049 if (!sg_version)
00050 sg_version = new shogun::CVersion();
00051 if (!sg_math)
00052 sg_math = new shogun::CMath();
00053 #ifdef TRACE_MEMORY_ALLOCS
00054 if (!sg_mallocs)
00055 sg_mallocs = new shogun::CSet<CMemoryBlock>();
00056
00057 SG_REF(sg_mallocs);
00058 #endif
00059 SG_REF(sg_io);
00060 SG_REF(sg_parallel);
00061 SG_REF(sg_version);
00062 SG_REF(sg_math);
00063
00064 sg_print_message=print_message;
00065 sg_print_warning=print_warning;
00066 sg_print_error=print_error;
00067 sg_cancel_computations=cancel_computations;
00068 }
00069
00070 void exit_shogun()
00071 {
00072 sg_print_message=NULL;
00073 sg_print_warning=NULL;
00074 sg_print_error=NULL;
00075 sg_cancel_computations=NULL;
00076
00077 SG_UNREF(sg_math);
00078 SG_UNREF(sg_version);
00079 SG_UNREF(sg_parallel);
00080 SG_UNREF(sg_io);
00081
00082
00083 }
00084 }