Open-RJ C/C++ User's Journal Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

example_stl_4.cpp

C++ example program for the Open-RJ/STL mapping. Demonstrates handling of parsing errors.

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        STL_simple.cpp
00003  *
00004  * Purpose:     C++ example program for the Open-RJ/STL mapping. Demonstrates
00005  *              handling of parsing errors.
00006  *
00007  * Created:     12th May 2006
00008  * Updated:     28th May 2006
00009  *
00010  * www:         http://www.openrj.org/
00011  *
00012  * License:     Copyright (c) 2006, Synesis Software Pty Ltd.
00013  *              All rights reserved.
00014  *
00015  *              (Licensed under the Synesis Software Open License)
00016  *
00017  *              This source code is placed into the public domain 2006
00018  *              by Synesis Software Pty Ltd. There are no restrictions
00019  *              whatsoever to your use of the software.
00020  *
00021  * ////////////////////////////////////////////////////////////////////////// */
00022 
00023 
00024 /* Open-RJ Header Files */
00025 #include <openrj/stl/database.hpp>
00026 
00027 /* Standard C++ Library Files */
00028 #include <iostream>
00029 
00030 /* /////////////////////////////////////////////////////////////////////////////
00031  * Namespace
00032  */
00033 
00034 using std::cerr;
00035 using std::endl;
00036 using std::cout;
00037 
00038 /* /////////////////////////////////////////////////////////////////////////////
00039  * Globals
00040  */
00041 
00042 // Sample database
00043 static const char   contents[] =
00044 
00045     "%% Sample Open-RJ database - Cats and Dogs\n"
00046     "%% Created:   28th September 2004\n"
00047     "%% Updated:   29th September 2004\n"
00048     "Name:      Barney\n"
00049     "Species:   Dog\n"
00050     "Breed:     Bijon \\\n"
00051     "           Frieze\n"
00052     "%%\n"
00053     "Name:      Elsa\n"
00054     "Species:   Dog\n"
00055     "Breed:     Mixed\n"
00056     "%%\n"
00057     "Name:      Fluffy Kitten\n"
00058     "Species:   Cat\n"
00059     "%%\n"
00060     "Name:      Moet\n"
00061     "Species:   Dog\n"
00062     "Breed:     Boxer\n"
00063     "%%\n"
00064     "Name:      Rebel\n"
00065     "Species:   Dog\n"
00066     "Breed:     German \\\n"
00067     "           Shepherd"       // The error is here (the \n has been removed)
00068     "%%\n"
00069     "Name:      Sparky\n"
00070     "Species:   Cat\n"
00071     "%%\n";
00072 
00073 /* ////////////////////////////////////////////////////////////////////////// */
00074 
00075 int main()
00076 {
00077     try
00078     {
00079         unsigned                        flags   =   0;  // No special flags here.
00080         openrj::stl::memory_database    db(&contents[0], sizeof(contents), flags);
00081 
00082     }
00083     catch(std::exception &x)
00084     {
00085         cerr << "Failed to open database: " << x.what() << endl;
00086     }
00087 
00088     return EXIT_SUCCESS;
00089 }
00090 
00091 /* /////////////////////////////////////////////////////////////////////////////
00092  * end of file
00093  */

Open-RJ Library documentation © Synesis Software Pty Ltd, 2004-2005