3ds Max C++ API Reference
MaxString Class Reference

Stores all the strings inside CStr and WStr. More...

#include <maxstring.h>

+ Inheritance diagram for MaxString:

Public Member Functions

 MaxString ()
 
 MaxString (const MaxString &)
 Copy Constructor The implementation of this function can be considered cheap in processor and memory usage. More...
 
 ~MaxString ()
 Destructor. More...
 
MaxStringoperator= (const MaxString &)
 
MaxString operator+ (const MaxString &) const
 Create a new string that is the concatenation of this string and another. More...
 
MaxStringoperator+= (const MaxString &)
 Appends a string at the end of this string. More...
 
int Compare (const MaxString &) const
 Check if the strings are equal. More...
 
int CompareIgnoreCase (const MaxString &) const
 Compare this string with another while ignoring the case. More...
 
bool operator== (const MaxString &) const
 Equality operator. More...
 
bool operator!= (const MaxString &) const
 Inequality operator. More...
 
bool operator< (const MaxString &) const
 Returns true if this string is less than the other; otherwise false. More...
 
bool operator<= (const MaxString &) const
 Returns true if this string is less than or equal to the other; otherwise false. More...
 
bool operator> (const MaxString &) const
 Returns true if this string is greater than the other; otherwise false. More...
 
bool operator>= (const MaxString &) const
 Returns true if this string is greater than or equal to the other; otherwise false. More...
 
bool IsNull () const
 Determine if this string is null. Note: an empty string is not null. More...
 
void SetNull ()
 Clears the data of this object. More...
 
char * AllocBufferCP (UINT codepage, size_t bytes)
 Allocate a new string inside this object and returns a modifiable pointer to it. More...
 
char * AllocBufferACP (size_t bytes)
 
char * AllocBufferUTF8 (size_t bytes)
 
wchar_t * AllocBufferUTF16 (size_t wchars)
 
unsigned intAllocBufferUTF32 (size_t uint)
 
void SetCP (UINT codepage, const char *string, size_t length=(size_t) -1)
 Reinitializes the instance with the specified string and code page. More...
 
void SetACP (const char *string, size_t length=(size_t) -1)
 Reinitializes the instance with the specified Active Code Page (ACP) string. More...
 
void SetUTF8 (const char *string, size_t length=(size_t) -1)
 Reinitializes the instance with the specified UTF8 string. More...
 
void SetUTF16 (const wchar_t *string, size_t length=(size_t) -1)
 Reinitializes the instance with the specified UTF16 string. More...
 
MaxStringCastCP ToCP (UINT codepage, size_t *length=NULL) const
 Returns a MaxStringCastCP which in turn enables casting to a char array encoded with a specific code page. More...
 
MaxStringCast< char > ToACP (size_t *length=NULL) const
 Cast this object to a char array using Active Code Page encoding. More...
 
MaxStringCastUTF8 ToUTF8 (size_t *length=NULL) const
 Cast this object to a UTF8 encoded string. More...
 
MaxStringCast< wchar_t > ToUTF16 (size_t *length=NULL) const
 Cast this object to a UTF16 or UNICODE encoded string. More...
 
MaxStringCast< unsigned intToUTF32 (size_t *length=NULL) const
 Cast this object to a UTF32 encoded string. More...
 
size_t Length (UINT encoding) const
 Get the number of characters in the string, based on the encoding. More...
 
int ConversionCount () const
 Returns the number of times this string has been converted to other encodings. More...
 
size_t AllocatedChars () const
 Returns the number of characters allocated in memory, in which the string is stored. More...
 
UINT CommonLosslessCP (MaxString &)
 Gets a common code page. More...
 
wchar_t * AllocBuffer (size_t s)
 
const MaxStringCast< wchar_t > ToMCHAR (size_t *length=NULL) const
 
wchar_t * ToBSTR () const
 Return a BSTR of this string. More...
 
const MaxStringCast< wchar_t > ToOLESTR (size_t *length=NULL) const
 Construct a OLE string. More...
 

Static Public Member Functions

static MaxString FromCP (UINT codepage, const char *string, size_t length=(size_t) -1)
 Construct a MaxString that will contain a copy of a string passed in. More...
 
static MaxString FromACP (const char *string, size_t length=(size_t) -1)
 Construct a MaxString from an Active Code Page encoded string. More...
 
static MaxString FromUTF8 (const char *string, size_t length=(size_t) -1)
 Construct a MaxString from a UTF8 encoded string. More...
 
static MaxString FromUTF16 (const wchar_t *string, size_t length=(size_t) -1)
 Construct a MaxString from a UTF16 encoded wide string. More...
 
static MaxString FromUTF32 (const unsigned int *string, size_t length=(size_t) -1)
 Construct a MaxString from a UTF32 encoded wide string. More...
 
static MaxString FromWin32Error (DWORD err)
 Generate a MaxString out of Win32 error code. More...
 
static MaxString FromAnsiError (int err)
 Generate a MaxString out of an ANSI error code. More...
 
static UINT NormalizeCP (UINT code)
 Normalize the code page. More...
 
static UINT CommonLosslessCP (UINT codepage1, UINT codepage2)
 Gets a common code page. More...
 
static MaxString FromMCHAR (const wchar_t *string, size_t length=(size_t) -1)
 
static MaxString FromBSTR (const wchar_t *string, size_t length=(size_t) -1)
 Construct a MaxString out of a BSTR. More...
 
static MaxString FromOLESTR (const wchar_t *string, size_t length=(size_t) -1)
 Construct a MaxString out of a OLESTR. More...
 
- 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...
 

Protected Member Functions

 MaxString (MaxStringData *data)
 Alternate protected constructor. More...
 
MaxStringoperator= (MaxStringData *data)
 protected assignment operator for an internal data type. More...
 

Protected Attributes

MaxStringData * p
 The data member that holds all encoding and string information. More...
 

Friends

class MaxStringInternal
 

Detailed Description

Stores all the strings inside CStr and WStr.

CStr and WStr use this class to perform their internal operations and hold different encodings for a string. It has several goals:

  • Limit the number of conversions between codepage and string format. (ACP -> UTF8 -> UTF16) This is done by storing several version of the same string.
  • Limit the number of string copies. This class uses a lazy copy algorithm. Several MaxString objects will use the same memory blocks, and are copied prior to modification.
  • Prevent loss of information. String operations done with this object will use the most-optimized way of performing a string operation. ie. Concatenating an UTF-16 string with a ACP string will give a UTF-16 string. Note: ACP: Active Code Page is abbreviated as ACP. Depending on the Windows active language, the active code page can be different. ACP always refer to the code page that Windows API functions expect.

Constructor & Destructor Documentation

◆ MaxString()

MaxString ( MaxStringData *  data)
protected

Alternate protected constructor.

Member Function Documentation

◆ operator=()

MaxString& operator= ( MaxStringData *  data)
protected

protected assignment operator for an internal data type.

◆ IsNull()

bool IsNull ( ) const

Determine if this string is null. Note: an empty string is not null.

◆ SetNull()

void SetNull ( )

Clears the data of this object.

◆ AllocBufferCP()

char* AllocBufferCP ( UINT  codepage,
size_t  bytes 
)

Allocate a new string inside this object and returns a modifiable pointer to it.

You can modify this string as long as you don't perform any other operation with this object's instance.

◆ AllocBufferACP()

char* AllocBufferACP ( size_t  bytes)

◆ AllocBufferUTF8()

char* AllocBufferUTF8 ( size_t  bytes)

◆ AllocBufferUTF16()

wchar_t* AllocBufferUTF16 ( size_t  wchars)

◆ AllocBufferUTF32()

unsigned int* AllocBufferUTF32 ( size_t  uint)

◆ Length()

size_t Length ( UINT  encoding) const

Get the number of characters in the string, based on the encoding.

◆ ConversionCount()

int ConversionCount ( ) const

Returns the number of times this string has been converted to other encodings.

◆ AllocatedChars()

size_t AllocatedChars ( ) const

Returns the number of characters allocated in memory, in which the string is stored.

(Including the NULL character). This is different from the number of characters actually stored for the string. Thus this can be bigger than the length of the string. It might actually be a little bit bigger than the length of the string if this object was manipulated with AllocBufferCP() or AllocBufferUTF16().

◆ AllocBuffer()

wchar_t* AllocBuffer ( size_t  s)
inline
See also
AllocBufferUTF16
AllocBufferACP
318 { return AllocBufferUTF16(s); }
wchar_t * AllocBufferUTF16(size_t wchars)

◆ ToMCHAR()

const MaxStringCast< wchar_t > ToMCHAR ( size_t length = NULL) const
inline
See also
ToUTF16
ToACP
500 {
501  return ToUTF16(length);
502 }
MaxStringCast< wchar_t > ToUTF16(size_t *length=NULL) const
Cast this object to a UTF16 or UNICODE encoded string.

◆ FromMCHAR()

static MaxString FromMCHAR ( const wchar_t *  string,
size_t  length = (size_t)-1 
)
inlinestatic
See also
FromUTF16
FromACP
330 { return FromUTF16(string, length); }
static MaxString FromUTF16(const wchar_t *string, size_t length=(size_t) -1)
Construct a MaxString from a UTF16 encoded wide string.

Friends And Related Function Documentation

◆ MaxStringInternal

friend class MaxStringInternal
friend

Member Data Documentation

◆ p

MaxStringData* p
protected

The data member that holds all encoding and string information.