00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "StdHelpers.h"
00017 #include "ITask.h"
00018
00019 #include <time.h>
00020 #if NR_PLATFORM != NR_PLATFORM_WIN32
00021 # include <sys/time.h>
00022 #endif
00023
00024 namespace nrEngine{
00025
00026
00027 void sleep( uint32 milliseconds )
00028 {
00029 #if NR_PLATFORM == NR_PLATFORM_WIN32
00030 Sleep( (DWORD)milliseconds );
00031 #else
00032 #if NR_PLATFORM == NR_PLATFORM_NETWARE
00033 delay(milliseconds/1000+1);
00034 #elif NR_PLATFORM == NR_PLATFORM_OS2
00035 DosSleep(milliseconds/1000+1);
00036 #else
00037
00038 timeval start;
00039 int64 a,b;
00040 gettimeofday(&start, NULL);
00041
00042
00043 a = start.tv_sec * 1000000L + start.tv_usec;
00044 b = a + milliseconds * 1000L;
00045
00046
00047 while (a < b){
00048 gettimeofday(&start, NULL);
00049 a = start.tv_sec * 1000000L + start.tv_usec;
00050 }
00051 #endif
00052 #endif
00053 }
00054
00055
00056
00057 std::string convertVersionToString(uint32 version)
00058 {
00059
00060 uint32 patch = version % 256;
00061
00062
00063 uint32 minor = ((version) / 256) % 256;
00064
00065
00066 uint32 major = ((version) / (256 * 256)) % 256;
00067
00068
00069 char str[32];
00070 sprintf(str, "%d.%d.%d", major, minor, patch);
00071
00072
00073 return std::string(str);
00074 }
00075
00076
00077
00078 uint32 createVersionInteger(uint8 major, uint8 minor, uint8 patch)
00079 {
00080 return uint32(major) * 256 * 256 + uint32(minor) * 256 + uint32(patch);
00081 }
00082
00083
00084
00085 std::string trim(const std::string& str)
00086 {
00087 std::string res;
00088
00089 for (uint32 i=0; i < str.length();i++){
00090 if(str[i] != ' ' && str[i] != '\n'){
00091 res += str[i];
00092 }
00093 }
00094
00095 return res;
00096 }
00097
00098
00099 std::string _NRExport orderToString(int32 order)
00100 {
00101 #define CHECK(a) case a: result=#a; break;
00102 char ord[256];
00103 sprintf(ord, "%d", order);
00104 std::string result = ord;
00105
00106 switch (order){
00107 CHECK(ORDER_SYS_ROOT)
00108 CHECK(ORDER_SYS_FIRST)
00109 CHECK(ORDER_SYS_SECOND)
00110 CHECK(ORDER_SYS_THIRD)
00111 CHECK(ORDER_SYS_FOURTH)
00112 CHECK(ORDER_SYS_FIVETH)
00113 CHECK(ORDER_SYS_LAST)
00114 CHECK(ORDER_FIRST)
00115 CHECK(ORDER_ULTRA_HIGH)
00116 CHECK(ORDER_VERY_HIGH)
00117 CHECK(ORDER_HIGH)
00118 CHECK(ORDER_NORMAL)
00119 CHECK(ORDER_LOW)
00120 CHECK(ORDER_VERY_LOW)
00121 CHECK(ORDER_ULTRA_LOW)
00122 CHECK(ORDER_LAST)
00123 };
00124
00125 #undef CHECK
00126 return result;
00127 }
00128
00129 };
00130