]> git.tdb.fi Git - libs/datafile.git/blob - Readme.txt
Fix binary format
[libs/datafile.git] / Readme.txt
1 libmspdatafile - structured datafile library
2 Copyright © 2006-2007  Mikko Rasa, Mikkosoft Productions
3 Version 0.1 readme
4
5
6 Libmspdatafile is a library for reading and writing structured data files.  It
7 supports both a human-readable text format and a more compact binary format.
8 The text-based format is designed to be compact yet clean, avoiding much of the
9 redundancy of XML.
10
11 Libmspdatafile is distributed under the terms of the GNU Lesser Public License.
12 Full text of the license can be found in the file License.txt.
13
14
15 *** Structure
16
17 The basic building block of a datafile is a statement.  A statement has a
18 keyword and zero or more arguments.  It may also have zero or more substate-
19 ments.
20
21 The interface is heavily object-oriented and typically one statement in a file
22 represents one object in the program's memory.
23
24 The library supports five basic data types: integers, floats, strings, booleans
25 and enums.  Data types are strictly enforced - the only allowed conversion is
26 from float to integer.
27
28 The correct argument types for a statement is determined from the function or
29 variable used to load it.  This means that semantical validation can only be
30 done by the program that actually uses the file.  A generic tool can only
31 perform syntactic validation.
32
33
34 *** Basic usage
35
36 Loading data from files is achieved through Loader classes.  Such a class must
37 be derived from the DataFile::Loader class.  In the constructor, a series of
38 calls to the various overloads of the add() function is executed, telling the
39 loader what to do.  The two basic actions are calling a function of the loader
40 with the statement's arguments, or assigning the arguments to variables of the
41 loaded object.
42
43 There is a load() function in namespace scope that allows loading a whole file
44 into an object.
45
46 It is also possible to call the Parser::parse function directly and obtain a
47 raw Statement.  However, this is rarely useful.
48
49
50 *** Syntax
51
52 The syntax of the text format vaguely resembles C.  Statements are terminated
53 with a semicolon and substatements are enclosed between burly braces.  The sub-
54 statement block comes after all arguments and the semicolon comes after it.  An
55 empty substatement block is allowed and equal to an absent block.
56
57 Integers can be written in decimal, octal or hexadecimal notation.  A minus
58 sign can be used in any base for negative numbers, as well as an optional plus
59 sign for positive numbers.
60
61 Floats must be written in decimal and they must contain a decimal point.  An
62 exponent may come after the mantissa, separated by the character e.  Minus and
63 plus signs are allowed in both exponent and mantissa.
64
65 Strings are enclosed in double quotes.  Backslash can be used to escape a
66 literal double quote or backslash.
67
68 Booleans are either true or false.
69
70 Enumeration values are represented as symbolic identifiers.  They may contain
71 alphaumeric characters and underscores and must begin with a letter or an
72 underscore.
73
74
75 *** Binary format
76
77 The binary format is not intended to be manipulated by anything else than
78 libmspdatafile.  A detailed description is not available at this time.
79
80 The tool provided with the library can be used to convert between the two
81 formats.
82
83
84 *** $Id$