JAULA Developer's Guide

JAULA Developer's Guide Copyright (c) 2007 Kombo Morongo

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with the Invariant Sections being Preface, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU Free Documentation License".

Preface

JAULA means JSON Analysis User Library Acronym and is the name given to the library for parsing/generating JSON formatted data to/from C++

This guide describes the library API, gives a few example on its usage and gives some information for installing the library on a Linux system

This guide is for JAULA version 1.X.X

Latest and former revisions of this guide and other JAULA available documentation can be obtained at http://morongo.homelinux.net/jaula/docs

Copyright

JAULA Developer's Guide Copyright (c) 2007 Kombo Morongo

JAULA is a free software project developed by Kombo Morongo.

Kombo Morongo as the author and copyright holder of this software has licensed it under the terms of the GNU LGPL 2.1 license.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with the Invariant Sections being Preface, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license is included in the section entitled "GNU Free Documentation License".

GNU Free Documentation License

Below you will find a full copy of the GNU Free Documentation License Version 1.2. Actual version of this file can be directly obtained from the Free Software Foundation at http://www.fsf.org/licensing/licenses/fdl.txt.

		GNU Free Documentation License
		  Version 1.2, November 2002


 Copyright (C) 2000,2001,2002  Free Software Foundation, Inc.
     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.


0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other
functional and useful document "free" in the sense of freedom: to
assure everyone the effective freedom to copy and redistribute it,
with or without modifying it, either commercially or noncommercially.
Secondarily, this License preserves for the author and publisher a way
to get credit for their work, while not being considered responsible
for modifications made by others.

This License is a kind of "copyleft", which means that derivative
works of the document must themselves be free in the same sense.  It
complements the GNU General Public License, which is a copyleft
license designed for free software.

We have designed this License in order to use it for manuals for free
software, because free software needs free documentation: a free
program should come with manuals providing the same freedoms that the
software does.  But this License is not limited to software manuals;
it can be used for any textual work, regardless of subject matter or
whether it is published as a printed book.  We recommend this License
principally for works whose purpose is instruction or reference.


1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that
contains a notice placed by the copyright holder saying it can be
distributed under the terms of this License.  Such a notice grants a
world-wide, royalty-free license, unlimited in duration, to use that
work under the conditions stated herein.  The "Document", below,
refers to any such manual or work.  Any member of the public is a
licensee, and is addressed as "you".  You accept the license if you
copy, modify or distribute the work in a way requiring permission
under copyright law.

A "Modified Version" of the Document means any work containing the
Document or a portion of it, either copied verbatim, or with
modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of
the Document that deals exclusively with the relationship of the
publishers or authors of the Document to the Document's overall subject
(or to related matters) and contains nothing that could fall directly
within that overall subject.  (Thus, if the Document is in part a
textbook of mathematics, a Secondary Section may not explain any
mathematics.)  The relationship could be a matter of historical
connection with the subject or with related matters, or of legal,
commercial, philosophical, ethical or political position regarding
them.

The "Invariant Sections" are certain Secondary Sections whose titles
are designated, as being those of Invariant Sections, in the notice
that says that the Document is released under this License.  If a
section does not fit the above definition of Secondary then it is not
allowed to be designated as Invariant.  The Document may contain zero
Invariant Sections.  If the Document does not identify any Invariant
Sections then there are none.

The "Cover Texts" are certain short passages of text that are listed,
as Front-Cover Texts or Back-Cover Texts, in the notice that says that
the Document is released under this License.  A Front-Cover Text may
be at most 5 words, and a Back-Cover Text may be at most 25 words.

A "Transparent" copy of the Document means a machine-readable copy,
represented in a format whose specification is available to the
general public, that is suitable for revising the document
straightforwardly with generic text editors or (for images composed of
pixels) generic paint programs or (for drawings) some widely available
drawing editor, and that is suitable for input to text formatters or
for automatic translation to a variety of formats suitable for input
to text formatters.  A copy made in an otherwise Transparent file
format whose markup, or absence of markup, has been arranged to thwart
or discourage subsequent modification by readers is not Transparent.
An image format is not Transparent if used for any substantial amount
of text.  A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain
ASCII without markup, Texinfo input format, LaTeX input format, SGML
or XML using a publicly available DTD, and standard-conforming simple
HTML, PostScript or PDF designed for human modification.  Examples of
transparent image formats include PNG, XCF and JPG.  Opaque formats
include proprietary formats that can be read and edited only by
proprietary word processors, SGML or XML for which the DTD and/or
processing tools are not generally available, and the
machine-generated HTML, PostScript or PDF produced by some word
processors for output purposes only.

The "Title Page" means, for a printed book, the title page itself,
plus such following pages as are needed to hold, legibly, the material
this License requires to appear in the title page.  For works in
formats which do not have any title page as such, "Title Page" means
the text near the most prominent appearance of the work's title,
preceding the beginning of the body of the text.

A section "Entitled XYZ" means a named subunit of the Document whose
title either is precisely XYZ or contains XYZ in parentheses following
text that translates XYZ in another language.  (Here XYZ stands for a
specific section name mentioned below, such as "Acknowledgements",
"Dedications", "Endorsements", or "History".)  To "Preserve the Title"
of such a section when you modify the Document means that it remains a
section "Entitled XYZ" according to this definition.

The Document may include Warranty Disclaimers next to the notice which
states that this License applies to the Document.  These Warranty
Disclaimers are considered to be included by reference in this
License, but only as regards disclaiming warranties: any other
implication that these Warranty Disclaimers may have is void and has
no effect on the meaning of this License.


2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either
commercially or noncommercially, provided that this License, the
copyright notices, and the license notice saying this License applies
to the Document are reproduced in all copies, and that you add no other
conditions whatsoever to those of this License.  You may not use
technical measures to obstruct or control the reading or further
copying of the copies you make or distribute.  However, you may accept
compensation in exchange for copies.  If you distribute a large enough
number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and
you may publicly display copies.


3. COPYING IN QUANTITY

If you publish printed copies (or copies in media that commonly have
printed covers) of the Document, numbering more than 100, and the
Document's license notice requires Cover Texts, you must enclose the
copies in covers that carry, clearly and legibly, all these Cover
Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
the back cover.  Both covers must also clearly and legibly identify
you as the publisher of these copies.  The front cover must present
the full title with all words of the title equally prominent and
visible.  You may add other material on the covers in addition.
Copying with changes limited to the covers, as long as they preserve
the title of the Document and satisfy these conditions, can be treated
as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit
legibly, you should put the first ones listed (as many as fit
reasonably) on the actual cover, and continue the rest onto adjacent
pages.

If you publish or distribute Opaque copies of the Document numbering
more than 100, you must either include a machine-readable Transparent
copy along with each Opaque copy, or state in or with each Opaque copy
a computer-network location from which the general network-using
public has access to download using public-standard network protocols
a complete Transparent copy of the Document, free of added material.
If you use the latter option, you must take reasonably prudent steps,
when you begin distribution of Opaque copies in quantity, to ensure
that this Transparent copy will remain thus accessible at the stated
location until at least one year after the last time you distribute an
Opaque copy (directly or through your agents or retailers) of that
edition to the public.

It is requested, but not required, that you contact the authors of the
Document well before redistributing any large number of copies, to give
them a chance to provide you with an updated version of the Document.


4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under
the conditions of sections 2 and 3 above, provided that you release
the Modified Version under precisely this License, with the Modified
Version filling the role of the Document, thus licensing distribution
and modification of the Modified Version to whoever possesses a copy
of it.  In addition, you must do these things in the Modified Version:

A. Use in the Title Page (and on the covers, if any) a title distinct
   from that of the Document, and from those of previous versions
   (which should, if there were any, be listed in the History section
   of the Document).  You may use the same title as a previous version
   if the original publisher of that version gives permission.
B. List on the Title Page, as authors, one or more persons or entities
   responsible for authorship of the modifications in the Modified
   Version, together with at least five of the principal authors of the
   Document (all of its principal authors, if it has fewer than five),
   unless they release you from this requirement.
C. State on the Title page the name of the publisher of the
   Modified Version, as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications
   adjacent to the other copyright notices.
F. Include, immediately after the copyright notices, a license notice
   giving the public permission to use the Modified Version under the
   terms of this License, in the form shown in the Addendum below.
G. Preserve in that license notice the full lists of Invariant Sections
   and required Cover Texts given in the Document's license notice.
H. Include an unaltered copy of this License.
I. Preserve the section Entitled "History", Preserve its Title, and add
   to it an item stating at least the title, year, new authors, and
   publisher of the Modified Version as given on the Title Page.  If
   there is no section Entitled "History" in the Document, create one
   stating the title, year, authors, and publisher of the Document as
   given on its Title Page, then add an item describing the Modified
   Version as stated in the previous sentence.
J. Preserve the network location, if any, given in the Document for
   public access to a Transparent copy of the Document, and likewise
   the network locations given in the Document for previous versions
   it was based on.  These may be placed in the "History" section.
   You may omit a network location for a work that was published at
   least four years before the Document itself, or if the original
   publisher of the version it refers to gives permission.
K. For any section Entitled "Acknowledgements" or "Dedications",
   Preserve the Title of the section, and preserve in the section all
   the substance and tone of each of the contributor acknowledgements
   and/or dedications given therein.
L. Preserve all the Invariant Sections of the Document,
   unaltered in their text and in their titles.  Section numbers
   or the equivalent are not considered part of the section titles.
M. Delete any section Entitled "Endorsements".  Such a section
   may not be included in the Modified Version.
N. Do not retitle any existing section to be Entitled "Endorsements"
   or to conflict in title with any Invariant Section.
O. Preserve any Warranty Disclaimers.

If the Modified Version includes new front-matter sections or
appendices that qualify as Secondary Sections and contain no material
copied from the Document, you may at your option designate some or all
of these sections as invariant.  To do this, add their titles to the
list of Invariant Sections in the Modified Version's license notice.
These titles must be distinct from any other section titles.

You may add a section Entitled "Endorsements", provided it contains
nothing but endorsements of your Modified Version by various
parties--for example, statements of peer review or that the text has
been approved by an organization as the authoritative definition of a
standard.

You may add a passage of up to five words as a Front-Cover Text, and a
passage of up to 25 words as a Back-Cover Text, to the end of the list
of Cover Texts in the Modified Version.  Only one passage of
Front-Cover Text and one of Back-Cover Text may be added by (or
through arrangements made by) any one entity.  If the Document already
includes a cover text for the same cover, previously added by you or
by arrangement made by the same entity you are acting on behalf of,
you may not add another; but you may replace the old one, on explicit
permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License
give permission to use their names for publicity for or to assert or
imply endorsement of any Modified Version.


5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this
License, under the terms defined in section 4 above for modified
versions, provided that you include in the combination all of the
Invariant Sections of all of the original documents, unmodified, and
list them all as Invariant Sections of your combined work in its
license notice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy of this License, and
multiple identical Invariant Sections may be replaced with a single
copy.  If there are multiple Invariant Sections with the same name but
different contents, make the title of each such section unique by
adding at the end of it, in parentheses, the name of the original
author or publisher of that section if known, or else a unique number.
Make the same adjustment to the section titles in the list of
Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections Entitled "History"
in the various original documents, forming one section Entitled
"History"; likewise combine any sections Entitled "Acknowledgements",
and any sections Entitled "Dedications".  You must delete all sections
Entitled "Endorsements".


6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this
License in the various documents with a single copy that is included in
the collection, provided that you follow the rules of this License for
verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute
it individually under this License, provided you insert a copy of this
License into the extracted document, and follow this License in all
other respects regarding verbatim copying of that document.


7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate
and independent documents or works, in or on a volume of a storage or
distribution medium, is called an "aggregate" if the copyright
resulting from the compilation is not used to limit the legal rights
of the compilation's users beyond what the individual works permit.
When the Document is included in an aggregate, this License does not
apply to the other works in the aggregate which are not themselves
derivative works of the Document.

If the Cover Text requirement of section 3 is applicable to these
copies of the Document, then if the Document is less than one half of
the entire aggregate, the Document's Cover Texts may be placed on
covers that bracket the Document within the aggregate, or the
electronic equivalent of covers if the Document is in electronic form.
Otherwise they must appear on printed covers that bracket the whole
aggregate.


8. TRANSLATION

Translation is considered a kind of modification, so you may
distribute translations of the Document under the terms of section 4.
Replacing Invariant Sections with translations requires special
permission from their copyright holders, but you may include
translations of some or all Invariant Sections in addition to the
original versions of these Invariant Sections.  You may include a
translation of this License, and all the license notices in the
Document, and any Warranty Disclaimers, provided that you also include
the original English version of this License and the original versions
of those notices and disclaimers.  In case of a disagreement between
the translation and the original version of this License or a notice
or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements",
"Dedications", or "History", the requirement (section 4) to Preserve
its Title (section 1) will typically require changing the actual
title.


9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except
as expressly provided for under this License.  Any other attempt to
copy, modify, sublicense or distribute the Document is void, and will
automatically terminate your rights under this License.  However,
parties who have received copies, or rights, from you under this
License will not have their licenses terminated so long as such
parties remain in full compliance.


10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions
of the GNU Free Documentation License from time to time.  Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.  See
http://www.gnu.org/copyleft/.

Each version of the License is given a distinguishing version number.
If the Document specifies that a particular numbered version of this
License "or any later version" applies to it, you have the option of
following the terms and conditions either of that specified version or
of any later version that has been published (not as a draft) by the
Free Software Foundation.  If the Document does not specify a version
number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.

Introduction

JAULA is a library for integrating JSON (RFC4627) data within c++ projects. This means serializing c++ native data into a stream with JSON format as well as reading a stream containing JSON formatted data into c++ native data types.

System requirements have focused on an standard GNU C++ development environment and STL has been thoroughly used all along the library development and API so, a minimun knowledge about abstract containers and auto-pointers could be required for a complete understanding of the library behaviour.

This guide aims to provide an in deep understanding of the library from the perspective of a developer who is trying to use it for its own applications.

Audience

This guide aims to provide an in deep understanding of the library from the perspective of a developer who is trying to use it for its own applications so, the intended audience are c++ developers interested in JSON data interchange.

System requirements have focused on an standard GNU C++ development environment and STL has been thoroughly used all along the library development and API so, a minimun knowledge about abstract containers and auto-pointers could be required for a complete understanding of the library behaviour.

Besides this, a minimun knowledge of autotools could be of help in order to ease linking the library within any paritcular application.

The next section provides a list of references to documents where you can get mor information about these particular subjects.

Related Documents

This section lists a set of documents that complements or is related with the material exposed in this guide.

Known Restrictions

As good as telling what the libray does is to tell what it doesn't and this section lists known limitations or unexpected bahavoiurs you may find using this library as to be warned about it.

wide characters support
This release of the library does not support wide characters (characters that require more than 8 bits for representing its value) data for C++ as all string values are stored in STL std::string objects, although it can deal with Unicode characters for JSON data. What it means is that, at the time of generating JSON data, as there is no way to express wide character strings, all the JSON formatted strings will result in 8 bits per character repesentation and that, at the time of parsing JSON formatted data into C++, unicode characters wider than 8 bits will be correctly read but only the least significant byte for each character will be stored in the resulting C++ string.
floating point and integer numeric values
As it is explained in the data values section, in order to ease conversion to and form C++ numeric data, two separate numeric values containers have been created, one for fixed point integer values and other for floating point quantites. This restriction is not imposed by JSON itself that indifferently express fixed and floating point quantities as numeric values. At time of generating JSON data, this restriction is generally trivial as you can always use the floating point numeric value container for any quantity and, if this quantity results in an integer value, the resulting JSON generated value will be correctly expressed but, at the time of parsing JSON data, you may expect the integer or the floating point value container read for a quantity depending on the particular data value read and it will be up to the user to determine (usually via dynamic casting) which value conatiner was used by the parsing process.

Installation

This chapter explains how to download and install the JAULA library and its examples from sources repository or from the packages available at SourceForge.

Obtaining JAULA

At the time of this edition, JAULA project is being held at SourceForge and you can access it by following the link http://sourceforge.net/projects/jaula/.

Although my recommendation is to navigate through the project to check for releases available, bugs fixed, notes and further documentation, if you want to start right now, project release downloadables are available at http://sourceforge.net/project/showfiles.php?group_id=193555.

If you are interested in accesing "live" source in order to get latest patches (and no warranties about how it works), development subversion repository is available at https://jaula.svn.sourceforge.net/svnroot/jaula. See the subversion repository section for configuring the sources for your environment.

Debian Packages

The library and an example using it have been compiled and packaged in Debian package format. Compiling was performed on a i386 PC running a Debian SID distribution.

As a result of the high variability of the Debian SID distribution over time, there is no exact description of the C++ compiler or required binaries and libraries used for its creation but, you must assume that the packaging was performed using a distribution updated to the release date.

Debian packaging was done following the Debian policy as well as some examples of well formatted packages for libraries and although lintian is complaining a little, packaging is fairly correct in its current state and no problems were detected using it and no manual operations are required to complete package installation or to cleanly uninstall them.

As it is explained in the Creating Debian packages from sources section, the scripts and related files for packaging have been included in the source tree so you will be able to create distribution packages for other environments starting up from sources.

Available Debian packages

For a generic X.Y.Z release, the Nth packaging operation will contain the following packages:

libjaulaX_X.Y.Z-N_i386.deb
Library Runtime. This package contains the library dynamically compiled as it is required by jparse or any executable you may create based on it.
libjaula-dev_X.Y.Z-N_i386.deb
Library development files. This package contains the headers, library compiled for static linking, libtool library definition and some other related files required to compile against this library without requiring to recompile it from sources.
libjaula-doc_X.Y.Z-N_i386.deb
Library documentation. This package contains the library documentation (created with doxygen) in html, rtf and latex format.
jparse_X.Y.Z-N_i386.deb
Example program. jparse reads a set of JSON formatted data files, analysing them in order to detect errors and re-writing file contents in a compressed form where line feeds and additional spaces have been removed.

Debian Package Installation

In order to install any of the packages in your system, download it from http://sourceforge.net/project/showfiles.php?group_id=193555 and then, from root user run:

# dpkg -i package_to_install

This command will succesfully run unless some package dependencies can not be satisfied or any system error appears. Besides dependencies with system libraries, the internal project interdependencies generally require binary library to be installed prior to any other package.

Source tarball

A generic X.Y.Z release will always contain a source tarball file of name jaula-X.Y.Z.tar.bz2 that can be downloaded from the project download page.

Dealing with the tarball implies the usual operations of uncompressing, compiling and installing the product which in a general case can be accomplished by the following command sequence:

$ tar xvjf jaula-X.Y.Z.tar.bz2
$ cd jaula-X.Y.Z
$ ./configure
$ make
$ su # or any other command in order to gain root privileges
# make install

This will install the libraries, header files and example binaries and documentation under the default directories (which usually are /usr/lib, /usr/include, /usr/bin and /usr/share/doc respectively).

Specific installation instructions can be found in the INSTALL file located at the project source root.

Note

Please note the "j" option in the tar command instead of the more usual "z" option. This is due to the bz2 (Burrows-Wheeler) algorithm used for file compression instead of gz gzip which results in a smaller file. If your system is old (really old) and you experience problems uncompressing the tarball, you may try the "l" option instead of "j" or even replace the "j" option by the long "--bzip2" alternative.

Source compilation requirements

In order to compile the sources in your system you will require a full operational C++ development environment consisting of a c++ compiler / linker and make as major dependencies. Also, because lexical analysis is based on flex, you will need this product installed as well.

If you want to generate library documentation, doxygen must be installed in your system but this is not mandatory in order to compile the sources. Also, pdflatex is required to convert the documentation to pdf format.

Configuration process will check if your environment is valid and will warn you if an optional component is missing or stop with an error if a mandatory dependency is not satisfied.

The development environment I have been using for this release consists of a Debian SID i386 distribution with the following packages installed:

  • gcc 4.1.1-15
  • make 3.81-3
  • flex 2.5.33-11
  • doxygen 1.5.1-1
  • texlive-extra-utils 2007-7

But, as the only requirements at source level are for flex and a good STL support, any POSIX environment should work fine.

In case you detect a problem compiling sources in a particular environment please post a support request at http://sourceforge.net/tracker/?group_id=193555&atid=945883 detailing the environment used and the error report at configuration or compilation stage.

Creating debian packages from sources

As it was described in the Debian packages section, all the scripts and related files required for generating the Debian packages are included in the source tree, at the /debian directory.

In case you want to create Debian packages for your particular environment, all you have to do after obtaining source code (by uncompressing tarball or downloading it from subversion repository) is to configure the package and run the following command sequence:

$ tar xvjf jaula-X.Y.Z.tar.bz2
$ cd jaula-X.Y.Z
$ ./configure
$ debuild -us -uc -rfakeroot

This will require that your system, besides the Source compilation requirements must satisfy a valid Debian packaging environment consisting of the following packages (when it is specifically required, minimum package level is annotated in brackets) :

  • dpkg
  • devscripts
  • debhelper (>= 4)
  • fakeroot (optional but highly advisable so you don't have to abuse of root privileges for packaging)
  • flex (>= 2.5)
  • doxygen (>= 1.4)
  • texlive-extra-utils

Although doxygen and texlive-extra-utils are not mandatory at source level configuration, this is a requirement that must be satisfied for Debian packaging because the control file attached checks their existence.

Note

Please note that because of the method used for packaging (at control file level), these dependencies must be installed as Debian packages and it is not valid to install them directly from sources.

As in the previous section, in case you detect a problem compiling sources in a particular environment please post a support request at http://sourceforge.net/tracker/?group_id=193555&atid=945883 detailing the environment used and the error report received from the packaging process.

Subversion repository

Sources are also public available through the subversion repository at https://jaula.svn.sourceforge.net/svnroot/jaula.

Dealing directly with subversion repository instead of using file releases (where you will also find sources in tarball format) has its own benefits and disadvantages such as:

Benefits
  • Direct access to last minute features and patches, before they are incorporated in a file release.
  • Sources from older releases are available, no matter if the corresponding file release is still available or not.
Disadvantages
  • Buggy or incomplete releases may be downloaded. All the file releases available, may it contain bugs or not, have at least been tested and sources can be compiled, packaged and successfully run the examples. This is not true for all the revisions available at sources repository. Actually only specific revisions are complete and functional and it is up to the user to prove if a particular repository revision is suitable for your needs.
  • Some deeper knowledge about subversion and autotools is required in order to put subversion downloaded sources to work. Some examples will be given in this chapter but this cannot replace real knowledge about what you are doing.

In general, subversion access is a must for someone who wants to participate in the project and would be a requirement for someone who is interested in patching the sources, evolving the library independently from this project or for someone trying to port it to a non supported environment.

Users who just need a library for JSON parsing / generation, to run a software that requires it or to make their own software, should be fine working with file releases (at source tarball level or binary packaging forms) and submitting bugs and requests through the project tracker at http://sourceforge.net/tracker/?group_id=193555.

If you are interested in taking a look at the project repository for checking logs or just see what is there, you can easily web browse it at http://jaula.svn.sourceforge.net/viewvc/jaula/.

If you are interested in participating in the project please mail to the project admin: morongo@users.sourceforge.net.

Specific SourceForge subversion documentation is available at http://sourceforge.net/docs/E09.

A very good online book about subversion is Version Control with Subversion available at http://svnbook.red-bean.com/nightly/en/index.html.

Repository organization

The subversion repository has been organized following the standard guidelines of three directories as explained below:

/trunk
This directory contains the development base line. All source changes will be by default directly applied here so, there is little chance for this directory (in any general revision) to contain a fully operational release (it may be even unable to compile). Unless you are participating in project development, this directory will be of very little use although you may be interested in taking a look into logs in order to see how and where is the project evolving to.
/tags
This directory contains all the tagged revisions. Inside this directory you will find a directory for each tagged version available for the project. In particular, there will always exist a tagged revision for each release or release candidate created so far. All release and release candidates have been named as the release they belong to. This directory will be particularly interesting for any general users who want to stay in a particular revision, no matter the present state of the project (as it will be shown in the example below).
/branches
This directory is not available yet as there has not been any need for it so far. In case that a real need comes up for evolving a named tag once the trunk development has changed so much that the change cannot be directly applied on the trunk line, a branch will be created starting from the named tag so that the tag is "frozen" in a fixed state and fixes can be applied without interfering normal project evolution. Until binary compatibility between library releases had been lost and critical bugs appear on any former release, there will be no real need for a branch so, the are little chances for a branch appearing in the near future. From a general user point of view, the branch directory will in general be as unstable and unreliable as the trunk base line is. All fixes created from branches will be always reflected in a tagged revision into the /tag directory so, only project developers are expected to make use of this directory.

This organization can be easily understood with an example. Let's suppose we are interested in obtaining the sources fro the 1.1.0-1 release (and that they are no available in tarball format from the file downloa area). The subversion command for achieving it will be:

$ svn checkout https://jaula.svn.sourceforge.net/svnroot/jaula/tags/jaula-1.1.0-1 jaula_1101

Putting repository sources to work

Dealing with repository sources is much like dealing with tarball sources but with a significant difference. As a matter of personal taste and because I like to keep repository as generic as possible, no file that can be generated from another file already existing in the repository will be ever uploaded.

This means that files created by autoconf, automake, libtool and, in general all files created by autotools components must be regenerated in the user environment.

In particular, ./configure command cannot be run directly from repository downloaded sources as this command is not present in the repository because it will be generated by autoconf from configure.in and other scripts that do exist in the repository.

Because of this, you cannot deal directly with the repository sources unless your development environment contains the full autotool command set as to run the examples shown below.

This generic approach should permit sources not to be restricted to any particular environment release but (there is always an exception), because of syntax change in automake scripts, the environment should include automake 1.9 or higher release. Besides this, no other restriction is known.

The order in which autotool commands are executed is important as interdependencies exist. In the following example the full command sequence in the right order is shown for compiling sources directly downloaded from subversion repository. The example shows the download and compilation procedure followed for creating the jaula-1.1.0-1 release but it can be easily changed for any other repository revision.

$ svn checkout \
> https://jaula.svn.sourceforge.net/svnroot/jaula/tags/jaula-1.1.0-1 \
> jaula-1.1.0-1
$ cd jaula-1.1.0-1
$ aclocal
$ autoheader
$ libtoolize --copy --force
$ automake --add-missing --copy
$ autoconf # from this point configure is available and
$ ./configure # we can treat this sources as a tarball
$ make

Another use case that worth mentioning is how to create a source tarball from a generic subversion revision. For this, the dist make target can be used as shown in the following full example:

$ svn checkout \
> https://jaula.svn.sourceforge.net/svnroot/jaula/tags/jaula-1.1.0-1 \
> jaula-1.1.0-1
$ cd jaula-1.1.0-1
$ aclocal
$ autoheader
$ libtoolize --copy --force
$ automake --add-missing --copy
$ autoconf
$ ./configure
$ make dist

After running this command sequence a file named jaula-1.1.0.tar.bz2 will be available at project root level as well as an additional jaula-1.1.0.tar.gz file with standard gzip compression.

Although you may consider this way for dealing with repository a little bit restrictive, please consider the following:

  • If development is being held from different environments with different autotool component releases (which as a matter of fact is), excessive and unnecesary updates could be performed in the repository as configure and related scripts differ from one version to another although they essentially perform the same tasks.
  • There is little need for a general user to deal with repository sources as a source tarball will always exist for each file release. If you cannot run the command sequences showed or if the results are not what it was expected, please try to download any file release available for the project.
  • In case you are dealing with an environment where autotools are not available, you can always create a tarball source from any subversion revision (with the method explained before) in a complete system and then apply the resulting tarball in the target environment.

As with the other installation methods, if problems appear you can always submit a support request at the project tracker http://sourceforge.net/tracker/?group_id=193555.

JPARSE - An initial example

As with most APIs, an easy example does more for understanding how it works than a hundred pages describing it. so we will begin showing the example that comes with the library and that is called jparse.

jparse receives a list of files from the command line assuming that each argument is a file containing a full json formatted structure. It then opens and reads each of these files, stopping when an error is detected and writing parsed data again on standard output.

Because of this, jparse can be used as an example about how to read JSON data, how to write data in JSON format and it can also perform as a unit test where to check if a file is well formatted and how will the library work on a specific file.

Full example code

In this section a full copy of the jparse code is included to get a complete look of it. In the next sections, each signifcant portion of it will be discussed.

The latest version of the code is available at https://jaula.svn.sourceforge.net/svnroot/jaula/trunk/examples/jparse.cc.


/*
  jparse.cc : JSON analysis user library unit test
			  Test for JSON files syntactic analysis

  Copyright (C) 2007 Kombo Morongo <morongo666@gmail.com>

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

  svn info:

  $Author: morongo $
  $HeadURL: https://jaula.svn.sourceforge.net/svnroot/jaula/tags/jaula-1.2.0-2/examp... $
  $Id: jparse.cc 7 2007-04-14 14:54:34Z morongo $
  $Revision: 7 $
*/

extern "C"
{
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
}



#ifdef HAVE_MEMORY
#include <memory>
#endif

#ifdef HAVE_FSTREAM
#include <fstream>
#endif

#ifdef HAVE_IOSTREAM
#include <iostream>
#endif

#ifdef HAVE_STRING
#include <string>
#endif

#include <jaula.h>

#define APPNAME "jparse"

int main(int argc, char *argv[])
{        /* main */

	std::cout << APPNAME << " : syntax analysis test for " << PACKAGE_NAME
                << " version " << PACKAGE_VERSION << std::endl
		<< std::endl
		<< "usage : " << APPNAME << "file_specs" << std::endl
		<< std::endl;

	unsigned int good = 0;
	for(int i = 1; (i < argc); i++)
	{

		std::ifstream    arch(argv[i], std::ios::in);
		if (!arch)
		{
			std::cerr << "Could not open file " << argv[i] << std::endl
				<< ". Execution aborted." << std::endl;
			return 1;
		}

		try
		{
			std::cout << "Analyzing " << argv[i] << " ...";
			std::auto_ptr<JAULA::Value_Complexgt; pParsed(JAULA::Parser::parseStream(arch));
			std::cout << "Ok." << std::endl
				<< std::endl
				<< "Reduced expression of " << argv[i] << ':' << std::endl
				<< *(pParsed.get()) << std::endl;
			good++;
		}
		catch(JAULA::Exception ex)
		{
			std::cout << "Error." << std::endl;
			std::cerr << std::endl << ex << std::endl;
		}

		arch.close();

		std::cout << std::endl;
	}

	std::cerr << "Execution finished. " << good << " file(s) successfully parsed."
          << std::endl;
	return 0;
}	 /* main */



// EOF $Id: jparse.cc 7 2007-04-14 14:54:34Z morongo $

Library and system headers

Ignoring the #ifdef ... #endif macros surrouning the header files (these macros were included to be synchronized with configure checks and eventually run different header inclusions on different environments), and the #include <config.h> that is a header generated during the configuration process and that basically defines the variables used for the #ifdef ... #endif macros, the whole application only requires 5 header files.

From these header files, jaula.h is the header file that contains all the definitions required for JAULA and, if the only application requirements were solely for JAULA library, no other header files should be required.

But, as the application has to do some additional work, some other system headers were included for the reasons explained below.

memory
This header is part of the STL library and was included to provide the std::auto_ptr template that will get the application rid of manually freeing the memory associated to the data values read from the json files.
fstream
This header is part of the STL library and was included to provide the classes for dealing with file streams as JAULA always receives data from streams so, JSON files must be read from it.
iostream
This header is part of the STL library and was included to provide the classes for dealing with standard output as a stream as JAULA always write data to streams so, jparse output must be sent through it.
string
This header is part of the STL library and was included to provide the classes for dealing with character strings. This header is not really mandatory as JAULA uses it and this header is automatically included by the time jaula.h is included.

Program flow

program flow has been kept as easy as possible with only a main loop that is repeated for each file given in the command line.

In pseudo code notation, the program flow is reduced to:

function main()
{
 print "presentation message";
 for each file specified in the command line
 {
   open file;
   parse json data from file;
   write json data to standard output;
   close file;
 }
 print "final statistics";
}

JAULA namespace

In order to avoid name clashing between JAULA and other libraries or user objects, all the JAULA definitions have been declared within a namespace called JAULA.

JAULA exceptions

All the JAULA specific operations are performed in a try block like this:

try
{
	jaula specific operations
}
catch(JAULA::Exception ex)
{
	print "jaula exception raised";
}

This is because all the methods from the library that deal with external data may eventually fail and, this failure is signalled by raising an exception.

All the exceptions that may be launched by the JAULA library are derived from the JAULA::Exception base class. This base class has an insertion operator << defined so that any exception can be human readable by sending it to a stream like in the std::cerr << std::endl << ex << std::endl; sentence.

Parsing JSON data

In its easiest way, parsing JSON data is as trivial as invoking the static JAULA::Parser::parseStream() method giving a stream as its only input parameter.

This method will return (in case that parsing can be performed) a pointer to memory taken from the heap and containing a data value describing the JSON data read.

As a consequence of the JSON specification, this data value must be an array or an object that, in terms of the JAULA API is represented as a JAULA::Value_Complex type pointer returned that basically means that the data value can be iterated in order to get its components.

Once the parsing method returns, the data value allocated memory is no longer managed by the library and it will be up to the user when and how t will be fred in order to avoid memory leaks due to unfred memory or segmentation faults if some part of the program tries to use a chunk of memory fred by a former operation.

One way for automating memory management is by means of the std::auto_ptr template and this approach has been used in this example (and in library implementation as well). In case you need some more info about auto pointers, look at auto_ptr in C++ Annotations or look in the Related Documents section for more info.

Writing JSON fomatted data

All data value conainers include an insertion << operator that can send data to a stream in a JSON formatted way. If the data value is a complex one, this insertion operation will recursively generate JSON formatted data for each of ist components.

So, in a general case, creating JSON data is a matter of populating a data value structure and invoke the insertion operation on the outermost data value component. In this trivial example, data population was automatically performed by the previuos parsing operation and no direct program intervention is required.

We can say that this program behaves like an echo filter that outputs a replic of its input (although parsing process reduces additional spaces, tabs, linefeeds, etc. data meaning is kept unaltered between jparse input and output) and, beyond JSON conversion back and forth it behaves like:

int main()
{
    while (true)
    {
        char c;

        std::cin.get(c);
        if (std::cin.fail())
            break;
        std::cout << c;
    }
    return 0;
}

Library Description

This section describes the JAULA Library focusing on its general usage and not on specific details.

For a complete description of the library API, you may refer to the JAULA API reference guide.

Library Namespace

In order to prevent name clashing with user definitions or with other libraries, all library definitions have been enclosed within a namespace called JAULA.

No further namespaces have been used throughout the library as no internal namespace hierarchy was defined for its declaration or implementation.

Exceptions

Library error handling is supported by the use of exceptions.

This means that whenever a method cannot return the requested value because of inconsistencies within the parameters given or the data analysed, an exception will be raised instead. This exception can be caught at an upper level and program flow can take an alternative action in order to workaround the problem that raised the exception. Actually, all exceptions should be caught by the application in order to prevent it from abrupt termination.

In order to ease exception handling, all jaula exceptions are derived from JAULA::Exception base class. So, all jaula generated exceptions can be grouped in a single catch block as shown below:

try
{
  // application code invoking jaula methods goes here
}
catch(JAULA::Exception const &jaulex)
{
 // code dealing with jaula exceptions goes here
 std::cerr << "jaula exception detected : " << jaulex << std::endl;
}
catch(/* some other exceptions that may appear */)
{
 // code dealing with other exception types
}

As you may see in the pseudo code fragment above, all JAULA::Exception instances share an insertion operator that gives a brief description about the exception whenever it is applied on a stream.

This section will describe the general JAULA::Exception usage, the derived classes existing in the library and how to extend the exception handling hierarchy for your own purposes.