![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2003 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: utils.h,v $ $Revision: 1.1 $ $State: Exp $ 00007 *******************************************************************************/ 00008 00009 #ifndef utils_H_ 00010 #define utils_H_ 00011 00012 #include "tdbutil/tdbUtilDefines.h" 00013 #include <stdio.h> 00014 00015 /* 00016 * Utility functions. 00017 */ 00018 DT_DLL_tdbutil void ps(int indent_level); 00019 00020 00021 /* 00022 * These callback function types are defined so this library 00023 * doesn't have to know about the GUI system but can still call 00024 * GUI functions which update a ProgressMeterDialogBoxClass 00025 */ 00026 typedef void MyProgressCallbackStartFunction(char *label, int range); 00027 typedef void MyProgressCallbackSetValueFunction(int value); 00028 typedef void MyProgressCallbackIncrementalProgressFunction(int increment); 00029 typedef void MyProgressCallbackEndFunction(void); 00030 00031 00032 /* 00033 * The calling GUI code does this: 00034 * 00035 * static ProgressMeterDialogBoxClass* p = 0; 00036 * static wxFrame* me = 0; 00037 * void prog_start_fcn(char *label, int range) { p = new ProgressMeterDialogBoxClass(me, "label", range); } 00038 * void prog_incremental_fcn(int increment) { p->DidSomeMore(increment); } 00039 * void prog_set_value_fcn(int value) { p->SetValue(value); } 00040 * void prog_end_fcn(void) { delete(p); } 00041 * 00042 * 00043 * The called, time-intensive prototdb functions call these like: 00044 * 00045 * void load_db(MyProgressCallbackStartFunction *prog_start_fcnp, 00046 * MyProgressCallbackSetValueFunction *prog_set_value_fcnp, 00047 * MyProgressCallbackIncrementalProgressFunction *prog_incremental_fcnp, 00048 * MyProgressCallbackEndFunction *prog_end_fcnp) 00049 * { 00050 * (*prog_start_fcnp)("Loading database", 10000); 00051 * 00052 * for (int i=0; i<10000; i++) 00053 * { 00054 * (*prog_set_value_fcnp)(i); // This, or... 00055 * (*prog_incremental_fcnp)(1); // this. 00056 * } 00057 * (*prog_end_fcnp)(); 00058 * } 00059 * 00060 * Or, if you can live with the restrictions, inherit CanPopUpProgressMeter class. 00061 */ 00062 00063 00064 00065 /**************************************************************** 00066 * File I/O 00067 ****************************************************************/ 00068 DT_DLL_tdbutil size_t DtFileLength(const char *pathname); 00069 00070 DT_DLL_tdbutil size_t DtFileLength(FILE *fp); 00071 00072 DT_DLL_tdbutil FILE* DtFileOpenForReading(const char *pathname); 00073 DT_DLL_tdbutil FILE* DtFileOpenForWriting(const char *pathname); 00074 00075 // Closes the specified file pointer, but unlike DtFileClose(), 00076 // this function will check that the file closed successfully, and 00077 // print out warnings otherwise. 00078 // @note This function will 00079 // @returns True if the file closed successfully, false otherwise. 00080 DT_DLL_tdbutil bool DtFileCloseVerbose(FILE *fp); 00081 00082 DT_DLL_tdbutil size_t DtReadBytes(void *where, size_t size, FILE *fp); 00083 00084 DT_DLL_tdbutil size_t DtReadMod4Bytes(void *where, size_t size, FILE *fp); 00085 00086 // fgets with the newline (if any) stripped from the result 00087 DT_DLL_tdbutil char* DtReadLine(char *buf, int bufSize, FILE *fp ); 00088 00089 //void DtSkipBytes(FILE *fp, size_t amount_to_skip); 00090 00091 #endif