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

example_stl_6.cpp

C++ example program for the Open-RJ/STL mapping. Demonstrates searching for fields in database.

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

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