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

example_cpp_5.cpp

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

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        example_cpp_5.cpp
00003  *
00004  * Purpose:     C++ example program for the Open-RJ/C++ 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/cpp/database.hpp>
00029 
00030 /* Standard C++ Library Files */
00031 #include <iostream>
00032 
00033 /* /////////////////////////////////////////////////////////////////////////////
00034  * Namespace
00035  */
00036 
00037 using std::cerr;
00038 using std::endl;
00039 using std::cout;
00040 
00041 /* /////////////////////////////////////////////////////////////////////////////
00042  * Globals
00043  */
00044 
00045 // Sample database
00046 static const char   contents[] =
00047 
00048     "%% Sample Open-RJ database - Cats and Dogs\n"
00049     "%% Created:   28th September 2004\n"
00050     "%% Updated:   29th September 2004\n"
00051     "Name:      Barney\n"
00052     "Species:   Dog\n"
00053     "Breed:     Bijon \\\n"
00054     "           Frieze\n"
00055     "%%\n"
00056     "Name:      Elsa\n"
00057     "Species:   Dog\n"
00058     "Breed:     Mixed\n"
00059     "%%\n"
00060     "Name:      Fluffy Kitten\n"
00061     "Species:   Cat\n"
00062     "%%\n"
00063     "Name:      Moet\n"
00064     "Species:   Dog\n"
00065     "Breed:     Boxer\n"
00066     "%%\n"
00067     "Name:      Rebel\n"
00068     "Species:   Dog\n"
00069     "Breed:     German \\\n"
00070     "           Shepherd\n"
00071     "%%\n"
00072     "Name:      Sparky\n"
00073     "Species:   Cat\n"
00074     "%%\n";
00075 
00076 /* ////////////////////////////////////////////////////////////////////////// */
00077 
00078 int main()
00079 {
00080     try
00081     {
00082         unsigned                        flags   =   0;  // No special flags here.
00083         openrj::cpp::MemoryDatabase     db(&contents[0], sizeof(contents), flags);
00084 
00085         cout << endl << "Enumerating all fields in the database:" << endl;
00086 
00087         { for(size_t iField = 0; iField < db.GetNumFields(); ++iField)
00088         {
00089             openrj::cpp::Field field = db.GetField(iField);
00090 
00091             cout << "  " << field.GetName() << "=" << field.GetValue() << endl;
00092         }}
00093     }
00094     catch(std::exception &x)
00095     {
00096         cerr << "Failed to open database: " << x.what() << endl;
00097     }
00098 
00099     return EXIT_SUCCESS;
00100 }
00101 
00102 /* /////////////////////////////////////////////////////////////////////////////
00103  * end of file
00104  */

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