📄 lxdcmutil.cpp.svn-base
字号:
#include "LXDcmUtil.hpp"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <process.h>
#define SITE_INSTANCE_UID_ROOT SITE_UID_ROOT ".1.4"
#ifdef HAVE_STATIC_CAST#define LXstatic_cast(x,y) (static_cast< x >(y))#else#define LXstatic_cast(x,y) ((x)(y))#endif
static unsigned long hostIdentifier = 0;
static unsigned int counterOfCurrentUID = 1;
static const int maxUIDLen = 64; /* A UID may be 64 chars or less */
static long gethostid(void)
{
return 1473669170;//just for test
}
inline static unsigned longforcePositive(long i){ return (i < 0) ? LXstatic_cast(unsigned long, -i) : LXstatic_cast(unsigned long, i);}
static char* stripTrailing(char* s, char c){ int i, n; if (s == NULL) return s; n = strlen(s); for (i = n - 1; (i >= 0) && (s[i] == c); i--) s[i] = '\0'; return s;}
static void addUIDComponent(char* uid, const char* s){ int charsLeft = maxUIDLen - strlen(uid); if (charsLeft > 0) { /* copy into uid as much of the contents of s as possible */ int slen = strlen(s); int use = charsLeft; if (slen < charsLeft) use = slen; strncat(uid, s, use); } stripTrailing(uid, '.');}
CLXDcmUtil::CLXDcmUtil()
{
}
char* CLXDcmUtil::GenerateUniqueIdentifier( char* uid, const char* prefix/*=NULL*/ )
{
char buf[128]; /* be very safe */ uid[0] = '\0'; /* initialise */ if (hostIdentifier == 0) hostIdentifier = LXstatic_cast(unsigned long, gethostid()); unsigned int counter = counterOfCurrentUID++; if (prefix != NULL ) { addUIDComponent(uid, prefix); } else { addUIDComponent(uid, SITE_INSTANCE_UID_ROOT); } sprintf(buf, ".%lu", hostIdentifier); addUIDComponent(uid, buf); sprintf(buf, ".%lu", forcePositive(getpid())); addUIDComponent(uid, buf); sprintf(buf, ".%lu", forcePositive(LXstatic_cast(long, time(NULL)))); addUIDComponent(uid, buf); sprintf(buf, ".%u", counter); addUIDComponent(uid, buf); return uid;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -