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.

注意
To perform mathematical operations using these data types use the build-in functions, see Mathematical Functions Manual (Classic) .
警告
An overview over MAXON API primitive data types can be found here: Basic Data Types .
// This example reads the "Fillet" settings of the selected Cube object // and writes them into a HyperFile.
Bool doFillet = false ; Float filletRadius = 20.0; Int32 filletSubidivision = 5;

// get parameters

GeData data;

// 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-> 关闭 ();

Bool

Boolean values are used for logical operations:

Access

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" ); }

Disc I/O

A Bool value can be stored in a BaseFile HyperFile :

另请参阅 BaseFile Manual on Bool and HyperFile Manual on Bool .

Char

A character variable contains a single symbol and is typically the smallest piece of memory.

// This example converts the given String into a C-String to use it with the standard library. const String string { "foobar" };

// convert to c string and insert into std string. Char * cstring = string . GetCStringCopy (); std::string stdString { cstring }; DeleteMem (cstring);

Disc I/O

A character can be stored in a BaseFile or HyperFile :

注意
To read and write Utf16Char and Utf32Char use BaseFile::ReadBytes() and BaseFile::WriteBytes() .

另请参阅 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.

注意
If larger integer numbers are needed the class maxon::BigInteger 可以使用。

Access

Integer values can be created by casting them from float values. To do this safely these macros should be used:

警告
Never try to cast an integer pointer into a float pointer or vice versa.
// This example performs a float point operation and safely converts the result to an integer. const Float32 percentage = 0.23f; const Int32 width = 1280; const Float32 pos = Float32 (width) * percentage; const Int32 pixel = SAFEINT32 (pos); ApplicationOutput ( "Pixel: " + String::IntToString (pixel));

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" );

Disc I/O

An integer value can be stored in a BaseFile HyperFile :

另请参阅 BaseFile Manual on 整数 and HyperFile Manual on 整数 .

Float

Floating point numbers present rational numbers with limited precision. Variations are available in 32 and 64 bit.

Access

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.

警告
Never try to cast an integer pointer into a float pointer or vice versa.

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:

// This example compares the result of a float operation with a given float value. const Float32 x = 0.1f; const Float32 y = 0.2f; const Float32 reference = 0.3f; const Float32 sum = x + y;

// 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:

// This example converts the given float value to a String with two digits after the comma. const Float32 value = 123.456f; ApplicationOutput ( "Value: " + String::FloatToString (value, -1, 2));

Disc I/O

A floating point value can be stored in a BaseFile HyperFile :

另请参阅 BaseFile Manual on Float and HyperFile Manual on Float .

延伸阅读

GeData::GetBool
Bool GetBool(void) const
定义: c4d_gedata.h:421
String::FloatToString
static String FloatToString(Float32 v, Int32 vvk=-1, Int32 nnk=-3)
定义: c4d_string.h:529
DA_LONG
@ DA_LONG
Int32.
定义: c4d_gedata.h:40
String::ToInt32
Int32 ToInt32(Bool *error) const
定义: c4d_string.h:598
DescID
定义: lib_description.h:327
GeData::GetType
Int32 GetType(void) const
定义: c4d_gedata.h:407
FILEDIALOG::ANY
@ ANY
Show an error dialog for any error.
Float
maxon::Float Float
定义: ge_sys_math.h:64
String::GetCStringCopy
Char * GetCStringCopy(STRINGENCODING type=STRINGENCODING::XBIT) const
Float32
maxon::Float32 Float32
定义: ge_sys_math.h:66
GETACTIVEOBJECTFLAGS::NONE
@ NONE
None.
SAFEINT32
Int32 SAFEINT32(Float32 x)
定义: apibasemath.h:266
AtomArray::GetCount
Int32 GetCount() const
定义: c4d_baselist.h:1619
MAXONCONVERTMODE::NONE
@ NONE
No check if file exists under case-sensitive drives.
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
HyperFile::WriteInt32
Bool WriteInt32(Int32 v)
HyperFile::Open
Bool Open(Int32 ident, const Filename &filename, FILEOPEN mode, FILEDIALOG error_dialog)
MaxonConvert
maxon::Url MaxonConvert(const Filename &fn, MAXONCONVERTMODE convertMode)
String
定义: c4d_string.h:38
String::IntToString
static String IntToString(Int32 v)
定义: c4d_string.h:495
FILEOPEN::WRITE
@ WRITE
GeData::GetInt32
Int32 GetInt32(void) const
定义: c4d_gedata.h:427
PRIM_CUBE_FRAD
@ PRIM_CUBE_FRAD
定义: ocube.h:11
maxon::DeleteMem
void DeleteMem(T *&p)
定义: defaultallocator.h:258
BaseDocument::GetActiveObjects
void GetActiveObjects(AtomArray &selection, GETACTIVEOBJECTFLAGS flags) const
GeData
定义: c4d_gedata.h:82
GeData::SetInt32
void SetInt32(Int32 v)
定义: c4d_gedata.h:573
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
ApplicationOutput
#define ApplicationOutput(formatString,...)
定义: debugdiagnostics.h:207
HyperFile::WriteFloat
Bool WriteFloat(Float v)
HyperFile::WriteBool
Bool WriteBool(Bool v)
String::Left
String Left(Int count) const
定义: c4d_string.h:411
PRIM_CUBE_SUBF
@ PRIM_CUBE_SUBF
定义: ocube.h:12
HyperFile::Close
Bool Close()
AutoAlloc
定义: ge_autoptr.h:36
DESCFLAGS_GET::NONE
@ NONE
None.
Bool
maxon::Bool Bool
定义: ge_sys_math.h:53
CompareFloatTolerant
Bool CompareFloatTolerant(Float32 a, Float32 b)
PRIM_CUBE_DOFILLET
@ PRIM_CUBE_DOFILLET
定义: ocube.h:13
Char
maxon::Char Char
定义: ge_sys_math.h:54
C4DAtom::GetParameter
Bool GetParameter(const DescID &id, GeData &t_data, DESCFLAGS_GET flags)
GeData::GetFloat
Float GetFloat(void) const
定义: c4d_gedata.h:439

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1