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 Parallel* sg_parallel=NULL;
00021 IO* sg_io=NULL;
00022 Version* sg_version=NULL;
00023 CMath* sg_math=NULL;
00024 #ifdef TRACE_MEMORY_ALLOCS
00025 CSet<MemoryBlock>* 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::IO();
00047 if (!sg_parallel)
00048 sg_parallel=new shogun::Parallel();
00049 if (!sg_version)
00050 sg_version = new shogun::Version();
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<MemoryBlock>();
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
00085 void set_global_io(IO* io)
00086 {
00087 SG_UNREF(sg_io);
00088 sg_io=io;
00089 SG_REF(sg_io);
00090 }
00091
00092 IO* get_global_io()
00093 {
00094 SG_REF(sg_io);
00095 return sg_io;
00096 }
00097
00098 void set_global_parallel(Parallel* parallel)
00099 {
00100 SG_UNREF(sg_parallel);
00101 sg_parallel=parallel;
00102 SG_REF(sg_parallel);
00103 }
00104
00105 Parallel* get_global_parallel()
00106 {
00107 SG_REF(sg_parallel);
00108 return sg_parallel;
00109 }
00110
00111 void set_global_version(Version* version)
00112 {
00113 SG_UNREF(sg_version);
00114 sg_version=version;
00115 SG_REF(sg_version);
00116 }
00117
00118 Version* get_global_version()
00119 {
00120 SG_REF(sg_version);
00121 return sg_version;
00122 }
00123
00124 void set_global_math(CMath* math)
00125 {
00126 SG_UNREF(sg_math);
00127 sg_math=math;
00128 SG_REF(sg_math);
00129 }
00130
00131 CMath* get_global_math()
00132 {
00133 SG_REF(sg_math);
00134 return sg_math;
00135 }
00136 }