BaseFile Class Reference

#include <c4d_file.h>

Inheritance diagram for BaseFile:

Detailed Description

Represents a file for reading and writing.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Private Member Functions

 BaseFile ()
 
 ~BaseFile ()
 

Alloc/Free

static BaseFileAlloc ()
 
static void Free (BaseFile *&fl)
 

Open/Close

Bool Open (const Filename &name, FILEOPEN mode=FILEOPEN::READ, FILEDIALOG error_dialog=FILEDIALOG::IGNOREOPEN, BYTEORDER order=BYTEORDER::V_MOTOROLA, Int32 type='C4DC', Int32 creator='C4D1')
 
Bool Close ()
 

Read/Write Bytes

Int ReadBytes (void *data, Int len, Bool just_try_it=false)
 
Int TryReadBytes (void *data, Int len)
 
Bool WriteBytes (const void *data, Int len)
 

File Pointer/Information/Error

Bool Seek (Int64 pos, FILESEEK mode=FILESEEK::RELATIVE_)
 
Int64 GetPosition ()
 
Int64 GetLength ()
 
LOCATION GetLocation () const
 
FILEERROR GetError () const
 
void SetError (FILEERROR error)
 
void SetOrder (BYTEORDER order)
 

Read

Bool ReadChar (Char *v)
 
Bool ReadUChar (UChar *v)
 
Bool ReadInt16 (Int16 *v)
 
Bool ReadUInt16 (UInt16 *v)
 
Bool ReadInt32 (Int32 *v)
 
Bool ReadUInt32 (UInt32 *v)
 
Bool ReadFloat32 (Float32 *v)
 
Bool ReadFloat64 (Float64 *v)
 
Bool ReadInt64 (Int64 *v)
 
Bool ReadUInt64 (UInt64 *v)
 
Bool ReadFilename (Filename *v)
 
Bool ReadBool (Bool *v)
 
Bool ReadString (maxon::String *v)
 
Bool ReadVector32 (Vector32 *v)
 
Bool ReadVector64 (Vector64 *v)
 
Bool ReadMatrix32 (Matrix32 *v)
 
Bool ReadMatrix64 (Matrix64 *v)
 

Write

Bool WriteChar (Char v)
 
Bool WriteUChar (UChar v)
 
Bool WriteInt16 (Int16 v)
 
Bool WriteUInt16 (UInt16 v)
 
Bool WriteInt32 (Int32 v)
 
Bool WriteUInt32 (UInt32 v)
 
Bool WriteFloat32 (Float32 v)
 
Bool WriteFloat64 (Float64 v)
 
Bool WriteInt64 (Int64 v)
 
Bool WriteUInt64 (UInt64 v)
 
Bool WriteFilename (const Filename &v)
 
Bool WriteBool (Bool v)
 
Bool WriteString (const maxon::String &v)
 
Bool WriteVector32 (const Vector32 &v)
 
Bool WriteVector64 (const Vector64 &v)
 
Bool WriteMatrix32 (const Matrix32 &v)
 
Bool WriteMatrix64 (const Matrix64 &v)
 

Constructor & Destructor Documentation

◆ BaseFile()

BaseFile ( )
private

◆ ~BaseFile()

~BaseFile ( )
private

Member Function Documentation

◆ Alloc()

static BaseFile* Alloc ( )
static

Allocates a file. Destroy the allocated file with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated file, or nullptr if the allocation failed.

◆ Free()

static void Free ( BaseFile *&  fl)
static

Destructs files allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]flThe file to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Open()

Bool Open ( const Filename name,
FILEOPEN  mode = FILEOPEN::READ,
FILEDIALOG  error_dialog = FILEDIALOG::IGNOREOPEN,
BYTEORDER  order = BYTEORDER::V_MOTOROLA,
Int32  type = 'C4DC',
Int32  creator = 'C4D1' 
)

Opens a file.

Note
If a plugin has to be cross platform from a PC to a Mac (generally advised) then it must correctly fill in the type and creator parameters which are needed on a Mac.
Parameters
[in]nameThe name of the file to open.
[in]modeThe file access mode: FILEOPEN
[in]error_dialogSet the type of error reporting that should happen while opening the file: FILEDIALOG
[in]orderThe type of byte order in the file: BYTEORDER
[in]typeThe type of file, only applies to Mac: MACTYPE_CINEMA.
[in]creatorThe application that wrote the file, for example 'ttxt' (SimpleText) or 'C4D1' for Cinema 4D, Only relevant to Mac: MACCREATOR_CINEMA.
Returns
true if the file was opened without any problem, otherwise false.

◆ Close()

Bool Close ( )

Closes the file.
Automatically called when a BaseFile object is destroyed.

Returns
true if the file was successfully closed, otherwise false.

◆ ReadBytes()

Int ReadBytes ( void *  data,
Int  len,
Bool  just_try_it = false 
)

Reads a block of bytes from the file.

Warning
Only use this when really needed. Be aware that the byte sequences will not be platform independent.
Parameters
[in]dataThe memory buffer to fill with the bytes from the file. The caller owns the pointed buffer.
[in]lenThe number of bytes to read from the file.
[in]just_try_itIf true and the data retrieved from the file is less than requested, no error will be generated.
Returns
The number of bytes read.

◆ TryReadBytes()

Int TryReadBytes ( void *  data,
Int  len 
)

Reads a block of bytes from the file.
If the end of the file is reached then only the remaining bytes will be read.

Note
Same as calling ReadBytes(data, len, true)
Parameters
[out]dataThe memory buffer to fill with the bytes from the file. The caller owns the pointed buffer.
[in]lenThe number of bytes to try and read from the file.
Returns
The number of bytes read.

◆ WriteBytes()

Bool WriteBytes ( const void *  data,
Int  len 
)

Writes a block of bytes to the file.

Warning
Only use this when really needed. Be aware that the byte sequences will not be platform independent.
Parameters
[in]dataThe memory buffer with the data to write to the file. The caller owns the pointed buffer.
[in]lenThe number of bytes to write to the file.
Returns
true if the bytes were successfully written to the file, otherwise false.

◆ Seek()

Bool Seek ( Int64  pos,
FILESEEK  mode = FILESEEK::RELATIVE_ 
)

Sets the file pointer within the file.

Parameters
[in]posThe position within the file to place the file pointer.
[in]modeSets how the position relates to the file.
Returns
true if the file pointer position was successfully changed, otherwise false.

◆ GetPosition()

Int64 GetPosition ( )

Gets the file pointer.

Returns
The position of the file pointer.

◆ GetLength()

Int64 GetLength ( )

Gets the length of the file in bytes.

Returns
The byte length of the file.

◆ GetLocation()

LOCATION GetLocation ( ) const

Gets the file location.

Returns
The file location: LOCATION

◆ GetError()

FILEERROR GetError ( ) const

Gets the last error during read or write.

Returns
The last error: FILEERROR

◆ SetError()

void SetError ( FILEERROR  error)

Sets the error manually.

Parameters
[in]errorThe error: FILEERROR

◆ SetOrder()

void SetOrder ( BYTEORDER  order)

Sets the byte order of the data in the file.

Parameters
[in]orderThe byte order: BYTEORDER

◆ ReadChar()

Bool ReadChar ( Char v)

Reads a Char from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Char.
Returns
true if the value was read successfully, otherwise false.

◆ ReadUChar()

Bool ReadUChar ( UChar v)

Reads a UChar from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed UChar.
Returns
true if the value was read successfully, otherwise false.

◆ ReadInt16()

Bool ReadInt16 ( Int16 v)

Reads a Int16 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Int16.
Returns
true if the value was read successfully, otherwise false.

◆ ReadUInt16()

Bool ReadUInt16 ( UInt16 v)

Reads a UInt16 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed UInt16.
Returns
true if the value was read successfully, otherwise false.

◆ ReadInt32()

Bool ReadInt32 ( Int32 v)

Reads a Int32 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Int32.
Returns
true if the value was read successfully, otherwise false.

◆ ReadUInt32()

Bool ReadUInt32 ( UInt32 v)

Reads a UInt32 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed UInt32.
Returns
true if the value was read successfully, otherwise false.

◆ ReadFloat32()

Bool ReadFloat32 ( Float32 v)

Reads a Float32 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Float32.
Returns
true if the value was read successfully, otherwise false.

◆ ReadFloat64()

Bool ReadFloat64 ( Float64 v)

Reads a Float64 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Float64.
Returns
true if the value was read successfully, otherwise false.

◆ ReadInt64()

Bool ReadInt64 ( Int64 v)

Reads a Int64 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Int64.
Returns
true if the value was read successfully, otherwise false.

◆ ReadUInt64()

Bool ReadUInt64 ( UInt64 v)

Reads a UInt64 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed UInt64.
Returns
true if the value was read successfully, otherwise false.

◆ ReadFilename()

Bool ReadFilename ( Filename v)

Reads a Filename from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Filename.
Returns
true if the value was read successfully, otherwise false.

◆ ReadBool()

Bool ReadBool ( Bool v)

Reads a Bool from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Bool.
Returns
true if the value was read successfully, otherwise false.

◆ ReadString()

Bool ReadString ( maxon::String v)

Reads a String from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed String.
Returns
true if the value was read successfully, otherwise false.

◆ ReadVector32()

Bool ReadVector32 ( Vector32 v)

Reads a Vector32 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Vector32.
Returns
true if the value was read successfully, otherwise false.

◆ ReadVector64()

Bool ReadVector64 ( Vector64 v)

Reads a Vector64 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Vector64.
Returns
true if the value was read successfully, otherwise false.

◆ ReadMatrix32()

Bool ReadMatrix32 ( Matrix32 v)

Reads a Matrix32 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Matrix32.
Returns
true if the value was read successfully, otherwise false.

◆ ReadMatrix64()

Bool ReadMatrix64 ( Matrix64 v)

Reads a Matrix64 from the file.

Parameters
[out]vAssigned the read value. The caller owns the pointed Matrix64.
Returns
true if the value was read successfully, otherwise false.

◆ WriteChar()

Bool WriteChar ( Char  v)

Writes a Char to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteUChar()

Bool WriteUChar ( UChar  v)

Writes a UChar to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteInt16()

Bool WriteInt16 ( Int16  v)

Writes a Int16 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteUInt16()

Bool WriteUInt16 ( UInt16  v)

Writes a UInt16 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteInt32()

Bool WriteInt32 ( Int32  v)

Writes a Int32 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteUInt32()

Bool WriteUInt32 ( UInt32  v)

Writes a UInt32 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteFloat32()

Bool WriteFloat32 ( Float32  v)

Writes a Float32 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteFloat64()

Bool WriteFloat64 ( Float64  v)

Writes a Float64 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteInt64()

Bool WriteInt64 ( Int64  v)

Writes a Int64 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteUInt64()

Bool WriteUInt64 ( UInt64  v)

Writes a UInt64 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteFilename()

Bool WriteFilename ( const Filename v)

Writes a Filename to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteBool()

Bool WriteBool ( Bool  v)

Writes a Bool to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteString()

Bool WriteString ( const maxon::String v)

Writes a String to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteVector32()

Bool WriteVector32 ( const Vector32 v)

Writes a Vector32 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteVector64()

Bool WriteVector64 ( const Vector64 v)

Writes a Vector64 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteMatrix32()

Bool WriteMatrix32 ( const Matrix32 v)

Writes a Matrix32 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.

◆ WriteMatrix64()

Bool WriteMatrix64 ( const Matrix64 v)

Writes a Matrix64 to the file.

Parameters
[in]vThe value to write to the file.
Returns
true if the value was written successfully, otherwise false.