VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlString.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 1992-2025 MAK Technologies, Inc
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vlutil/vlMachineTypes.h>
13 #include <vector>
14 #include <iosfwd>
15 
16 #if _MSC_VER >= 1920 //VC16 2019
17 #include <xstring>
18 #endif
19 
20 #if __has_include(<compare>)
21 # include <compare>
22 # if defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907
23 # define DtSPACESHIP_OPERATOR_IS_SUPPORTED 1
24 # endif
25 #endif
26 
27 #ifdef DtUSE_UTILITIES_NAMESPACE
28 namespace DtUSE_UTILITIES_NAMESPACE
29 {
30 #endif
31 
37  {
38  public:
39 
41  DtString();
42 
44  DtString( const char* str );
45 
47  DtString( const char* str, int length );
48 
50  DtString( const std::string& str );
51 
53  DtString( const DtString& orig );
54 
61 
62  DtString( double val );
63  DtString( int val );
64  DtString( long val );
65  DtString( char val );
66  DtString( unsigned int val );
67  DtString( unsigned long val );
68 
70 
72  virtual ~DtString();
73 
76 
77  virtual DtString& operator = ( const char* orig );
78  virtual DtString& operator = ( const DtString& orig );
79 
81 
84  [[deprecated("Use c_str() instead.")]] virtual operator const char*() const;
85 
87  virtual DtString* clone() const;
88 
91 
92  friend DT_DLL_VLUTIL bool operator < ( const DtString& str1, const DtString& str2 );
93  friend DT_DLL_VLUTIL bool operator > ( const DtString& str1, const DtString& str2 );
94  friend DT_DLL_VLUTIL bool operator == ( const DtString& str1, const DtString& str2 );
95  friend DT_DLL_VLUTIL bool operator != ( const DtString& str1, const DtString& str2 );
96  friend DT_DLL_VLUTIL bool operator <= ( const DtString& str1, const DtString& str2 );
97  friend DT_DLL_VLUTIL bool operator >= ( const DtString& str1, const DtString& str2 );
98 
99  virtual bool operator < ( const char* str ) const;
100  virtual bool operator > ( const char* str ) const;
101  virtual bool operator == ( const char* str ) const;
102  virtual bool operator != ( const char* str ) const;
103  virtual bool operator <= ( const char* str ) const;
104  virtual bool operator >= ( const char* str ) const;
105 
106 #if DtSPACESHIP_OPERATOR_IS_SUPPORTED
107  // Note: Since DtString implicitly casts to const char*, this operator is necessary to prevent
108  // the pointer version of <=> from being used which will compare memory addresses instead of string contents.
109  std::strong_ordering operator<=>(const DtString& s1, const DtString& s2)
110  {
111  if (s1 == s2) return std::strong_ordering::equal;
112  if (s1 < s2) return std::strong_ordering::less;
113  return std::strong_ordering::greater;
114  }
115 #endif
116 
118 
122 
123  virtual bool caseCompare(const char* str) const;
124  virtual bool caseCompare(const DtString& str) const;
125 
127 
130 
131  friend DT_DLL_VLUTIL DtString operator + ( const char* str1, const DtString& str2 );
132  friend DT_DLL_VLUTIL DtString operator + ( const DtString& str1, const DtString& str2 );
133 
134  virtual DtString operator + ( const char* str ) const;
135  virtual DtString& operator += ( const char* str );
136  virtual DtString& operator += ( const DtString& str );
137 
139 
142 
143  virtual char& operator [] ( int index );
144  virtual const char& operator [] ( int index ) const;
145 
147 
154 
155  virtual bool snipFront( const char ch, bool toLastCh = false );
156  virtual bool snipBack( const char ch, bool fromFirstCh = false );
158 
160 
161  virtual bool chompFront();
162  virtual bool chompBack();
164 
167  virtual void tokenize( const char delimiter, std::vector<DtString>& tokens ) const;
168 
172  virtual int toInt( bool* ok = 0 ) const;
173 
177  virtual unsigned int toUInt( bool* ok = 0 ) const;
178 
182  virtual float toFloat( bool* ok = 0 ) const;
183 
187  virtual double toDouble( bool* ok = 0 ) const;
188 
192  virtual bool toBoolean( bool* ok = 0 ) const;
193 
195  virtual void toUpper();
196 
198  virtual void toLower();
199 
203  virtual int findChar( const char ch );
204 
208  virtual int findLastChar( const char ch );
209 
213  virtual int findString( const DtString& string ) const;
214 
218  virtual int findLastString( const DtString& string );
219 
220  bool snipFrontToLast( const char ch )
221  {
222  return snipFront( ch, true );
223  }
224 
225  bool snipBackToFirst( const char ch )
226  {
227  return snipBack( ch, true );
228  }
229 
231  virtual int count( const char ch ) const;
232 
235  virtual int length() const;
236 
238  virtual int size() const;
239 
241  virtual std::string stdString() const;
242 
245  virtual const char* string() const;
246 
248  virtual const char* c_str() const;
249 
251  virtual bool isEmpty() const;
252 
255  virtual DtString section(const char sep, int start, int end = -1) const;
256 
257  public:
258 
260  static const DtString& nullString();
261 
264  static const DtString& nullId();
265 
266  protected:
267 
268  friend DT_DLL_VLUTIL std::ostream& operator << ( std::ostream& os, const DtString& str );
269  friend DT_DLL_VLUTIL std::istream& operator >> ( std::istream& is, DtString& str );
270 
275  void clear();
276 
279  void setString( const char* str );
280 
281  protected:
282 
283  enum
284  {
285  theDefaultBufferSize = 64
286  };
287 
288  char myDefaultBuffer[theDefaultBufferSize];
289  char* myString;
290  bool myStringAlloced;
292  unsigned int myBufSize;
293 
294  static const int theMaxInsertionStringSize;
295 
296  };
297 
298 
299  inline bool DtString::isEmpty() const
300  {
301  return (myString[0] == '\0');
302  }
303 
304 #ifdef DtUSE_UTILITIES_NAMESPACE
305 }
306 #endif
const bool operator==(const DtU128 &lhs, const DtU128 &rhs)
virtual bool isEmpty() const
returns true if the string is empty, where empty is size() == 0
Definition: vlString.h:299
bool snipFrontToLast(const char ch)
Definition: vlString.h:220
DtVector operator+(const DtVector &v1, const DtVector &v2)
implements v1 + v2
std::ostream & operator<<(std::ostream &os, const Dt3dChord &chord)
std::istream & operator>>(std::istream &is, Dt3dExtent &extent)
bool snipBackToFirst(const char ch)
Definition: vlString.h:225
char * myString
Use this buffer if possible.
Definition: vlString.h:289
unsigned int myBufSize
Does myString need to be deleted when done?
Definition: vlString.h:292
bool operator<(const DtTimeReflectedObjectIdKey &left, const DtTimeReflectedObjectIdKey &right)
Compare 2 time ID keys.
Definition: reflectedObjectListHLA.h:548
const bool operator!=(const DtU128 &lhs, const DtU128 &rhs)
Instances of DtString are used to represent strings.
Definition: vlString.h:36
This file contains typedefs for machine dependant types.
const bool operator>(const DtU128 &lhs, const DtU128 &rhs)
static const int theMaxInsertionStringSize
current buffer size
Definition: vlString.h:294
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

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)