KwikPeg Manuals
Home
PegFile
Examples
Examples
Index
Index


Members
Styles
(none)
Signals
(none)
Overview 

The PegFile class provides an abstraction layer which gives KwikPeg access to your file system.

The KwikPeg GUI does not require a file system for normal use. However, the image conversion classes can provide runtime conversion of image files to KwikPeg bitmap format if a file system is available. KwikPeg provides its own Universal File System (UFS) interface to the file services provided by the file system operating on your target system.

The Universal File System interface can provide access to the following file systems:

AMX/FS File System used with KADAK's AMX RTOS
KwikNet UFS used with KADAK's KwikNet TCP/IP Stack
Standard C using the MS-DOS file system
Standard C using a UNIX-like file system
Custom user defined file system


To use the PegFile class, your KwikPeg configuration must have the following option enabled:
  File System: Attached file system: (select one)

The file system must be configured for use with KwikPeg as described in the KwikPeg GUI User's Guide which you can view in Acrobat PDF format.  User's Guide



** Note **

To use the PegFile class for file access, your application must include header file KP_FILES.H after the inclusion of either the PEG header file PEG.HPP or your KwikPeg Library Header File KP_LIB.H.



 See Also

PegImageConvert


Top of page


 Members

Constructors:

PegFile(void)
PegFile(const char *filename, const char *mode)
PegFile(KP_TFILE *fd)

The first constructor creates a PegFile object with no active file.

The second constructor creates a PegFile object and uses it to open the file referenced by filename in the file mode specified by parameter mode. The use of this constructor is equivalent to using the first constructor to create the PegFile object, followed immediately by a call to the object's Open() member function to open the file.

The third constructor creates a PegFile object and attaches to it the open file specified by fd. Parameter fd is a file descriptor, a handle to a file already opened by your application with a direct call to the underlying file system services. The use of this constructor is equivalent to using the first constructor to create the PegFile object, followed immediately by a call to the object's Attach() member function to attach the open file.

 

Public Functions:

int Attach(KP_TFILE *fd)

This function attaches the open file specified by fd to the PegFile object and returns the value 0. Parameter fd is the file descriptor of a file already opened by your application with a direct call to the underlying file system services. The function returns EOF if the PegFile object currently has a file open.

int Close(void)

This function closes the PegFile object's currently open file and returns the value 0. The function returns EOF if the file cannot be closed or if the PegFile object currently has no open file.

KP_TFILE *Detach(void)

This function detaches the currently open file from the PegFile object and returns the file descriptor (handle) to the caller. The file descriptor is the value used by the underlying file system to identify the file. The file remains open. The function returns NULL if the PegFile object currently has no open file.

int IsOpen(void)

This function returns a non-zero value if the PegFile object has a file open. Otherwise, the function returns the value 0.

int Open(const char *filename,
  const char *mode)

This function opens the file referenced by filename in the file mode specified by parameter mode. The allowable file name format and file access modes are those specified by standard C and supported by your file system. The opened file is attached to the PegFile object. The function returns 0 if the file is successfully opened. The function returns EOF if the file cannot be opened or if the PegFile object currently has a file open.

int OpenTemp(void)

This function creates and opens a temporary file. The file is opened for read and write binary access. The function returns 0 if the file is successfully created and opened. The function returns EOF if the file cannot be created or opened or if the PegFile object currently has a file open.

The temporary file will be automatically removed (deleted) when the file is closed by member function Close().

size_t Read(void *buf,
  size_t size, size_t cnt)

This function reads cnt elements of size bytes each from the file into the memory buffer referenced by pointer buf. The function returns n, the number of complete elements of the requested size successfully read. If n is less than cnt, the file may be at end of file or an error may have occurred, in which case the state of the file pointer is indeterminate. The function returns 0 if cnt or size is 0 or if no complete elements can be read.

static int Remove(const char *filename)

This function removes (deletes) the file referenced by filename. The allowable file name format is that supported by your file system. The function returns the value 0 if the file is successfully deleted. Otherwise, the function returns EOF.

int Seek(long offset, int origin)

This function sets the file pointer to the file location that is offset bytes from the specified origin. Set origin to SEEK_CUR to seek from the current file location, SEEK_END to seek from the end of the file or SEEK_SET to seek from the beginning of the file.

The function returns 0 if the file pointer is successfully moved. Otherwise a non-zero value is returned.

long Tell(void)

This function returns the current file pointer value measured as the number of bytes from the beginning of the file. The value -1 is returned if the file pointer location is indeterminate.

size_t Write(const void *buf,
  size_t size, size_t cnt)

This function writes cnt elements of size bytes each to the file from the memory buffer referenced by pointer buf. The function returns n, the number of complete elements of the requested size successfully written. Value n will be less than cnt if an error occurs. The function returns 0 if cnt or size is 0 or if no complete elements can be written.


Top of page


 Examples

The example provided with the PegQuant class creates a PegFile object which is used to read several graphic files to create an optimal palette for displaying the images from the files.




Top of page
KwikPeg Manuals
Home
Index
Index

 
Copyright © 2000-2003