quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_system.a #include <File.h> File(STREAM stream = DEF_STREAM); boolean open(const SysString& filename, MODE mode = READ_ONLY); boolean put(const SysString& str); boolean close();
description:File out(File::ERROR); File foo_wo; SysString temp_file; Integral::makeTemp(temp_file); if (!foo_wo.open(temp_file, File::WRITE_ONLY)) { Console::put(L"Error in open"); } SysString str1(L"testing output\n"); out.put(str1); foo_wo.put(str1); foo_wo.close(); File::remove(temp_file);
static const SysString CLASS_NAME = L"File";
static const long MAX_FNAME_SIZE = PATH_MAX;
static const long BUF_SIZE = 8192;
static const long BAD_COUNT = -1;
enum STREAM { NO_STREAM = -1, OUT, IN, ERROR, DEF_STREAM = NO_STREAM };
enum SEEK {POS = SEEK_SET, POS_PLUS_CUR = SEEK_CUR, POS_PLUS_END = SEEK_END }
enum MODE { READ_ONLY = 0, READ_PLUS, WRITE_ONLY, WRITE_PLUS, APPEND_ONLY, APPEND_PLUS, DEF_MODE = READ_ONLY };
enum TYPE { TEXT = 0, BINARY, DEF_TYPE = TEXT };
enum BMODE {NATIVE = 0, SWAP, BIG_ENDIAN, LITTLE_ENDIAN, DEF_BMODE = NATIVE };
static const char SYS_TEXT_READ_ONLY[] = "r";
static const char SYS_TEXT_READ_PLUS[] = "r+";
static const char SYS_TEXT_WRITE_ONLY[] = "w";
static const char SYS_TEXT_WRITE_PLUS[] = "w+";
static const char SYS_TEXT_APPEND_ONLY[] = "a";
static const char SYS_TEXT_APPEND_PLUS[] = "a+";
static const char SYS_BINARY_READ_ONLY[] = "rb";
static const char SYS_BINARY_READ_PLUS[] = "rb+";
static const char SYS_BINARY_WRITE_ONLY[] = "wb";
static const char SYS_BINARY_WRITE_PLUS[] = "wb+";
static const char SYS_BINARY_APPEND_ONLY[] = "ab";
static const char SYS_BINARY_APPEND_PLUS[] = "ab+";
static const SysString TYPE_TEXT = L"text";
static const SysString TYPE_BINARY = L"binary";
static const SysString INDENT_STR = L" ";
static const SysString WRAP_TERM_STR = L"\n";
static const SysString WRAP_PRE_INDENT_STR = L"";
static const SysString WRAP_POST_INDENT_STR = L">";
static const long NO_WRAP = -1;
static const SysString STREAM_FILE = L"-";
static const long DEF_LOCK = false;
static const long DEF_INDENT = 0;
static const long DEF_LINE_WRAP = NO_WRAP;
static const long DEF_OPEN_RETRY = 5;
static const long DEF_OPEN_DELAY = 2;
static const long DEF_LOCK_RETRY = 5;
static const long DEF_LOCK_DELAY = 2;
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;
STREAM stream_d;
FILE* fp_d;
MODE mode_d;
TYPE type_d;
boolean lock_d;
BMODE byte_mode_d;
boolean byte_swap_d;
long indent_level_d;
long line_wrap_d;
long column_position_d;
long open_retry_d;
long open_delay_d;
static SysString** temp_files_d;
static long temp_size_d;
static long temp_num_d;
static Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static const SysString& name();
static boolean diagnose(Integral::DEBUG debug_level);
static boolean setDebug(Integral::DEBUG level);
boolean debug(const unichar* message) const;
~File();
File(STREAM stream = DEF_STREAM);
these methods are omitted because we do not ever want multiple file pointers on the same file
these methods are omitted because we do not ever want multiple file pointers on the same file
these methods are omitted because File can not write itself to an sof file
these methods are omitted because they are not useful for File objects
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
long memSize() const;
boolean swap(File& arg);
boolean setStreamType(STREAM arg);
boolean setFileMode(MODE arg);
SysString** getTempFilename();
long getNumTempFiles();
boolean open(const unichar* filename, MODE mode = DEF_MODE, TYPE type = DEF_TYPE);
boolean open(const SysString& filename, MODE mode = DEF_MODE, TYPE type = DEF_TYPE);
boolean close();
boolean flush();
boolean truncate(long size);
boolean setOpenRetry(long retry, long delay);
boolean lock(long retry = DEF_LOCK_RETRY, long DELAY = DEF_LOCK_DELAY);
boolean unlock();
boolean seek(long offset, SEEK mode);
long tell() const;
boolean eof() const;
boolean rewind();
boolean isOpen() const;
boolean isReadable() const;
boolean isWritable() const;
boolean isText() const;
boolean isBinary() const;
boolean isLocked() const;
long size(boolean keep_position = true) const;
static long size(const unichar* filename);
static long size(const SysString& filename);
boolean get(SysChar& chr);
boolean put(const SysChar chr);
boolean get(SysString& str, long len = BUF_SIZE);
boolean put(const SysString& str);
long read(void* ptr, long size, long num);
long write(const void* ptr, long size, long num);
boolean increaseIndention();
boolean decreaseIndention();
boolean setLineWrap(long ncols);
long getLineWrap() const;
long getLineLength() const;
static boolean registerTemp(SysString& name);
static boolean cleanTemps();
static boolean remove(const unichar* filename);
static boolean remove(const SysString& filename);
static boolean rename(const unichar* old_name, const unichar* new_name);
static boolean rename(const SysString& old_name, const SysString& new_name);
static boolean mkdir(const unichar* dir_name);
static boolean mkdir(const SysString& dir_name);
static boolean rmdir(const unichar* dir_name);
static boolean rmdir(const SysString& dir_name);
static boolean exists(const unichar* filename);
static boolean exists(const SysString& filename);
static boolean compare(const unichar* file1, const unichar* file2);
static boolean compare(const SysString& file2, const SysString& file2);
boolean setBMode(BMODE mode);
BMODE getBMode() const;
BMODE getMachineByteOrder() const;
int16 encode(int16 value) const;
int32 encode(int32 value) const;
int64 encode(int64 value) const;
int16 decode(int16 value) const;
int32 decode(int32 value) const;
int64 decode(int64 value) const;
boolean substr(SysString& str, long offset, long num_elements = Integral::NO_POS) const;
long firstStr(const unichar* str, long start = Integral::NO_POS) const;
long firstStr(const SysString& str, long start = Integral::NO_POS) const;
File(const File& arg);
boolean encode(void* buf, long size, long nitems) const;
boolean encode(void* obuf, const void* ibuf, long size, long nitems) const;
boolean decode(void* buf, long size, long nitems) const;
boolean decode(void* obuf, const void* ibuf, long size, long nitems) const;
// get a temporary file name // SysString temp_file; Integral::makeTemp(temp_file); // declare a file for writing // File write_file; // open the temporary file in write mode // if (!write_file.open(temp_file, File::WRITE_ONLY)) { Console::put(L"Error in open"); } // create a string to write and write it to the file // SysString str1(L"testing output\n"); write_file.put(str1); // close the file // write_file.close(); // create a file for reading // File read_file; // open the temporary file for reading // if (read_file.open(temp_file, File::READ_PLUS)) { // lock the file so no one can edit it while we read // read_file.lock(); // get the string out of the file // SysString str2; read_file.get(str2); // we should have read in the same file that we wrote // if (str2.ne(L"testing output")) { Console::put(L"Error in getString"); } // release the file lock and close the file // read_file.unlock(); read_file.close(); } else { Console::put(L"Error in open"); } // delete the temporary file // File::remove(temp_file);
// Create file objects. // File read_stdin; File write_stdout; // Initialize one string to "-" // and create a second to store output. // SysString str1(L"-"); SysString str2; // "-" is passed as the first argument to // the open method to set the object to access // stdin/stdout. The second argument determines // whether the File object will read from stdin, // or write to stdout. // // In this case the object will read from stdin. // if(read_stdin.open(str1, File::READ_ONLY)){ read_stdin.get(str2); } else { Console::put(L"Error Opening Stdin\n"); } // Destroy the object. // read_stdin.close(); // Again "-" is passed. This time the object // will write to stdout. // if(write_stdout.open(str1, File::WRITE_ONLY)){ write_stdout.put(str2); } else { Console::put(L"Error Opening Stdout"); } // Destroy the object. // write_stdout.close();