system.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Animehunter
00028 */
00029 
00032 
00033 
00034 #pragma once
00035 
00036 
00037 #include "../api_core.h"
00038 #include "../Text/string_types.h"
00039 #include "../System/cl_platform.h"
00040 #include <vector>
00041 
00044 struct CL_API_CORE CL_PreallocatedMemory
00045 {
00046         int dummy;
00047 };
00048 
00049 class CL_Mutex;
00050 
00054 class CL_API_CORE CL_System
00055 {
00058 
00059 public:
00061         static unsigned int get_time();
00062 
00064         static cl_ubyte64 get_microseconds();
00065 
00066     enum CL_CPU_ExtensionX86 { mmx, mmx_ex, _3d_now, _3d_now_ex, sse, sse2, sse3, ssse3, sse4_a, sse4_1, sse4_2, xop, avx, aes, fma3, fma4 };
00067     enum CL_CPU_ExtensionPPC { altivec };
00068 
00069     static bool detect_cpu_extension(CL_CPU_ExtensionX86 ext);
00070     static bool detect_cpu_extension(CL_CPU_ExtensionPPC ext);
00071 
00073         static CL_Mutex *get_sharedptr_mutex();
00074 
00076         static int get_num_cores();
00077 
00078 
00082 
00083 public:
00085         static void *aligned_alloc(size_t size, size_t alignment = 16);
00086 
00088         static void aligned_free(void *ptr);
00089 
00091         static int capture_stack_trace(int frames_to_skip, int max_frames, void **out_frames, unsigned int *out_hash = 0);
00092 
00094 
00095         static std::vector<CL_String> get_stack_frames_text(void **frames, int num_frames);
00096 
00101         static void sleep(int millis);
00102 
00108         static void pause(int millis);
00109 
00112 
00118         static CL_String get_exe_path();
00119 
00121         template<typename T>
00122         static void call_constructor(T *memory)
00123         {
00124                 new ((CL_PreallocatedMemory *) memory) T;
00125         }
00126 
00127         template<typename T, typename P1>
00128         static void call_constructor(T *memory, P1 p1)
00129         {
00130                 new ((CL_PreallocatedMemory *) memory) T(p1);
00131         }
00132 
00133         template<typename T, typename P1, typename P2>
00134         static void call_constructor(T *memory, P1 p1, P2 p2)
00135         {
00136                 new ((CL_PreallocatedMemory *) memory) T(p1, p2);
00137         }
00138 
00139         template<typename T, typename P1, typename P2, typename P3>
00140         static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3)
00141         {
00142                 new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3);
00143         }
00144 
00145         template<typename T, typename P1, typename P2, typename P3, typename P4>
00146         static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4)
00147         {
00148                 new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4);
00149         }
00150 
00151         template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5>
00152         static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
00153         {
00154                 new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5);
00155         }
00156 
00157         template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
00158         static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6)
00159         {
00160                 new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5, p6);
00161         }
00162 
00163         template<typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
00164         static void call_constructor(T *memory, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7)
00165         {
00166                 new ((CL_PreallocatedMemory *) memory) T(p1, p2, p3, p4, p5, p6, p7);
00167         }
00168 
00170         template<typename T>
00171         static void call_destructor(T *memory)
00172         {
00173                 memory->~T();
00174         }
00175 
00176 
00180 
00181 private:
00183 };
00184 
00185