quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_io.a #include <Sof.h> Sof(); boolean open(const SysString& filename, File::MODE mode = File::READ_ONLY, File::TYPE type = File::DEF_TYPE); boolean put(const SysString& name, long size); long write(const void* ptr, long size, long nitems);
description:long j = 27; Sof sof1; SysString file1(L"temp.out"); if (sof1.open(file1, File::WRITE_ONLY, File::BINARY) != true) { return Error::handle(file1, L"open", Error::TEST, __FILE__, __LINE__); } SysString cname(L"MyLong"); sof1.put(cname, 0, sizeof(long)); sof1.write(&j, sizeof(j), 1); sof1.close();
static const SysString CLASS_NAME = L"Sof";
static const long MAX_MAGIC_LENGTH = 22;
static const SysString VERSION = L"v1.0";
static const long MESSAGE_SIZE = 1024;
static const long CLASS_NAME_SIZE = 256;
static const char DELETE_CHAR_TEXT = ' ';
static const char DELETE_CHAR_BINARY = '\0';
static const char NEWLINE_BUFFER[] = '\n';
static const long NEWLINE_LENGTH = strlen(NEWLINE_BUFFER);
static const SysString BSTR_NATIVE = L"abcd";
static const SysString BSTR_SWAP = L"dcba";
static const long BCODE_NATIVE = 1633837924;
static const long BCODE_SWAP = 1684234849;
static const long BSTR_LEN = 4;
static const float IEEE_FLOAT_NATIVE = 16777999408082104352768.000000;
static const float IEEE_FLOAT_SWAP = 261007875622861537280.000000;
static const long NO_TAG = SofList::NO_TAG;
static const long ALL_TAGS = NO_TAG + 1;
static const long FREE_TAG = NO_TAG + 2;
static const long IMPLICIT_END = -1073741824;
static const long IMPLICIT_START = (NO_TAG + 3);
static const long BUFFER_SIZE = FILE::BUF_SIZE;
static const long SYMBOL_BASE = (2 * sizeof(uint32) + sizeof(uint16) + sizeof(ubyte));
static const long SYMBOL_OFFSET_NEXT = 0;
static const long SYMBOL_OFFSET_CKSM = SYMBOL_OFFSET_NEXT + sizeof(byte);
static const long SYMBOL_OFFSET_IND = SYMBOL_OFFSET_CKSM + sizeof(uint16);
static const long SYMBOL_OFFSET_REFS = SYMBOL_OFFSET_IND + sizeof(int32);
static const long SYMBOL_OFFSET_NAME = SYMBOL_OFFSET_REFS + sizeof(int32);
static const long INDEX_SIZE = (4 * sizeof(long) + sizeof(uint16) + sizeof(byte));
static const long INDEX_OFFSET_NEXT = 0;
static const long INDEX_OFFSET_CKSM = INDEX_OFFSET_NEXT + sizeof(byte);
static const long INDEX_OFFSET_POS = INDEX_OFFSET_CKSM + sizeof(uint16);
static const long INDEX_OFFSET_TAG = INDEX_OFFSET_POS + sizeof(int32);
static const long INDEX_OFFSET_SIZE = INDEX_OFFSET_TAG + sizeof(int32);
static const long INDEX_OFFSET_NAME = INDEX_OFFSET_SIZE + sizeof(int32);
static const long SKIP_TABLE_GROUP = 10;
static const unichar DEF_DELIMITER = L'#';
static const long DEF_POS = -1;
static const long DEF_IMPLICIT = IMPLICIT_START;
static const boolean DEF_DISABLE_LOCK = true;
static const long ANY_SIZE = -1;
static const long ERR = 10000;
static const long ERR_NOTSOF = 10001;
static const long ERR_NOOBJ = 10002;
static const long ERR_NOTAG = 10003;
static const long ERR_UPDATEH = 10011;
static const long ERR_UPDATE = 10012;
static const long ERR_CLOSE = 10015;
static const long ERR_RANGE = 10020;
static const long ERR_CURPOS = 10021;
static const long ERR_FLOAT = 10042;
static const long ERR_READHD = 10043;
static const long ERR_TYPE = 10044;
static const long ERR_STRUCT = 10045;
static const long ERR_LABEL = 10051;
static const long ERR_IMPLIC = 10061;
static const long ERR_TAG = 10062;
static const long ERR_BINARY = 10063;
static const long ERR_PARTIAL = 10070;
static const long ERR_RESIZE = 10071;
SysString name_d;
SysString expanded_name_d;
File::TYPE file_type_d;
File fp_d;
unichar delimiter_d;
long end_of_header_d;
long end_of_data_d;
long cur_data_d;
long cur_pos_d;
long implicit_count_d;
boolean disable_lock_d;
long lock_retry_d;
long lock_delay_d;
SofSymbolTable table_d;
SofList index_d;
SysString cname_d;
SysString version_d;
SysString magic_d;
ushort file_checksum_d;
boolen partial_write_d;
boolen partial_read_d;
SofParser* vec_parser_d;
int32* skip_table_d
long skip_table_incr_d;
long last_skip_table_pos_d;
long vec_start_pos_d;
long vec_size_d;
long vec_curr_elem_d;
Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static Checksum cksm_d;
static const SysString& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean setDebug(Integral::DEBUG debug_level);
boolean debug(const unichar* msg) const;
~Sof();
Sof();
boolean assign(const Sof& arg);
Sof& operator=(const Sof& arg);
these methods are omitted because Sof object cannot write itself to an Sof file
these methods are omitted because they are not useful for Sof 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);
boolean clear(Integral::CMODE ctype_a = Integral::DEF_CMODE);
long memSize();
boolean open(const unichar* filename, File::MODE mode = File::READ_ONLY, File::TYPE type = File::DEF_TYPE);
boolean open(const SysString& filename, File::MODE mode = File::READ_ONLY, File::TYPE type = File::DEF_TYPE);
boolean close();
static boolean closeAll();
boolean setLockDisable(boolean disable);
boolean setLockRetry(long retry, long delay = File::DEF_LOCK_DELAY);
boolean setDelimiter(unichar chr);
unichar getDelimiter() const;
const SysString& getName() const;
const SysString& getExpandedName() const;
boolean isSof();
static boolean isSof(const SysString& filename);
boolean isText() const;
boolean isBinary() const;
boolean isOpen() const;
boolean isSameFile(Sof& sof_object);
boolean find(const SysString& name, long tag);
long first(const SysString& name);
long last(const SysString& name);
long next(const SysString& name, long cur_tag);
long prev(const SysString& name, long cur_tag);
boolean put(const SysString& name, long size);
boolean put(const SysString& name, long tag, long size);
boolean remove(const SysString& name, long object_tag);
boolean remove(long name, long object_tag);
boolean remove(const SysString& name);
boolean remove(long name);
boolean copy(long o_tag, Sof& i_sof, const SysString& i_cname, long i_tag);
boolean copy(long o_tag, Sof& i_sof, long i_cname, long i_tag);
boolean copy(Sof& i_sof, const SysString& i_cname);
boolean copy(Sof& i_sof, long i_cname);
long getObjectSize(const SysString& name, long tag);
long getObjectSize();
long getCount(const SysString& name);
long getCount();
long getNameCount();
boolean enumerate(SofList& index, SofSymbolTable& table) const;
boolean seek(long offset, File::SEEK whence);
long tell() const;
boolean rewind();
long read(void* ptr, long size, long nitems);
long write(const void* ptr, long size, long nitems);
boolean gets(SysString& ptr, long size = BUFFER_SIZE);
boolean puts(const SysString& ptr);
boolean writeLabelPrefix(const SysString& param_name);
boolean writeLabelSuffix(const SysString& param_name);
boolean increaseIndention();
boolean decreaseIndention();
boolean setLineWrap(long ncols);
long getLineLength() const;
long getLineWrap() const;
boolean startPartialWrite();
boolean stopPartialWrite();
boolean startPartialRead();
boolean stopPartialRead();
boolean getPartialWrite() const;
boolean getPartialRead() const;
int32* getSkipTable();
const int32* getSkipTable() const;
long getSkipTableIncr() const;
long getSkipTablePos() const;
long getStartPos() const;
long getVecSize() const;
long getVecCurrentElement() const;
const SofParser& getVecParser() const;
SofParser& getVecParser();
boolean setSkipTableIncr(long pos);
boolean setSkipTablePos(long pos);
boolean setStartPos(long pos);
boolean setVecSize(long size);
boolean setVecCurrentElement(long elem);
boolean clearSkipTable();
boolean writeSkipTable();
boolean readSkipTable();
boolean resize(long size);
Sof(const Sof& arg);
boolean cleanUp();
boolean freeIndex();
boolean update();
boolean readIndex();
boolean writeIndex();
boolean readTable()
boolean writeTable();
boolean openRead();
boolean openReadText();
boolean openReadBinary();
boolean openReadIndexText();
boolean openReadIndexBinary();
boolean openWrite(File::MODE access_mode);
boolean writeLabel(long name, long tag);
boolean writeLabel(const SysString& name, long tag);
boolean parseLabel(SysString& name, long& tag, const SysString& buf);
boolean skipLabel();
boolean seekData();
boolean seekDataText();
boolean seekDataBinary();
boolean find(long name, long tag);
boolean add(const SysString& name, long size, long tag = FREE_TAG);
boolean add(long name, long size, long tag = FREE_TAG);
boolean resize(const SysString& name, long tag, long size);
long fwrite(const void* ptr, long size, long nitems);
long fread(void* ptr, long size, long nitems);
boolean fseek(long offset, File::SEEK whence);
long ftell();
boolean clearSpace(long nbytes);
boolean copySegment(long src_pos, long size);
boolean copySegment(long src_pos, long dest_pos, long size);
boolean setErrorPointer();
boolean registerPtr();
boolean unRegisterPtr();
friend class AudioFile;examples:
Sof sof0; Sof sof1; SysString file1; SysString file2; SysString long_cname(L"Long"); file1.assign(L"/tmp/foo_bin.sof"); file2.assign(L"/tmp/foo_asc.sof"); // open files for write (text & binary) // if (!sof0.open(file1, File::WRITE_ONLY)) { return Error::handle(long_cname, L"open", Error::TEST, __FILE__, __LINE__); } if (!sof1.open(file2, File::WRITE_ONLY, File::BINARY)) { return Error::handle(long_cname, L"open", Error::TEST, __FILE__, __LINE__); } // add a long entry to the files // long j = 27; sof0.put(long_cname, Sof::ANY_SIZE); sof1.put(long_cname, 0, sizeof(long)); // write the text value // SysString output; output.assign((long)j, (unichar*)("value = %ld\n")); sof0.puts(output); // write the binary value // sof1.write(&j, sizeof(j), 1); // add another long entry to the files // j = 277; sof0.put(long_cname, Sof::ANY_SIZE); sof1.put(long_cname, 1, sizeof(long)); // close the files // sof0.close(); sof1.close(); // open files again in read plus // sof0.open(file1, File::READ_PLUS); // read all the text values // long tag; for (tag = sof0.first(long_cname); tag != Sof::NO_TAG; tag = sof0.next(long_cname, tag)) { // find the node // sof0.find(long_cname, tag); } sof0.close();