Download Shareware and Freeware Software for Windows, Linux, Macintosh, PDA

line Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

Serving Software Downloads in 976 Categories, Downloaded 32.291.839 Times

IFF Format Library 0.1

  Date Added: February 16, 2010  |  Visits: 801

IFF Format Library

Report Broken Link
Printer Friendly Version

Product Homepage
Download (80 downloads)

IFF Format Library provides header structures and utility functions for reading and writing data files in the Interchange Files. The Interchange File Format is a simple structured binary file format consisting of sized and typed chunks of data, selectively readable without having to know the format of each chunk. This functionality is similar to what XML provides for text documents, and the IFF format can indeed be viewed as a sort of a binary XML. IFFs extensibility is an excellent way of not breaking old applications when the file format changes, making it an excellent choice for your next applications data files. The IFF is also the simplest and the smallest such data format, ensuring that your files consist of real data rather than overhead and that your code spends more time on real work than on parsing the data file. This library defines the IFF header structures and provides simple algorithms for directly writing many of your objects as chunks and containers. Installation: This library can be downloaded from SourceForge, as can its sole prerequisite: libiff - The library source package. uSTL - An STL implementation, required. First, unpack and install uSTL, as described in its documentation. Unpack libiff and run ./configure; make install, which will install the library to /usr/local/lib and headers to /usr/local/include. ./configure --help lists available configuration options, in the usual autoconf fashion. The one thing to be aware of is that by default the library will not be completely conforming to EA85 specification. Why that is so, and why you should take the default options anyway, is discussed in detail in the next section. If you really want to use the original EA85 format, you can to pass --with-bigendian --with-2grain to configure. Usage: If you are using C++, chances are you already have an object-oriented design of some kind. You have a collection of objects, related to each other in some way, and you want to write them all to a file in some way. It is, of course, possible to just write them all to the file, one after the other, but that approach makes things difficult if you ever decide to change the structure of those objects, write more or fewer of them, or explain to other people how to read your format. Hence, it is desirable to create some kind of structure in the file, to be able to determine where each objects begins and ends, and what kind of object is where. When using an IFF format, youll make simple objects into chunks, and objects containing other objects into FORMs, LISTs, or CATs. The first task is to make each of your objects readable and writable through uSTL streams. To do that youll need to define three methods, read, write, and stream_size, and create flow operator overrides with a STD_STREAMABLE macro. Here is a typical example: #include < iff.h > // iff header includes ustl.h, but doesnt use the namespace. using namespace ustl; // it is recommended to leave iff:: namespace on. /// Stores players vital statistics. class CPlayerStats { public: void read (istream& is); void write (ostream& os) const; size_t stream_size (void) const; private: uint16_t m_HP; uint16_t m_MaxHP; uint16_t m_Mana; uint16_t m_MaxMana; }; // Since the object is simple, and contains no other objects, // well make it a simple chunk. enum { // Define a chunk format for writing this object. fmt_PlayerStats = IFF_FMT(S,T,A,T) }; // In a hex editor youll see STAT at the beginning of the object // making it easy to find when you want to hack something in it. /// Reads the object from stream p is void CPlayerStats::read (istream& is) { is >> m_HP >> m_MaxHP >> m_Mana >> m_MaxMana; } /// Writes the object to stream p os. void CPlayerStats::write (ostream& os) const { os << m_HP << m_MaxHP << m_Mana << m_MaxMana; } /// Returns the size of the written object inline size_t CPlayerStats::stream_size (void) const { return (stream_size_of (m_HP) + // This evaluates at compile time to 8, stream_size_of (m_MaxHP) + // so making this function inline is stream_size_of (m_Mana) + // usually a good idea. stream_size_of (m_MaxMana)); } STD_STREAMABLE(CPlayerStats) This needs to happen in all your objects. Make them streamable and define a format id. Then, to save everything, use iff::Read/Write functions from iff/utils.h (no, you dont need to include it separately), like this: void SomeDocumentObject::SavePlayer (const string& filename) const { // uSTL streams work on memory blocks, not on files directly, // so the needed buffer has to be preallocated. // memblock buf (iff::form_size_of (m_Player)); // // Well need a stream to write the player object to. // ostream os (buf); // // This writes it as a FORM, which just happens to be one of the three // allowable top-level chunk types. When a file starts with FORM, LIST, // or CAT, programs know it is an IFF file. The top level chunk should // contain the entire file, and nothing should follow it. // iff::WriteFORM (os, m_Player, fmt_MyGamePlayer); buf.write_file ("player.sav"); } // The following will be in the player class /// Reads the player object from stream p is size_t CPlayer::stream_size (istream& is) { // Player is a compound object, a FORM, so it can only contain other // chunks and FORMs, not simple values. return (iff::chunk_size_of (m_Name) + // m_Name is a string iff::chunk_size_of (m_Stats) + // CPlayerStats object iff::vector_size_of (m_Inventory) + // a vector, chunk saved // Quests is a special manager object that writes each quest // as a chunk or a form with some common settings. iff::list_size_of (m_Quests)); } /// Reads the player object from stream p is void CPlayer::write (ostream& os) const { iff::WriteChunk (os, m_Name, fmt_PlayerName); iff::WriteChunk (os, m_Stats, fmt_PlayerStats); iff::WriteVector (os, m_Inventory, fmt_Inventory); iff::WriteLIST (os, m_Quests, fmt_Quests); } /// Reads the player object from stream p is void CPlayer::read (istream& is) { iff::ReadChunk (is, m_Name, fmt_PlayerName); iff::ReadChunk (is, m_Stats, fmt_PlayerStats); iff::ReadVector (is, m_Inventory, fmt_Inventory); iff::ReadLIST (is, m_Quests, fmt_Quests); } The above is enough to get you a structured file with format checking on read. If you try reading something that is not a player savegame file or if the file is somehow corrupted, youll get an informative exception. The read method above is the simplest implementation, to be used if you really do not expect things to change at this level. A player will always have a name, some stats, and stuff in his pockets. But what if you decided to add, say, a known spell list? The read function will then break. Sure you can hack up some conversion routine for yourself, but what about your users who already have an old version of your game? Are you going to tell them that those fifty four hours of gameplay they saved will have to be replayed just because you added one lousy feature? Well, some companies are like that. But with IFF, you have the formats and sizes in each header, so you can make a more resilient read that will support new and old formats alike: /// Reads the player object from stream p is void CPlayer::read (istream& is) { while (is.remaining()) { // // The Peek function will get the format without moving the stream // pointer, handling also the case of compound chunks. // switch (iff::PeekChunkOrGroupFormat (is)) { case fmt_PlayerName: iff::ReadChunk (is, m_Name, fmt_PlayerName); break; case fmt_PlayerStats: iff::ReadChunk (is, m_Stats, fmt_PlayerStats); break; case fmt_Inventory: iff::ReadVector(is, m_Inventory, fmt_Inventory); break; case fmt_Quests: iff::ReadLIST (is, m_Quests, fmt_Quests); break; default: iff::SkipChunk (is); break; } } } This way missing chunks will not cause a problem, resulting in defaults being used for the corresponding object, and neither will new ones, which will be skipped. Once you have this set up, changing the file format becomes more or less easy and painless, both for you and your users. All this you get for a very small cost of changing simple flow writes to WriteChunk and the like. As you can see above, the code remains readable, maintainable, and compact. Finally, if a user sends you his savefile that reproduces some bug, and you need to find out whether he was low on mana, youll be able to find the right number at a glance in a hex editor; its bytes 8 and 9 after STAT. Whats New in This Release: - This is the initial release of the library, featuring basic functionality of reading and writing simple and compound chunks..

Requirements: No special requirements
Platforms: Linux
Keyword: Cplayerstats Data Data Files Files Format Iff Iff Format Library Interchange Files Library Objects Reading And Writing T M Utility Functions
Users rating: 0/10

License: Freeware Size: 26.62 KB
3D Graphic Tools  -  libbsb 0.0.7
libbsb is a portable C library for reading and writing BSB format image files. Typically used for nautical charts, BSB charts use the .KAP or .CAP extension and store cartographic information in addition to a run-length encoded raster image....
153.6 KB  
Libraries  -  Libquicktime 1.0.0
Libquicktime is a library for reading and writing quicktime files. Note: libquicktime is in no way related to the original quicktime software, which can be found here. You should not expect all quicktime files created by original software to be...
1003.52 KB  
Libraries  -  CFITSIO 3.040
CFITSIO is a library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format. CFITSIO simplifies the task of writing software that deals with FITS files by providing an easy to use...
2.06 MB  
Programming  -  niftilib 2.0.0 Alpha
Niftilib is a set of i/o libraries for reading and writing files in the nifti-1 data format. nifti-1 is a binary file format for storing medical image data, e.g. magnetic resonance image (MRI) and functional MRI (fMRI) brain images.
256 KB  
Libraries  -  libsndfile 1.0.17
Libsndfile is a C library for reading and writing files containing sampled sound (such as the Apple/SGI AIFF format and MS Windows WAV) through one standard library interface. The library was written to compile and run on a Linux system but...
808.96 KB  
Modules  -  Transformations -- CSV 6.x-1.0-beta1
A set of operations for the Transformations module that deal with reading and writing CSV data.This module makes use of the standards-compliant CSV parser at to parse its input data. That's generally good for memory...
10 KB  
Science  -  SegyMAT 1.4
SegyMAT is a set of Matlab files for reading and writing SEG-Y files from Matlab. SegyMAT aims at being both simple to use to read SEG-Y files, and extensive enough to aid in writing complex seismic data.
491.52 KB  
Science  -  Python ISO8211 Library 8211.beta.0.9.1
This project provides a library written in Python for reading and eventually writing ISO8211 files. ISO8211 is a format used for various GIS systems (geographic data), including SDTS, the format used by the US Geological Survey.
70.75 KB  
Libraries  -  FlatTree 0.5.1
FlatTree is a Java library designed for reading and writing of flat files. The library will help you with CSV, FLR (fixed length record) or mixed structures, offers tree-style processing API and adapters for SAX, Stax and XStream for...
Science  -  SWISS::Knife 1.68
Perl module for reading and writing UniProtKB data in plain text format.
950.7 KB  
Programming  -  Cedalion for Linux 0.2.6
Cedalion is a programming language that allows its users to add new abstractions and define (and use) internal DSLs. Its innovation is in the fact that it uses projectional editing to allow the new abstractions to have no syntactic limitations.
471.04 KB  
Programming  -  Math::GMPf 0.29
Math::GMPf - perl interface to the GMP library's floating point (mpf) functions.
30.72 KB  
Programming  -  Net::Wire10 1.08
Net::Wire10 is a Pure Perl connector that talks to Sphinx, MySQL and Drizzle servers. Net::Wire10 implements the low-level network protocol, alias the MySQL wire protocol version 10, necessary for talking to one of the aforementioned...
30.72 KB  
Programming  -  logilab-common 0.56.2
a bunch of modules providing low level functionnalities shared among some python projects devel Please note that some of the modules have some extra dependencies. For instance, logilab.common.db will require a db-api 2.0 compliant...
174.08 KB  
Programming  -  OpenSSL for linux 1.0.0a
The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a...
3.83 MB  
Libraries  -  wolfSSL 3.15.3
The wolfSSL embedded SSL/TLS library is a lightweight SSL library written in ANSI standard C and targeted for embedded and RTOS environments - primarily because of its small size, speed, and feature set. It is commonly used in standard operating...
3.88 MB  
Libraries  -  EuGTK 4.8.9
Makes it easy to develop good- looking, fast, cross-platform programs that run on Linux, OS X, and Windows. Euphoria is a very fast interpreted/compiled language with straight-forward syntax. EuGTK allows programming in a clean, object-oriented...
10.68 MB  
Libraries  -  Linux User Group Library Manager 1.0
The LUG Library Manager is a project to help Linux User Groups start their own library. A LUG library is helpful to the community at large because it increases access to information, and gives everyone the opportunity to become more knowledgeable.
5.35 KB  
Libraries  -  Module::MakefilePL::Parse 0.12
Module::MakefilePL::Parse is a Perl module to parse required modules from Makefile.PL. SYNOPSIS use Module::MakefilePL::Parse; open $fh, Makefile.PL; $parser = Module::MakefilePL::Parse->new( join("", ) ); $info = $parser->required;...
8.19 KB  
Libraries  -  sqlpp 0.06
sqlpp Perl package is a SQL preprocessor. sqlpp is a conventional cpp-alike preprocessor taught to understand SQL ( PgSQL, in particular) syntax specificities. In addition to the standard #define/#ifdef/#else/#endif cohort, provides also...
10.24 KB