Rebel Fork Framework
Urho3D::File Class Reference

File opened either through the filesystem or from within a package file. More...

#include <Urho3D/IO/File.h>

Inheritance diagram for Urho3D::File:
Urho3D::Object Urho3D::AbstractFile Urho3D::RefCounted Urho3D::Deserializer Urho3D::Serializer

Public Member Functions

 File (Context *context)
 Construct.
 
 File (Context *context, const ea::string &fileName, FileMode mode=FILE_READ)
 Construct and open a filesystem file.
 
 File (Context *context, PackageFile *package, const ea::string &fileName)
 Construct and open from a package file.
 
 ~File () override
 Destruct. Close the file if open.
 
unsigned Read (void *dest, unsigned size) override
 Read bytes from the file. Return number of bytes actually read. More...
 
unsigned Seek (unsigned position) override
 Set position from the beginning of the file.
 
unsigned Write (const void *data, unsigned size) override
 Write bytes to the file. Return number of bytes actually written.
 
const ea::string & GetAbsoluteName () const override
 Return absolute file name in file system.
 
unsigned GetChecksum () override
 Return a checksum of the file contents using the SDBM hash algorithm.
 
bool Open (const ea::string &fileName, FileMode mode=FILE_READ)
 Open a filesystem file. Return true if successful.
 
bool Open (PackageFile *package, const ea::string &fileName)
 Open from within a package file. Return true if successful.
 
void Close () override
 Close the file.
 
void Flush ()
 Flush any buffered output to the file.
 
FileMode GetMode () const
 
bool IsOpen () const override
 
void * GetHandle () const
 Return the file handle.
 
bool IsPackaged () const
 
void ReadBinary (ea::vector< unsigned char > &buffer)
 Reads a binary file to buffer.
 
ea::vector< unsigned char > ReadBinary ()
 Reads a binary file to buffer.
 
virtual void ReadText (ea::string &text)
 Reads a text file, ensuring data from file is 0 terminated.
 
virtual ea::string ReadText ()
 Reads a text file, ensuring data from file is 0 terminated.
 
bool Copy (File *srcFile)
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
 ~Object () override
 Destruct. Clean up self from event sender & receiver structures.
 
virtual StringHash GetType () const =0
 
virtual const ea::string & GetTypeName () const =0
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual bool IsInstanceOf (StringHash type) const =0
 Check whether current instance implements specified type.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
virtual void SerializeInBlock (Archive &archive)
 Serialize content from/to archive. May throw ArchiveException.
 
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
 
template<typename T >
T * Cast ()
 Cast the object to specified most derived class.
 
template<typename T >
const T * Cast () const
 Cast the object to specified most derived class.
 
void SubscribeToEventManual (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEventManual (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
template<class T >
void SubscribeToEvent (StringHash eventType, T handler)
 Subscribe to an event that can be sent by any sender.
 
template<class T >
void SubscribeToEvent (Object *sender, StringHash eventType, T handler)
 Subscribe to a specific sender's event.
 
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
 
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
 
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
 
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
 
void UnsubscribeFromAllEventsExcept (const ea::vector< StringHash > &exceptions)
 Unsubscribe from all events except those listed.
 
void UnsubscribeFromAllEventsExcept (const ea::vector< Object * > &exceptions)
 Unsubscribe from all events except those with listed senders.
 
void SendEvent (StringHash eventType)
 Send event to all subscribers.
 
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
template<typename... Args>
void SendEvent (StringHash eventType, const Args &... args)
 Send event with variadic parameter pairs to all subscribers. The parameters are (paramID, paramValue) pairs.
 
ContextGetContext () const
 Return execution context.
 
const VariantGetGlobalVar (StringHash key) const
 
const VariantMapGetGlobalVars () const
 
void SetGlobalVar (StringHash key, const Variant &value)
 
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
 
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
 
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
 
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
 
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
 
bool HasEventHandlers () const
 Return whether has subscribed to any event.
 
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
 
const ea::string & GetCategory () const
 
void SendEvent (StringHash eventType, const VariantMap &eventData)
 Send event with parameters to all subscribers.
 
void SetBlockEvents (bool block)
 Block object from sending and receiving events.
 
bool GetBlockEvents () const
 Return sending and receiving events blocking status.
 
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
 
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 
 RefCounted (const RefCounted &rhs)=delete
 Prevent copy construction.
 
RefCountedoperator= (const RefCounted &rhs)=delete
 Prevent assignment.
 
int AddRef ()
 
int ReleaseRef ()
 
int Refs () const
 
int WeakRefs () const
 
RefCountRefCountPtr () const
 Return pointer to the reference count structure.
 
bool HasScriptObject () const
 Return true if script runtime object wrapping this native object exists.
 
bool IsScriptStrongRef () const
 Return true if script reference is strong.
 
- Public Member Functions inherited from Urho3D::AbstractFile
 AbstractFile ()
 Construct.
 
 AbstractFile (unsigned int size)
 Construct.
 
 ~AbstractFile () override=default
 Destruct.
 
virtual void SetName (const ea::string &name)
 
const ea::string & GetName () const override
 Return the file name.
 
- Public Member Functions inherited from Urho3D::Deserializer
 Deserializer ()
 Construct with zero size.
 
 Deserializer (unsigned size)
 Construct with defined size.
 
virtual ~Deserializer ()
 Destruct.
 
virtual bool IsEof () const
 
unsigned SeekRelative (int delta)
 Set position relative to current position. Return actual new position.
 
unsigned GetPosition () const
 
unsigned Tell () const
 Return current position.
 
unsigned GetSize () const
 
long long ReadInt64 ()
 Read a 64-bit integer.
 
int ReadInt ()
 Read a 32-bit integer.
 
short ReadShort ()
 Read a 16-bit integer.
 
signed char ReadByte ()
 Read an 8-bit integer.
 
unsigned long long ReadUInt64 ()
 Read a 64-bit unsigned integer.
 
unsigned ReadUInt ()
 Read a 32-bit unsigned integer.
 
unsigned short ReadUShort ()
 Read a 16-bit unsigned integer.
 
unsigned char ReadUByte ()
 Read an 8-bit unsigned integer.
 
bool ReadBool ()
 Read a bool.
 
float ReadFloat ()
 Read a float.
 
double ReadDouble ()
 Read a double.
 
IntRect ReadIntRect ()
 Read an IntRect.
 
IntVector2 ReadIntVector2 ()
 Read an IntVector2.
 
IntVector3 ReadIntVector3 ()
 Read an IntVector3.
 
Rect ReadRect ()
 Read a Rect.
 
Vector2 ReadVector2 ()
 Read a Vector2.
 
Vector3 ReadVector3 ()
 Read a Vector3.
 
Vector3 ReadPackedVector3 (float maxAbsCoord)
 Read a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
 
Vector4 ReadVector4 ()
 Read a Vector4.
 
Quaternion ReadQuaternion ()
 Read a quaternion.
 
Quaternion ReadPackedQuaternion ()
 Read a quaternion with each component packed in 16 bits.
 
Matrix3 ReadMatrix3 ()
 Read a Matrix3.
 
Matrix3x4 ReadMatrix3x4 ()
 Read a Matrix3x4.
 
Matrix4 ReadMatrix4 ()
 Read a Matrix4.
 
Color ReadColor ()
 Read a color.
 
BoundingBox ReadBoundingBox ()
 Read a bounding box.
 
ea::string ReadString ()
 Read a null-terminated string.
 
ea::string ReadFileID ()
 Read a four-letter file ID.
 
StringHash ReadStringHash ()
 Read a 32-bit StringHash.
 
ByteVector ReadBuffer ()
 Read a buffer with size encoded as VLE.
 
void ReadBuffer (ByteVector &byteVector)
 Read a buffer with size encoded as VLE (inplace).
 
ResourceRef ReadResourceRef ()
 Read a resource reference.
 
ResourceRefList ReadResourceRefList ()
 Read a resource reference list.
 
Variant ReadVariant ()
 Read a variant.
 
Variant ReadVariant (VariantType type, Context *context=nullptr)
 Read a variant whose type is already known. Context is required for SharedPtr<Serializable>.
 
VariantVector ReadVariantVector ()
 Read a variant vector.
 
StringVector ReadStringVector ()
 Read a string vector.
 
VariantMap ReadVariantMap ()
 Read a variant map.
 
StringVariantMap ReadStringVariantMap ()
 Read a string variant map.
 
unsigned ReadVLE ()
 Read a variable-length encoded unsigned integer.
 
ea::string ReadLine ()
 Read a text line.
 
- Public Member Functions inherited from Urho3D::Serializer
virtual ~Serializer ()
 Destruct.
 
bool WriteInt64 (long long value)
 Write a 64-bit integer.
 
bool WriteInt (int value)
 Write a 32-bit integer.
 
bool WriteShort (short value)
 Write a 16-bit integer.
 
bool WriteByte (signed char value)
 Write an 8-bit integer.
 
bool WriteUInt64 (unsigned long long value)
 Write a 64-bit unsigned integer.
 
bool WriteUInt (unsigned value)
 Write a 32-bit unsigned integer.
 
bool WriteUShort (unsigned short value)
 Write a 16-bit unsigned integer.
 
bool WriteUByte (unsigned char value)
 Write an 8-bit unsigned integer.
 
bool WriteBool (bool value)
 Write a bool.
 
bool WriteFloat (float value)
 Write a float.
 
bool WriteDouble (double value)
 Write a double.
 
bool WriteIntRect (const IntRect &value)
 Write an IntRect.
 
bool WriteIntVector2 (const IntVector2 &value)
 Write an IntVector2.
 
bool WriteIntVector3 (const IntVector3 &value)
 Write an IntVector3.
 
bool WriteRect (const Rect &value)
 Write a Rect.
 
bool WriteVector2 (const Vector2 &value)
 Write a Vector2.
 
bool WriteVector3 (const Vector3 &value)
 Write a Vector3.
 
bool WritePackedVector3 (const Vector3 &value, float maxAbsCoord)
 Write a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
 
bool WriteVector4 (const Vector4 &value)
 Write a Vector4.
 
bool WriteQuaternion (const Quaternion &value)
 Write a quaternion.
 
bool WritePackedQuaternion (const Quaternion &value)
 Write a quaternion with each component packed in 16 bits.
 
bool WriteMatrix3 (const Matrix3 &value)
 Write a Matrix3.
 
bool WriteMatrix3x4 (const Matrix3x4 &value)
 Write a Matrix3x4.
 
bool WriteMatrix4 (const Matrix4 &value)
 Write a Matrix4.
 
bool WriteColor (const Color &value)
 Write a color.
 
bool WriteBoundingBox (const BoundingBox &value)
 Write a bounding box.
 
bool WriteString (ea::string_view value)
 Write a null-terminated string.
 
bool WriteString (std::string_view value)
 
bool WriteString (const char *value)
 
bool WriteFileID (const ea::string &value)
 Write a four-letter file ID. If the string is not long enough, spaces will be appended.
 
bool WriteStringHash (const StringHash &value)
 Write a 32-bit StringHash.
 
bool WriteBuffer (const ea::vector< unsigned char > &value)
 Write a buffer, with size encoded as VLE.
 
bool WriteResourceRef (const ResourceRef &value)
 Write a resource reference.
 
bool WriteResourceRefList (const ResourceRefList &value)
 Write a resource reference list.
 
bool WriteVariant (const Variant &value)
 Write a variant.
 
bool WriteVariantData (const Variant &value)
 Write a variant without the type information.
 
bool WriteVariantVector (const VariantVector &value)
 Write a variant vector.
 
bool WriteStringVector (const StringVector &value)
 Write a variant vector.
 
bool WriteVariantMap (const VariantMap &value)
 Write a variant map.
 
bool WriteStringVariantMap (const StringVariantMap &value)
 Write a string variant map.
 
bool WriteVLE (unsigned value)
 Write a variable-length encoded unsigned integer.
 
bool WriteLine (const ea::string &value)
 Write a text line. Char codes 13 & 10 will be automatically appended.
 

Private Member Functions

 URHO3D_OBJECT (File, Object)
 
bool OpenInternal (const ea::string &fileName, FileMode mode, bool fromPackage=false)
 Open file internally using either C standard IO functions or SDL RWops for Android asset files. Return true if successful.
 
bool ReadInternal (void *dest, unsigned size)
 Perform the file read internally using either C standard IO functions or SDL RWops for Android asset files. Return true if successful. This does not handle compressed package file reading.
 
void SeekInternal (unsigned newPosition)
 Seek in file internally using either C standard IO functions or SDL RWops for Android asset files.
 

Private Attributes

ea::string absoluteFileName_
 Absolute file name.
 
FileMode mode_
 Open mode.
 
void * handle_
 File handle.
 
ea::shared_array< unsigned char > readBuffer_
 Read buffer for Android asset or compressed file loading.
 
ea::shared_array< unsigned char > inputBuffer_
 Decompression input buffer for compressed file loading.
 
unsigned readBufferOffset_
 Read buffer position.
 
unsigned readBufferSize_
 Bytes in the current read buffer.
 
unsigned offset_
 Start position within a package file, 0 for regular files.
 
unsigned checksum_
 Content checksum.
 
bool compressed_
 Compression flag.
 
bool readSyncNeeded_
 Synchronization needed before read -flag.
 
bool writeSyncNeeded_
 Synchronization needed before write -flag.
 

Additional Inherited Members

- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.
 
- Static Public Attributes inherited from Urho3D::Object
static constexpr ea::array< StringHash, 0 > TypeHierarchy {}
 
- Protected Attributes inherited from Urho3D::Object
WeakPtr< Contextcontext_
 Execution context.
 
- Protected Attributes inherited from Urho3D::AbstractFile
ea::string name_
 File name.
 
- Protected Attributes inherited from Urho3D::Deserializer
unsigned position_
 Stream position.
 
unsigned size_
 Stream size.
 

Detailed Description

File opened either through the filesystem or from within a package file.

Member Function Documentation

◆ Copy()

bool Urho3D::File::Copy ( File srcFile)

Copy a file from a source file, must be opened and FILE_WRITE Unlike FileSystem.Copy this copy works when the source file is in a package file

◆ GetMode()

FileMode Urho3D::File::GetMode ( ) const
inline

Return the open mode.

◆ IsOpen()

bool Urho3D::File::IsOpen ( ) const
overridevirtual

Return whether is open.

Reimplemented from Urho3D::AbstractFile.

◆ IsPackaged()

bool Urho3D::File::IsPackaged ( ) const
inline

Return whether the file originates from a package.

◆ Read()

unsigned Urho3D::File::Read ( void *  dest,
unsigned  size 
)
overridevirtual

Read bytes from the file. Return number of bytes actually read.

Implements Urho3D::Deserializer.


The documentation for this class was generated from the following files: