Main | License | Installation | FAQ | Screenshots | Contact | Links | Sf.net | Freshmeat.net | KDE-Apps.org
Requirements | Design | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CookBook Class Reference

#include <cookBook.hpp>

Inheritance diagram for CookBook:

Inheritance graph
[legend]

Public Member Functions

 CookBook (DatabasePtr _database, const std::string &inputXSLFileName, const std::string &outputXSLFileName, bool performVersionCheck=true) throw (Error)
CompilerPtr getXMLLayer (void) const
DatabasePtr getDatabase (void) const
int getVersion (void) const throw (Error)
 Query database version.
void update (void) throw (Error)
 Update database version.

Static Protected Member Functions

static CompilerPtr createXMLLayer (DatabasePtr _database, const std::string &inputXSLFileName, const std::string &outputXSLFileName)

Protected Attributes

DatabasePtr database
 Database.
CompilerPtr xmlLayer
 Compiler-chain.

Detailed Description

Specialized database class for accessing cookbook database. This class encapsulates the knowledge about the special structure of the cookbook database.

Todo:
Porting of old databases using a wizard.

Use transactions.

Date:
Thu Mar 10 2005
Author:
Jan Wedekind (wedesoft@users.sourceforge.net)

Definition at line 31 of file cookBook.hpp.


Constructor & Destructor Documentation

CookBook::CookBook ( DatabasePtr  _database,
const std::string &  inputXSLFileName,
const std::string &  outputXSLFileName,
bool  performVersionCheck = true 
) throw (Error)

Constructor.

Parameters:
_database Database holding the recipes.
inputXSLFileName Filename of XSL-script translating XML-queries to the SQL-dialec of the database.
outputXSLFileName Filename of XSL-script adapting the structure of the output generated by the XSU-utility.
performVersionCheck This boolean has to be set to false, if the database is empty (no tables have been created yet).
See also:
XSU

XSLCompiler


Member Function Documentation

CompilerPtr CookBook::getXMLLayer ( void   )  const [inline]

Get compiler-chain for accessing database. The returned compiler-chain is an XSU-utility with two XSL-scripts for pre- and postprocessing. The XSL-scripts are providing an abstraction- layer to hide the SQL-dialect of the database.

The following picture illustrates, how the compiler-chain is being used to extract a recipe for example:

cookbook.png

Example for using compiler-chain

Returns:
Compiler-chain for accessing database.

Definition at line 57 of file cookBook.hpp.

References xmlLayer.

00057 { return xmlLayer; }

DatabasePtr CookBook::getDatabase ( void   )  const [inline]

Get direct access to database.

See also:
Database

Definition at line 60 of file cookBook.hpp.

References database.

00060 { return database; }

int CookBook::getVersion ( void   )  const throw (Error)

Query database version.

Definition at line 56 of file cookBook.cpp.

References XMLDocument::fromString(), XMLDocument::getDocumentElement(), and xmlLayer.

Referenced by update().

00057 {
00058   XMLDocument xmlDocument( "" );
00059   xmlDocument.fromString
00060     ( xmlLayer->translate
00061       ( "<?xml version='1.0' encoding='UTF-8'?><version/>" ) );
00062   int
00063     version = atoi( xmlDocument.getDocumentElement().selectNode( "version" ).
00064                     getNodeText().c_str() );
00065   return version;
00066 }

void CookBook::update ( void   )  throw (Error)

Update database version.

Definition at line 68 of file cookBook.cpp.

References ERRORMACRO, getVersion(), versionText(), and xmlLayer.

00069 {
00070   // Read version number.
00071   int version = getVersion();
00072   
00073   // Check for minimum version requirement.
00074   ERRORMACRO( version >= 13, Error, ,
00075               i18n( "Update for database versions 0.1 to 0.12 is not "
00076                     "supported." ) );
00077   
00078   // Check against maximum version constraint.
00079   ERRORMACRO( version <= DATABASEVERSION, Error, ,
00080               i18n( "Recipe database is of version %1. This software can "
00081                     "only handle databases up to version %2. You need to "
00082                     "update AnyMeal to access this database." ).
00083               arg( versionText( version ) ).
00084               arg( versionText( DATABASEVERSION ) ) );
00085 
00086   // Update database.
00087   stringstream query;
00088   query << "<?xml version='1.0' encoding='UTF-8'?>" << endl
00089         << "<update><version>" << version << "</version></update>"
00090         << endl;
00091   ofstream nullDevice( "/dev/null" );
00092   xmlLayer->translate( query, nullDevice );
00093 }

static CompilerPtr CookBook::createXMLLayer ( DatabasePtr  _database,
const std::string &  inputXSLFileName,
const std::string &  outputXSLFileName 
) [static, protected]


Field Documentation

DatabasePtr CookBook::database [protected]

Database.

Definition at line 71 of file cookBook.hpp.

Referenced by getDatabase().

CompilerPtr CookBook::xmlLayer [protected]

Compiler-chain.

Definition at line 73 of file cookBook.hpp.

Referenced by getVersion(), getXMLLayer(), and update().


The documentation for this class was generated from the following files:

anymeal 0.30 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Sep 14 16:01:28 2008 - GNU Free Documentation License