Primitive Data Types Manual (Classic)
Primitive data types are the building blocks for data stored within Cinema 4D . These data types are typically based on the standard data types of C++ and are available in a 32 and 64 bit version.
// get parameters
// read the "Fillet" parameter if (!cube-> GetParameter ( DescID ( PRIM_CUBE_DOFILLET ), data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); doFillet = data. GetBool ();
// read the "Fillet Radius" parameter if (!cube-> GetParameter ( DescID ( PRIM_CUBE_FRAD ), data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); filletRadius = data. GetFloat ();
// read the "Fillet Subdivision" parameter if (!cube-> GetParameter ( DescID ( PRIM_CUBE_SUBF ), data, DESCFLAGS_GET::NONE )) return maxon::UnexpectedError( MAXON_SOURCE_LOCATION ); filletSubidivision = data. GetInt32 ();
// save to HyperFile AutoAlloc<HyperFile> hyperFile; if (hyperFile == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION );
// open the HyperFile to write if (!hyperFile-> Open ( 'cube' , filename, FILEOPEN::WRITE , FILEDIALOG::ANY )) return maxon::IoError( MAXON_SOURCE_LOCATION , MaxonConvert (filename, MAXONCONVERTMODE::NONE ), "Could not open file." _s); hyperFile-> WriteBool (doFillet); hyperFile-> WriteFloat (filletRadius); hyperFile-> WriteInt32 (filletSubidivision); hyperFile-> 关闭 ();
Boolean values are used for logical operations:
int
.
Bool variables can be created on demand or can be obtained from other entities.
Access Bool values stored in a BaseContainer :
另请参阅 BaseContainer Manual .
Access Bool values stored in a GeData object ( GeData type is DA_LONG ):
另请参阅 GeData Manual .
// This example stores and reads a Boolean value in the GeData object. GeData data; data. SetInt32 ( false );// Boolean values are internally stored as integers if (data. GetType () == DA_LONG ) { // get Boolean value if (data. GetBool ()) ApplicationOutput ( "is true" ); else ApplicationOutput ( "is false" ); }
A Bool value can be stored in a BaseFile 或 HyperFile :
另请参阅 BaseFile Manual on Bool and HyperFile Manual on Bool .
A character variable contains a single symbol and is typically the smallest piece of memory.
char
.
unsigned char
.
UInt16
.
UInt32
.
// convert to c string and insert into std string. Char * cstring = string . GetCStringCopy (); std::string stdString { cstring }; DeleteMem (cstring);
A character can be stored in a BaseFile or HyperFile :
另请参阅 BaseFile Manual on Char and HyperFile Manual on Char .
Integer variables contain whole numbers. Both signed and unsigned variations are available, both in 16, 32 and 64 bit.
short int
.
unsigned short int
.
signed int
.
unsigned int
.
signed long long
.
unsigned long long
.
Int64
.
UInt64
.
Integer values can be created by casting them from float values. To do this safely these macros should be used:
Integer variables can be obtained from other entities.
Access integer values stored in a BaseContainer :
另请参阅 BaseContainer Manual .
Access Int32 or Int64 values stored in a GeData object ( GeData type is DA_LONG or DA_LLONG ):
另请参阅 GeData Manual .
String objects can be parsed to get the numeric value represented by the string:
另请参阅 String Manual (Classic) .
// This example converts a string into an integer number. const String bottles = "99 bottles of beer on the wall" ; const String number = bottles. Left (2); const Int32 numberOfBottles = number. ToInt32 ( nullptr );To display them in the GUI, integer numbers also can be converted to String objects:
另请参阅 String Manual (Classic) .
// This example prints the number of selected objects to the console. AutoAlloc<AtomArray> selection; if (selection == nullptr ) return maxon::OutOfMemoryError( MAXON_SOURCE_LOCATION ); doc-> GetActiveObjects (selection, GETACTIVEOBJECTFLAGS::NONE ); const Int32 selCount = selection-> GetCount (); ApplicationOutput ( String::IntToString (selCount) + " object(s) selected" );An integer value can be stored in a BaseFile 或 HyperFile :
另请参阅 BaseFile Manual on 整数 and HyperFile Manual on 整数 .
Floating point numbers present rational numbers with limited precision. Variations are available in 32 and 64 bit.
float
.
double
.
Float64
.
Floating point variables can be obtained from other entities.
Access float values stored in a BaseContainer :
另请参阅 BaseContainer Manual .
Access float values stored in a GeData object ( GeData type is DA_REAL ):
另请参阅 GeData Manual .
Of course it is also possible to cast integer types into float values. Just be aware of the limited precision of different float formats.
String objects can be parsed to get the numeric value represented by the string:
Since floating point values are only stored with limited precision they cannot represent every value perfectly. This is especially critical when it is needed to compare two floating point values:
// compare float values if ( CompareFloatTolerant (sum, reference)) ApplicationOutput ( "The float values are really close to each other." );
To display them in the GUI, floating point numbers also can be converted to String objects:
A floating point value can be stored in a BaseFile 或 HyperFile :
另请参阅 BaseFile Manual on Float and HyperFile Manual on Float .