00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <openrj/cpp/database.hpp>
00029
00030
00031 #include <iostream>
00032
00033
00034
00035
00036
00037 using std::cerr;
00038 using std::endl;
00039 using std::cout;
00040
00041
00042
00043
00044
00045
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;
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
00104