3ds Max C++ API Reference
MaxStringCast< ChType > Class Template Reference

A MaxStringCast is used when casting a MaxString to a type. More...

#include <maxstring.h>

+ Inheritance diagram for MaxStringCast< ChType >:

Public Member Functions

 MaxStringCast ()
 
 MaxStringCast (const MaxString &string, const ChType *w)
 
 operator const ChType * () const
 Returns a const pointer to the string. More...
 
const ChType * data () const
 Returns a const pointer to the string. More...
 
const ChType * null_data () const
 Returns a const pointer pointer to 0. More...
 
bool isNull () const
 returns true if this string is null or empty, false otherwise More...
 
const MaxStringCast< wchar_t > ToMCHAR (size_t *length=NULL) const
 Cast this object to a MCHAR. More...
 
const MaxStringCast< wchar_t > ToOLESTR (size_t *length=NULL) const
 Cast this object to a wchar_t. More...
 
const MaxStringowner () const
 Returns a const ref to the owning MaxString. More...
 

Protected Attributes

MaxString p
 
const ChType * buf
 

Additional Inherited Members

- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

template<typename ChType>
class MaxSDK::Util::MaxStringCast< ChType >

A MaxStringCast is used when casting a MaxString to a type.

It holds

  1. A MaxString, which increments the ref count on the MaxStringData (so the MaxStringData pointer won't be deleted)
  2. A pointer to the appropriate string buffer in the MaxStringData.

So, the string pointer is guaranteed to be valid as along as the MaxStringCast instance is alive. Warning: If you cast directly to a, for example, char*, then something else could operate on the MaxString causing it to delete the string buffer in the MaxStringData, and you would be left holding a dangling pointer.

Note, data held by this class should be treated as read only and not modifiable. Thus its operator methods only convert to constant types. For instance if used with a char type, its operators will only return a const char*. If you want a char* type need to create a copy instead. Therefore do not use const_cast<> with this class.

Constructor & Destructor Documentation

◆ MaxStringCast() [1/2]

MaxStringCast ( )
inline
388  : buf(NULL)
389  {
390  }
#define NULL
Definition: autoptr.h:18
const ChType * buf
Definition: maxstring.h:384

◆ MaxStringCast() [2/2]

MaxStringCast ( const MaxString string,
const ChType *  w 
)
inline
393  : p(string)
394  , buf(w)
395  {
396  }
MaxString p
Definition: maxstring.h:383

Member Function Documentation

◆ operator const ChType *()

operator const ChType * ( ) const
inline

Returns a const pointer to the string.

If the string is NULL, a pointer to 0 is returned.

401  {
402  return (buf) ? buf: null_data();
403  }
const ChType * null_data() const
Returns a const pointer pointer to 0.
Definition: maxstring.h:412

◆ data()

const ChType* data ( ) const
inline

Returns a const pointer to the string.

If the string is NULL, a pointer to 0 is returned.

407  {
408  return (buf) ? buf: null_data();
409  }

◆ null_data()

const ChType* null_data ( ) const
inline

Returns a const pointer pointer to 0.

413  {
414  static ChType null_char = 0;
415  return &null_char;
416  }

◆ isNull()

bool isNull ( ) const
inline

returns true if this string is null or empty, false otherwise

422  {
423  return 0 == data()[0];
424  }
const ChType * data() const
Returns a const pointer to the string.
Definition: maxstring.h:406

◆ ToMCHAR()

const MaxStringCast<wchar_t> ToMCHAR ( size_t length = NULL) const
inline

Cast this object to a MCHAR.

The string returned is valid as long as the MaxStringCast exists.

433  {
434  return p.ToUTF16(length);
435  }
MaxStringCast< wchar_t > ToUTF16(size_t *length=NULL) const
Cast this object to a UTF16 or UNICODE encoded string.

◆ ToOLESTR()

const MaxStringCast<wchar_t> ToOLESTR ( size_t length = NULL) const
inline

Cast this object to a wchar_t.

The string returned is valid as long as the MaxStringCast exists.

452  {
453  return p.ToUTF16(length);
454  }

◆ owner()

const MaxString& owner ( ) const
inline

Returns a const ref to the owning MaxString.

458  {
459  return p;
460  }

Member Data Documentation

◆ p

MaxString p
protected

◆ buf

const ChType* buf
protected