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-2025 MAK Technologies, Inc
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
DtString DtReplaceAllSubstrings(const DtString &str, const DtString &searchFor, const DtString &replacement)
This function will replace all instances of a substring within a string with another string specified...
static std::map< DtString, DtString > longNamesToShortNames
Definition: vlCgHelpers.h:23
struct DtFloat64Layout::@7 bits
DtFloat32 flt
Definition: vlCgHelpers.h:36
const int endianChecker
This checks whether the machine is Big Endian or Little Endian.
Definition: vlCgHelpers.h:43
Contains the DtString class declaration.
static DtU16 endianSwap16Bit(DtU16 rhs)
swap 16 bits
Definition: vlCgHelpers.h:60
static DtFloat32 endianSwapFloat32Bit(DtFloat32 rhs)
swap 32 bits
Definition: vlCgHelpers.h:85
unsigned long long DtU64
-------—— Network Layout for a long long (64 bytes unsigned)
Definition: vlMachineTypes.h:185
static int myCurrentLargeFileNum
Definition: vlCgHelpers.h:22
static DtFloat64 endianSwapFloat64Bit(DtFloat64 rhs)
swap 64 bits
Definition: vlCgHelpers.h:98
DtU16 mslong
Definition: vlCgHelpers.h:38
static DtU64 endianSwap64Bit(DtU64 rhs)
swap 64 bits
Definition: vlCgHelpers.h:76
static DtString MakeCCompatibleString(DtString input)
Definition: vlCgHelpers.h:110
Used to Swap Longs.
Definition: vlCgHelpers.h:25
DtFloat64 flt
Definition: vlCgHelpers.h:27
DtU32 mslong
Definition: vlCgHelpers.h:29
static DtU32 endianSwap32Bit(DtU32 rhs)
swap 32 bits
Definition: vlCgHelpers.h:68
This file declares functions and types helpful to developers using DtString.
virtual void toUpper()
Convert this string&#39;s alphabetic characters to uppercase.
DtU16 lslong
Definition: vlCgHelpers.h:39
virtual const char * c_str() const
Returns a char* representation of the DtString;.
unsigned short DtU16
A 16 bit unsigned integer value.
Definition: vlMachineTypes.h:140
DtU32 lslong
Definition: vlCgHelpers.h:30
DtString DtFirstCharToUpper(const DtString &)
This function returns a new string with the first character uppercase.
Definition: vlCgHelpers.h:34
virtual int length() const
length() - Exactly the same as size():
virtual const char * string() const
string() - Returns a char * representation of the DtString: deprecated
unsigned long DtU32
A 32 bit unsigned integer value.
Definition: vlMachineTypes.h:153
virtual bool snipFront(const char ch, bool toLastCh=false)
Truncates everything before or after the character, including the character, respectively.
Instances of DtString are used to represent strings.
Definition: vlString.h:36
double DtFloat64
A 64 bit floating point value.
Definition: vlMachineTypes.h:212
struct DtFloat32Layout::@8 bits
static void swapByteArray(char *byteArray, int theSize)
Swap the byte array in memory.
Definition: vlCgHelpers.h:47

Document ID: Generated on Thu Oct 16 00:12:25 EDT 2025 from SVN revision 280738
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)