?? file.h
字號:
// file: $isip/class/system/File/File.h// version: $Id: File.h,v 1.54 2003/04/09 19:46:31 duncan Exp $//// make sure definitions are only made once//#ifndef ISIP_FILE#define ISIP_FILE// isip include files//#ifndef ISIP_INTEGRAL#include <Integral.h>#endif#ifndef ISIP_ERROR#include <Error.h>#endif#ifndef ISIP_MEMORY_MANAGER#include <MemoryManager.h>#endif// forward class definitions//class SysChar;class SysString;// File: a general purpose file pointer. this class abstracts file// manipulations, which are operating system specific, and provides// a general interface that all classes should use to access files.//// an important feature of this class is that a polling strategy for// opening files is built into the class. when a file open fails, it is// possible that the file exists, but the network file system for the// computer is in error. this happens often in unix when dealing with// files using the network file system. an effective solution is simply// to wait a specified time, and try again. more often than not,// the next open will succeed. since all file I/O is centralized through// this class, this feature is automatically available to all isip classes.//class File { //--------------------------------------------------------------------------- // // public constants // //---------------------------------------------------------------------------public: // define the class name // static const SysString CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define some maximum sizes // static const long MAX_FNAME_SIZE = PATH_MAX; static const long BUF_SIZE = 8192; static const long BAD_COUNT = -1; // standard file streams // enum STREAM { NO_STREAM = -1, OUT, IN, ERROR, DEF_STREAM = NO_STREAM }; // seek positions // enum SEEK { POS = SEEK_SET, POS_PLUS_CUR = SEEK_CUR, POS_PLUS_END = SEEK_END }; // i/o modes // enum MODE { READ_ONLY = 0, READ_PLUS, WRITE_ONLY, WRITE_PLUS, APPEND_ONLY, APPEND_PLUS, DEF_MODE = READ_ONLY }; // i/o types // enum TYPE { TEXT = 0, BINARY, DEF_TYPE = TEXT }; // byte-order modes // enum BMODE { NATIVE = 0, SWAP, BIG_ENDIAN, LITTLE_ENDIAN, DEF_BMODE = NATIVE }; // names for each of the enumerated file modes // static const char SYS_TEXT_READ_ONLY[]; static const char SYS_TEXT_READ_PLUS[]; static const char SYS_TEXT_WRITE_ONLY[]; static const char SYS_TEXT_WRITE_PLUS[]; static const char SYS_TEXT_APPEND_ONLY[]; static const char SYS_TEXT_APPEND_PLUS[]; static const char SYS_BINARY_READ_ONLY[]; static const char SYS_BINARY_READ_PLUS[]; static const char SYS_BINARY_WRITE_ONLY[]; static const char SYS_BINARY_WRITE_PLUS[]; static const char SYS_BINARY_APPEND_ONLY[]; static const char SYS_BINARY_APPEND_PLUS[]; // names for each of the enumerated file type // static const SysString TYPE_TEXT; static const SysString TYPE_BINARY; // indention and line wrapping // static const SysString INDENT_STR; static const SysString WRAP_TERM_STR; static const SysString WRAP_PRE_INDENT_STR; static const SysString WRAP_POST_INDENT_STR; // a string denoting a piped input/output // static const SysString STREAM_FILE; //---------------------------------------- // // default values and arguments // //---------------------------------------- // lock constants: // def_lock_retry is the default number of times we try to lock a file // before reporting fails, the def_lock_delay is the time in seconds before // each retry // static const long DEF_LOCK = false; static const long DEF_LOCK_RETRY = 5; static const long DEF_LOCK_DELAY = 2; // formatting constants // static const long DEF_INDENT = 0; static const long NO_WRAP = -1; static const long DEF_LINE_WRAP = NO_WRAP; // open related constants: // def_open_retry is the default number of times we try to open a file // before reporting fails, the def_open_delay is the time in seconds before // each retry // static const long DEF_OPEN_RETRY = 5; static const long DEF_OPEN_DELAY = 2; //---------------------------------------- // // error codes // //---------------------------------------- static const long ERR = 1000; static const long ERR_NOTCLS = 1001; static const long ERR_NOTOPN = 1002; static const long ERR_REOPEN = 1003; static const long ERR_CLOSE = 1004; static const long ERR_FLUSH = 1005; static const long ERR_TRUNCT = 1006; static const long ERR_WRAP = 1007; static const long ERR_DECODE = 1008; //--------------------------------------------------------------------------- // // protected data // //---------------------------------------------------------------------------protected: // the stream type // STREAM stream_d; // the file pointer // FILE* fp_d; // open mode and type // MODE mode_d; TYPE type_d; // lock flag // boolean lock_d; // byte-order modes: // it can be an absolute byte-order (LITTLE_ENDIAN or BIG_ENDIAN) or // a relative order to the machine (NATIVE or SWAP) // BMODE byte_mode_d; // byte-swap flag: // this is relative to the machine's byte-order // boolean byte_swap_d; // indention level // long indent_level_d; // line wrapping limit // long line_wrap_d; // current column position // long column_position_d; // file polling: // open_retry_d is the number of times that the file will be polled for // opening before an error is returned. open_delay_d is the delay in // seconds between attempts to open the file. // long open_retry_d; long open_delay_d; // declare an array of SysString objects to keep track of temporary filenames // static SysString** temp_files_d; static long temp_size_d; static long temp_num_d; // declare a static debug level for all class instantiations // static Integral::DEBUG debug_level_d; // static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //---------------------------------------------------------------------------public: // method: name // static const SysString& name() { return CLASS_NAME; } // other static methods // static boolean diagnose(Integral::DEBUG debug_level); // method: setDebug // static boolean setDebug(Integral::DEBUG level) { debug_level_d = level; return true; } // other debug methods // boolean debug(const unichar* message) const; // destructor/constructor(s): // the copy constructor is private // ~File(); File(STREAM stream = DEF_STREAM); // assign methods: // these methods are omitted because we do not ever want multiple file // pointers on the same file. see the File::swap method // // operator= methods: // these methods are omitted because we do not ever want multiple file // pointers on the same file. // // i/o methods: // these methods are omitted because File can not write itself // to an sof file // // equality methods: // these methods are omitted because they are not useful for File objects // // memory management methods: // the clear method is omitted so the user is forced to open and close // files in a disciplined manner // // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -