# File Class Reference

A stream file class. More...

`#include <yateclass.h>`

Inheritance diagram for File:

List of all members.

## Public Member Functions

| File ()
| File (HANDLE handle)
virtual | ~File ()
virtual bool | openPath (const char *name, bool canWrite=false, bool canRead=true, bool create=false, bool append=false, bool binary=false)
virtual bool | terminate ()
void | attach (HANDLE handle)
HANDLE | detach ()
HANDLE | handle () const
virtual bool | canRetry () const
virtual bool | valid () const
virtual bool | setBlocking (bool block=true)
virtual unsigned int | length ()
virtual int | writeData (const void *buffer, int length)
virtual int | readData (void *buffer, int length)

## Static Public Member Functions

static HANDLE | invalidHandle ()
static bool | remove (const char *name)
static bool | createPipe (File &reader, File &writer)

## Protected Member Functions

void | copyError ()

## Protected Attributes

HANDLE | m_handle

## Detailed Description

A stream file class.

Class to encapsulate a system dependent file in a system independent abstraction

## Constructor & Destructor Documentation

File | ( |  | ) |

Default constructor, creates a closed file

File | ( | HANDLE | handle | ) |

Constructor from an existing handle

Parameters:

  | handle | Operating system handle to an open file

virtual ~File | ( |  | ) | `[virtual]`

Destructor, closes the file

## Member Function Documentation

virtual bool openPath | ( | const char * | name,
|  | bool | canWrite = `false`,
|  | bool | canRead = `true`,
|  | bool | create = `false`,
|  | bool | append = `false`,
|  | bool | binary = `false` |
| ) |  |  | `[virtual]`

Opens a file from the filesystem pathname

Parameters:

  | name | Name of the file according to the operating system's conventions
  | canWrite | Open the file for writing
  | canRead | Open the file for reading
  | create | Create the file if it doesn't exist
  | append | Set the write pointer at the end of an existing file
  | binary | Open the file in binary mode if applicable

Returns:
  True if the file was successfully opened

virtual bool terminate | ( |  | ) | `[virtual]`

Closes the file handle

Returns:
  True if the file was (already) closed, false if an error occured

Implements Stream.

void attach | ( | HANDLE | handle | ) |

Attach an existing handle to the file, closes any existing first

Parameters:

  | handle | Operating system handle to an open file

HANDLE detach | ( |  | ) |

Detaches the object from the file handle

Returns:
  The handle previously owned by this object

HANDLE handle | ( |  | ) | const`[inline]`

Get the operating system handle to the file

Returns:
  File handle

virtual bool canRetry | ( |  | ) | const`[virtual]`

Check if the last error code indicates a retryable condition

Returns:
  True if error was temporary and operation should be retried

Reimplemented from Stream.

virtual bool valid | ( |  | ) | const`[virtual]`

Check if this file is valid

Returns:
  True if the file is valid, false if it's invalid or closed

Implements Stream.

static HANDLE invalidHandle | ( |  | ) | `[static]`

Get the operating system specific handle value for an invalid file

Returns:
  Handle value for an invalid file

virtual bool setBlocking | ( | bool | block = `true` | ) | `[virtual]`

Set the blocking or non-blocking operation mode of the file

Parameters:

  | block | True if I/O operations should block, false for non-blocking

Returns:
  True if operation was successfull, false if an error occured

Reimplemented from Stream.

virtual unsigned int length | ( |  | ) | `[virtual]`

Find the length of the file if it has one

Returns:
  Length of the file or zero if length is not defined

virtual int writeData | ( | const void * | buffer,
|  | int | length |
| ) |  |  | `[virtual]`

Write data to an open file

Parameters:

  | buffer | Buffer for data transfer
  | length | Length of the buffer

Returns:
  Number of bytes transferred, negative if an error occurred

Implements Stream.

virtual int readData | ( | void * | buffer,
|  | int | length |
| ) |  |  | `[virtual]`

Read data from an open file

Parameters:

  | buffer | Buffer for data transfer
  | length | Length of the buffer

Returns:
  Number of bytes transferred, negative if an error occurred

Implements Stream.

static bool remove | ( | const char * | name | ) | `[static]`

Deletes a file entry from the filesystem

Parameters:

  | name | Absolute path and name of the file to delete

Returns:
  True if the file was successfully deleted

static bool createPipe | ( | File & | reader,
|  | File & | writer |
| ) |  |  | `[static]`

Create a pair of unidirectionally pipe connected streams

Parameters:

  | reader | Reference to a File that becomes the reading side of the pipe
  | writer | Reference to a File that becomes the writing side of the pipe

Returns:
  True is the pipe was created successfully

void copyError | ( |  | ) | `[protected]`

Copy the last error code from the operating system

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

- yateclass.h