Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

ORESDB.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ORESDB.CPP

Go to the documentation of this file.
00001 //Filename    : ORESDB.CPP
00002 //Description : Resource library with database index reading object
00003 
00004 #include <string.h>
00005 #include <OSYS.H>
00006 #include <ODB.H>
00007 #include <ORESDB.H>
00008 
00009 //-------------------------------------------------------//
00010 //
00011 // Resource library reading object
00012 //
00013 // Files required :
00014 //
00015 // - A resource file build by LIBDB.EXE, it is always in .RES extension
00016 // - A database file with Index Pointer field, the values of the field
00017 //   are automatically calculated by LIBDB.EXE
00018 //
00019 //-------------------------------------------------------//
00020 
00021 //---------- Begin of function ResourceDb::init ---------//
00029 void ResourceDb::init(char* resName, Database* dbObj, int indexOffset, int useCommonBuf) {
00030     deinit();
00031 
00032     file_open( resName );
00033 
00034     db_obj             = dbObj;
00035     index_field_offset = indexOffset;
00036     use_common_buf     = useCommonBuf;
00037 
00038     if( use_common_buf )
00039         data_buf = sys.common_data_buf;
00040     else
00041         data_buf = NULL;
00042 
00043     err_if( db_obj == NULL )
00044         err_now("db_obj is NULL");
00045 
00046     init_flag = 1;
00047 }
00048 
00049 //----------- End of function ResourceDb::init ------------//
00050 
00051 //---------- Begin of function ResourceDb::deinit ---------//
00053 void ResourceDb::deinit() {
00054     if( init_flag ) {
00055         if( !use_common_buf && data_buf ) {
00056             mem_del(data_buf);
00057             data_buf = NULL;
00058         }
00059 
00060         if( !read_all )
00061             file_close();
00062 
00063         init_flag=0;
00064     }
00065 }
00066 
00067 //----------- End of function ResourceDb::deinit ----------//
00068 
00069 //---------- Begin of function ResourceDb::read ----------//
00084 char* ResourceDb::read(int recNo) {
00085     err_when( !init_flag || !db_obj );
00086 
00087     long* indexFieldPtr;
00088     char* recPtr;
00089 
00090     if( (recPtr = db_obj->read(recNo)) == NULL )
00091         return NULL;
00092 
00093     indexFieldPtr = (long*) (recPtr+index_field_offset);
00094 
00095     if( memcmp( indexFieldPtr, "    ", 4 ) == 0 )
00096         return NULL;                                  // no sample screen for this file
00097 
00098     file_seek( *indexFieldPtr );
00099     data_buf_size = file_get_long();
00100 
00101     err_when( use_common_buf && data_buf_size > COMMON_DATA_BUF_SIZE );
00102 
00103     if( !use_common_buf )
00104         data_buf = mem_resize( data_buf, data_buf_size );
00105 
00106     file_read( data_buf, data_buf_size );
00107 
00108     return data_buf;
00109 }
00110 
00111 //----------- End of function ResourceDb::read -------------//
00112 
00113 //---------- Begin of function ResourceDb::get_file ----------//
00123 File* ResourceDb::get_file() {
00124     err_when( !init_flag || !db_obj );
00125 
00126     long* indexFieldPtr;
00127     char  emptyField[] = "        ";
00128     char* recPtr;
00129 
00130     if( (recPtr = db_obj->read()) == NULL )
00131         return NULL;
00132 
00133     indexFieldPtr = (long*) (recPtr+index_field_offset);
00134 
00135     if( memcmp( indexFieldPtr, emptyField, 8 ) == 0 )
00136         return NULL;                                  // no sample screen for this file
00137 
00138     file_seek( *indexFieldPtr + sizeof(long) );
00139 
00140     return this;
00141 }
00142 
00143 //----------- End of function ResourceDb::get_file -------------//
00144 
00145 //---------- Begin of function ResourceDb::init_imported ----------//
00155 void ResourceDb::init_imported(char* resName, int readAll, int useCommonBuf) {
00156     deinit();
00157 
00158     db_obj             = NULL;
00159     index_field_offset = NULL;
00160 
00161     read_all = readAll;
00162 
00163     file_open( resName );
00164 
00165     if( read_all ) {
00166         data_buf_size = file_size();
00167 
00168         data_buf = mem_add( data_buf_size );
00169         file_read( data_buf, data_buf_size );
00170         file_close();
00171 
00172         use_common_buf = 0;                           // don't use vga buffer if read all
00173     }
00174     else {
00175         use_common_buf = useCommonBuf;
00176 
00177         if( use_common_buf )
00178             data_buf = sys.common_data_buf;
00179         else
00180             data_buf = NULL;
00181     }
00182 
00183     init_flag = 1;
00184 }
00185 
00186 //----------- End of function ResourceDb::init_imported -------------//
00187 
00188 //---------- Begin of function ResourceDb::read_imported ----------//
00198 char* ResourceDb::read_imported(long offset) {
00199     err_when( !init_flag );
00200 
00201     // #### begin Gilbert 4/10 ######//
00202     //  err_if( offset<0 || offset>=data_buf_size )
00203     //          err_here();
00204     // #### end Gilbert 4/10 ######//
00205 
00206     //-------- read from buffer ---------//
00207 
00208     // ##### begin Gilbert 4/10 #######//
00209     if( read_all ) {
00210         err_when( offset<0 || offset>=data_buf_size );
00211         return data_buf + offset + sizeof(long);      // by pass the long parameters which is the size of the data
00212     }
00213     // ##### end Gilbert 4/10 #######//
00214 
00215     //---------- read from file ---------//
00216 
00217     // ##### begin Gilbert 2/10 ######//
00218     err_when( offset >= file_size() );
00219     // ##### end Gilbert 2/10 ######//
00220     file_seek( offset );
00221 
00222     data_buf_size = file_get_long();
00223 
00224     err_when( use_common_buf && data_buf_size > COMMON_DATA_BUF_SIZE);
00225 
00226     if( !use_common_buf )
00227         data_buf = mem_resize( data_buf, data_buf_size );
00228 
00229     file_read( data_buf, data_buf_size );
00230 
00231     return data_buf;
00232 }
00233 
00234 //----------- End of function ResourceDb::read_imported -------------//

Generated on Fri Aug 23 01:38:17 2002 for VirtualU by doxygen1.2.17