hash_db.h

Go to the documentation of this file.
00001 /*
00002  * hash_db.h
00003  *
00004  * Copyright (C) 2006  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Simple implementation of a transactionally safe hash database.
00032  */
00033 
00034 #ifndef WAVEPACKET_HASH_DB__H__
00035 #define WAVEPACKET_HASH_DB__H__
00036 
00037 // includes --------------------------------------------------------------------
00038 #include "datahash/datahash.h"          // these are what we store
00039 
00040 
00041 namespace hash_db {
00042 
00043 /// \ingroup datahash_top
00044 /*@{*/
00045 
00046 ////////////////////////////////////////////////////////////////////////////////
00047 ///
00048 /// \defgroup hash_db Simple Hash Database API
00049 ///
00050 /// Quick API for atomically storing and retrieving collections of objects.
00051 ///
00052 /// This is NOT scalable!  Do not use for storage of lots of objects, or high
00053 /// performance, etc.  This is a quick-and-dirty implementation for atomic
00054 /// storage of a small number of small objects.
00055 ///
00056 /// Similar to BerkelyDB model: you can get and put objects based on a client-
00057 /// defined ID.
00058 ///
00059 ////////////////////////////////////////////////////////////////////////////////
00060 /*@{*/
00061 
00062 
00063 ////////////////////////////////////////////////////////////////////////////////
00064 ///
00065 ///     hash_db::Database
00066 ///
00067 ///     This is the object to use.  Uses advisory locking under the covers, so
00068 ///     only 1 process can access at a time.
00069 ///
00070 ////////////////////////////////////////////////////////////////////////////////
00071 
00072 class Database {
00073 public:
00074         // virtual destructor --------------------------------------------------
00075         virtual ~Database(void) throw();
00076 
00077         // hash_db::Database class interface methods ---------------------------
00078 
00079         /// get IDs for all objects in database
00080         virtual void getIds(OUT SetString& ids) = 0;
00081 
00082         /// add the given object (hash) to the database with the given ID
00083         virtual bool addObject(IN const char * id,
00084                                 IN smart_ptr<Datahash> obj) = 0;
00085 
00086         /// retrieve the object with the specified ID
00087         virtual smart_ptr<Datahash> getObject(IN const char * id) = 0;
00088 
00089         /// delete the object with the specified ID
00090         virtual bool deleteObject(IN const char * id) = 0;
00091 
00092         /// commit all outstanding changes
00093         virtual bool commit(void) = 0;
00094 
00095         // public static methods (factories) -----------------------------------
00096 
00097         /// create Database object from specified file
00098         static smart_ptr<Database> create(IN const char * db_file);
00099 };
00100 
00101 
00102 
00103 };      // hash_db namespace
00104 
00105 #endif  // WAVEPACKET_HASH_DB__H__
00106