VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlCgHelpers.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
8 
9 #pragma once
10 
11 #include "vlString.h"
12 #include "vlStringUtil.h"
13 #include <map>
14 #include <string.h>
15 
16 
17 #ifdef DtUSE_UTILITIES_NAMESPACE
18 namespace DtUSE_UTILITIES_NAMESPACE
19 {
20 #endif
21 
22 static int myCurrentLargeFileNum = 0;
23 static std::map<DtString,DtString> longNamesToShortNames;
26 {
28  struct{
31  } bits;
32 };
33 
35 {
37  struct{
40  } bits;
41 };
43 const int endianChecker = 1;
44 #define is_bigendian() ( (*(char*)&endianChecker) == 0 )
45 
47 static void swapByteArray( char * byteArray, int theSize )
48 {
49  int theEnd = 0;
50  for( int i = 0; i < ( theSize >> 1 ); ++i )
51  {
52  theEnd = ( theSize - 1 ) - i;
53  byteArray[ i ] ^= byteArray[ theEnd ];
54  byteArray[ theEnd ] ^= byteArray[ i ];
55  byteArray[ i ] ^= byteArray[ theEnd ];
56  }
57 }
58 
61 {
62  unsigned short msbyte = rhs & 0x00ff;
63  unsigned short lsbyte = ( rhs & 0xff00 ) >> 8;
64  return ( msbyte << 8 ) | lsbyte;
65 }
66 
69 {
70  unsigned short msword = endianSwap16Bit( rhs & 0x0000ffff );
71  unsigned short lsword = endianSwap16Bit(( rhs & 0xffff0000 ) >> 16 );
72  return ( msword << 16 ) | lsword;
73 }
74 
77 {
79  unsigned int mspart = endianSwap32Bit( static_cast<unsigned int>(rhs & 0xffffffff) );
80  unsigned int lspart = endianSwap32Bit(static_cast<unsigned int>(( rhs >> 32 ) & 0xffffffff) );
81  return ( DtU64 ( mspart ) << 32 ) | lspart;
82 }
83 
86 {
87  DtFloat32Layout temp;
88  temp.flt = rhs;
90  DtU16 mspart = endianSwap16Bit(temp.bits.mslong);
91  DtU16 lspart = endianSwap16Bit(temp.bits.lslong);
92  temp.bits.mslong = mspart;
93  temp.bits.lslong = lspart;
94  return temp.flt;
95 }
96 
99 {
100  DtFloat64Layout temp;
101  temp.flt = rhs;
103  DtU32 mspart = endianSwap32Bit(temp.bits.mslong);
104  DtU32 lspart = endianSwap32Bit(temp.bits.lslong);
105  temp.bits.mslong = mspart;
106  temp.bits.lslong = lspart;
107  return temp.flt;
108 }
109 
111 {
112  bool usingDt = false;
113  input = DtReplaceAllSubstrings(input, '/', "__");
114  input = DtReplaceAllSubstrings(input, '#', "__");
115  input = DtReplaceAllSubstrings(input, '&', "__");
116  input = DtReplaceAllSubstrings(input, '-', "__");
117  input = DtReplaceAllSubstrings(input, '.', "__");
118  input = DtReplaceAllSubstrings(input, ' ', "__");
119  input = DtReplaceAllSubstrings(input, '(', "_");
120  input = DtReplaceAllSubstrings(input, ')', "_");
121  input = DtReplaceAllSubstrings(input, '<', "_");
122  input = DtReplaceAllSubstrings(input, '>', "_");
123 
124  DtString inputUpper = input;
125  inputUpper.toUpper();
126 
127  std::map<DtString,DtString>::iterator iter = longNamesToShortNames.find(inputUpper);
128  if(iter != longNamesToShortNames.end())
129  {
130  input = iter->second;
131  }
132  else
133  {
134  DtString nonDt = input;
135  if(nonDt[0] == 'D' && nonDt[1] == 't')
136  {
137  nonDt.snipFront('t');
138  DtString nonDtUpper = nonDt;
139  nonDtUpper.toUpper();
140  std::map<DtString,DtString>::iterator iter = longNamesToShortNames.find(nonDtUpper);
141  if(iter != longNamesToShortNames.end())
142  {
143  input = "Dt" + DtFirstCharToUpper(iter->second);
144  }
145  }
146  }
147 
148  if(input.length() > 100)
149  {
150  std::string temp = input.string();
151  temp.resize(50);
152 
154  temp += num;
155 
156  longNamesToShortNames[inputUpper] = temp.c_str();
157 
158  input = temp.c_str();
159 
161  }
162 
163  // Trailing terminator is empty string.
164  static const char *keywords[] = {
165  "abstract", "as", "base",
166  "break", "case", "catch",
167  "checked", "class", "const",
168  "continue", "decimal", "default", "delegate",
169  "do", "else", "enum",
170  "event", "explicit", "extern", "false",
171  "finally", "fixed", "for",
172  "foreach", "goto", "if", "implicit",
173  "in", "interface", "internal",
174  "is", "lock", "namespace",
175  "new", "null", "object", "operator",
176  "out", "override", "params", "private",
177  "protected", "public", "readonly", "ref",
178  "return", "sealed",
179  "sizeof", "stackalloc", "static",
180  "struct", "switch", "this", "throw",
181  "true", "try", "typeof",
182  "unchecked", "unsafe",
183  "using", "using static", "virtual",
184  "volatile", "while",
185  "" };
186  int kw = 0;
187  while (strlen(keywords[kw]) > 0)
188  {
189  if (strcmp(keywords[kw], input) == 0)
190  {
191  input = "_" + input;
192  break;
193  }
194  kw++;
195  }
196 
197  return input;
198 }
199 
200 #ifdef DtUSE_UTILITIES_NAMESPACE
201 }
202 #endif

Document ID: Generated on Mon Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (www.mak.com)