Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Datafile Class Reference

#include <CGBuffer.h>

Collaboration diagram for Datafile:

Collaboration graph
List of all members.

Public Member Functions

void Close ()
 Datafile ()
int Open (const char *path)
int Read ()
void Release ()
void Reset ()
DatafileRetain ()
 ~Datafile ()

Public Attributes

MemoryBufferdata_buffer
unsigned long data_size

Private Attributes

FILE * file
int ref_count

Constructor & Destructor Documentation

Datafile::Datafile  )  [inline]
 

Definition at line 154 of file CGBuffer.h.

References data_buffer, data_size, file, and ref_count.

00154                : ref_count(1), file(NULL), data_buffer(NULL), data_size(0)
00155     {
00156     }

Datafile::~Datafile  )  [inline]
 

Definition at line 158 of file CGBuffer.h.

References Reset().

00159     {
00160         Reset();
00161     }


Member Function Documentation

void Datafile::Close  )  [inline]
 

Definition at line 214 of file CGBuffer.h.

References file.

Referenced by CGBuffer::LoadJPEG(), and Reset().

00215     {
00216         if (file) {
00217             fclose(file);
00218             file = NULL;
00219         }
00220     }

int Datafile::Open const char *  path  )  [inline]
 

Definition at line 175 of file CGBuffer.h.

References MemoryBuffer::Create(), data_buffer, data_size, DPRINTF, file, and Reset().

Referenced by CGBuffer::Open().

00176     {
00177         file = fopen(path,"r");
00178         if (!file) {
00179             DPRINTF(0,"Datafile::Open() - Couldn't open %s\n", path);
00180             Reset();
00181             return 0;
00182         }
00183         fseek(file, 0, SEEK_END);
00184         data_size = ftell(file);
00185         data_buffer = MemoryBuffer::Create(data_size);
00186         if (!data_buffer) {
00187             DPRINTF(0,"Datafile::Open() - Couldn't allocate MemoryBuffer of size %d\n", data_size);
00188             Reset();
00189             return 0;
00190         }
00191         //DPRINTF(0,"Datafile::Open() - Successfully opened '%s' %d bytes\n", path, data_size);
00192         return 1;
00193     }

int Datafile::Read  )  [inline]
 

Definition at line 195 of file CGBuffer.h.

References MemoryBuffer::data, data_buffer, data_size, DPRINTF, file, and Reset().

Referenced by CGBuffer::LoadJPEG().

00196     {
00197         if ((file == NULL) || (data_buffer == NULL) || (data_size == 0)) {
00198             DPRINTF(0,"Datafile::Read() - No file open, file of zero size, or no valid MemoryBuffer\n");
00199             Reset();
00200             return 0;
00201         }
00202         
00203         fseek(file, 0, SEEK_SET);        
00204         if (fread((void*)data_buffer->data, 1, data_size, file) != data_size) {
00205             DPRINTF(0,"Datafile::Read() - Didn't read to finish?");
00206             Reset();
00207             return 0;
00208         }
00209         
00210         //DPRINTF(0,"Datafile::Read() - Successfully read all %d bytes into buffer\n",data_size);
00211         return 1;
00212     }

void Datafile::Release  )  [inline]
 

Definition at line 169 of file CGBuffer.h.

References ref_count.

00170     {
00171         if (--ref_count==0) 
00172             delete this;
00173     }

void Datafile::Reset  )  [inline]
 

Definition at line 222 of file CGBuffer.h.

References Close(), data_buffer, and MemoryBuffer::Release().

Referenced by CGBuffer::Open(), Open(), Read(), CGBuffer::Render(), and ~Datafile().

00223     {
00224         Close();
00225         if (data_buffer) {
00226             data_buffer->Release();
00227             data_buffer = NULL;
00228         }
00229     }

Datafile* Datafile::Retain  )  [inline]
 

Definition at line 163 of file CGBuffer.h.

References ref_count.

00164     {
00165         ++ref_count;
00166         return this;
00167     }


Member Data Documentation

MemoryBuffer* Datafile::data_buffer
 

Definition at line 151 of file CGBuffer.h.

Referenced by Datafile(), CGBuffer::LoadJPEG(), Open(), Read(), and Reset().

unsigned long Datafile::data_size
 

Definition at line 152 of file CGBuffer.h.

Referenced by Datafile(), CGBuffer::LoadJPEG(), Open(), and Read().

FILE* Datafile::file [private]
 

Definition at line 148 of file CGBuffer.h.

Referenced by Close(), Datafile(), Open(), and Read().

int Datafile::ref_count [private]
 

Definition at line 147 of file CGBuffer.h.

Referenced by Datafile(), Release(), and Retain().


The documentation for this class was generated from the following file:
Generated on Sat Jan 14 22:33:16 2006 for Celestia by  doxygen 1.4.1