Mobile API Reference  MicroStrategy 2019
ManipulationHelper.h
Go to the documentation of this file.
1 //
2 // ManipulationHelper.h
3 // ReportServiceCore
4 //
5 // Created by wzhu on 3/26/12.
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 //
8 
9 #ifndef ReportServiceCore_GUIDHelper_h
10 #define ReportServiceCore_GUIDHelper_h
11 
12 #include "GUID.h"
13 #include "DSSBaseElementProxy.h"
14 #include "time.h"
15 
17 {
18  // TToHexString converts an <T> value (unsigned integral) to a
19  // character hexadecimal string.
20  // As it is only used internally it doesn't do any sanity checks.
21  template<class T>
22  inline void TToHexString(T iT, char* ipString)
23  {
24  const char lcHexDigits[16] =
25  {
26  '0', '1', '2', '3', '4', '5', '6', '7',
27  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
28  };
29 
30 
31  for(int i = (sizeof(T)*2-1); i >= 0; --i, iT >>= 4)
32  {
33  ipString[i] = lcHexDigits[iT & 0x0000000F];
34  }
35  }
36 
50  inline GUID createUID()
51  {
52 
53  short ALPHA_CHAR_CODES[] = {48, 49, 50, 51, 52, 53, 54,
54  55, 56, 57, 65, 66, 67, 68, 69, 70};
55 
56  std::string uid;
57 
58  int i = 0;
59  int j = 0;
60 
61  srand(time(NULL));
62 
63  for (i = 0; i < 8; i++)
64  {
65  uid.push_back(ALPHA_CHAR_CODES[rand()%16]);
66  }
67 
68  for (i = 0; i < 3; i++)
69  {
70  for (j = 0; j < 4; j++)
71  {
72  uid.push_back(ALPHA_CHAR_CODES[rand()%16]);
73  }
74  }
75 
76  double lTime = time(NULL)*1000;
77 
78  char lIDString[33];
79  const unsigned int* pc = reinterpret_cast<const unsigned int*>(&lTime);
80  TToHexString<unsigned int>(*pc, lIDString);
81  TToHexString<unsigned int>(*(pc + 1), lIDString + 8);
82  TToHexString<unsigned int>(*(pc + 2), lIDString + 16);
83  TToHexString<unsigned int>(*(pc + 3), lIDString + 24);
84  lIDString[32] = '\0';
85 
86  //MDataType::DateTime lEndTime = MDataType::DateTime::NowUTC();
87  // Note: time is the number of milliseconds since 1970,
88  // which is currently more than one trillion.
89  // We use the low 8 hex digits of this number in the UID.
90  // Just in case the system clock has been reset to
91  // Jan 1-4, 1970 (in which case this number could have only
92  // 1-7 hex digits), we pad on the left with 7 zeros
93  // before taking the low digits.
94  std::string lTemp = "0000000";
95  lTemp += lIDString;
96  std::string timeString = lTemp.substr(lTemp.size() - 8);
97 
98  for (i = 0; i < 8; i++)
99  {
100  uid.push_back(timeString[i]);
101  }
102 
103  for (i = 0; i < 4; i++)
104  {
105  uid.push_back(ALPHA_CHAR_CODES[rand()%16]);
106  }
107 
108  GUID lGUID;
110  return lGUID;
111  }
112 
113 
114 }
115 
116 
117 #endif
void TToHexString(T iT, char *ipString)
Definition: ManipulationHelper.h:22
static bool ConvertFromStringToGUID(std::string iString, GUID &pGUID)
GUID createUID()
Definition: ManipulationHelper.h:50
#define NULL
Definition: Null.h:10
Definition: ManipulationHelper.h:16
Definition: Base/Base/GUID.h:32