include/EDoc/PersistenceIFace.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003    Copyright (C) 2007 by Brendon Costa
00004 
00005    This library is free software; you can redistribute it and/or modify 
00006    it under the terms of the "LGPL Like" License defined in the file COPYING 
00007    that should have been distributed along with this source.
00008 
00009    This library is distributed in the hope that it will be useful, 
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of 
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013    You should have received a copy of the "LGPL Like" License 
00014    along with this library; see the file COPYING. if not, it can be 
00015    obtained from the EDoc++ website: 
00016    http://edoc.sourceforge.net/license.html
00017 
00018 *******************************************************************************/
00019 #ifndef EDOC_PERSISTENCEIFACE_H
00020 #define EDOC_PERSISTENCEIFACE_H
00021 
00022 #include "EDoc/stdint.h"
00023 #include <string>
00024 
00025 namespace EDoc
00026 {
00027    //===========================================================================
00028    /** \brief Defines an interface for reading/writing various types of
00029     * primitive data.
00030     *
00031     * This interface defines primitives for reading/writing certain integer and
00032     * string types to/from files. Each primitive has an associated key which
00033     * it is necessary for the user to provide but may not necessarily be used by
00034     * the underlying implementation. For example the text implementation of this
00035     * interface will validate the key and the data type are correct, whereas the
00036     * binary interface will just assume that the data it is reading is correct.
00037     */
00038    class PersistenceIFace
00039    {
00040    public:
00041 
00042       //------------------------------------------------------------------------
00043       /** \brief Constructor.
00044        */
00045       PersistenceIFace() :
00046          ref_count(0)
00047       {}
00048 
00049       //------------------------------------------------------------------------
00050       /** \brief Destructor.
00051        */
00052       virtual ~PersistenceIFace() {}
00053 
00054 
00055       //------------------------------------------------------------------------
00056       /** \brief Open the file associated with this instance preparing it for
00057        * reading or writing.
00058        */
00059       virtual void Open() = 0;
00060 
00061       //------------------------------------------------------------------------
00062       /** \brief Close the file associated with this instance. 
00063        */
00064       virtual void Close() = 0;
00065 
00066       //------------------------------------------------------------------------
00067       /** \brief Read a string primitive. 
00068        */
00069       virtual std::string ReadString(const char* key) = 0;
00070 
00071       //------------------------------------------------------------------------
00072       /** \brief Read a boolean primitive. 
00073        */
00074       virtual bool ReadBoolean(const char* key) = 0;
00075 
00076       //------------------------------------------------------------------------
00077       /** \brief Read a uint8_t primitive. 
00078        */
00079       virtual uint8_t ReadUInt8(const char* key) = 0;
00080 
00081       //------------------------------------------------------------------------
00082       /** \brief Read a int32_t primitive. 
00083        */
00084       virtual int32_t ReadInt32(const char* key) = 0;
00085 
00086       //------------------------------------------------------------------------
00087       /** \brief Read a uint32_t primitive. 
00088        */
00089       virtual uint32_t ReadUInt32(const char* key) = 0;
00090 
00091       //------------------------------------------------------------------------
00092       /** \brief Read a record type primitive. 
00093        */
00094       virtual uint8_t ReadRecordType() = 0;
00095 
00096 
00097 
00098       //------------------------------------------------------------------------
00099       /** \brief Write a string primitive. 
00100        */
00101       virtual void WriteString(const char* key, std::string value) = 0;
00102 
00103       //------------------------------------------------------------------------
00104       /** \brief Write a boolean primitive. 
00105        */
00106       virtual void WriteBoolean(const char* key, bool value) = 0;
00107 
00108       //------------------------------------------------------------------------
00109       /** \brief Write a uint8_t primitive. 
00110        */
00111       virtual void WriteUInt8(const char* key, uint8_t value) = 0;
00112 
00113       //------------------------------------------------------------------------
00114       /** \brief Write a int32_t primitive. 
00115        */
00116       virtual void WriteInt32(const char* key, int32_t value) = 0;
00117 
00118       //------------------------------------------------------------------------
00119       /** \brief Write a uint32_t primitive. 
00120        */
00121       virtual void WriteUInt32(const char* key, uint32_t value) = 0;
00122 
00123       //------------------------------------------------------------------------
00124       /** \brief Write a uint32_t primitive with additional debug string.
00125        *
00126        * The debug string is a small string that can be written to text files
00127        * to help the user understand what the uint32_t value might represent or
00128        * be an index for. This is entirely for debugging purposes and is not
00129        * accessible with the associated read interface.
00130        */
00131       virtual void WriteUInt32Debug(const char* key, uint32_t value, 
00132          std::string debug_text) = 0;
00133 
00134       //------------------------------------------------------------------------
00135       /** \brief Write a int32_t primitive with additional debug string.
00136        *
00137        * The debug string is a small string that can be written to text files
00138        * to help the user understand what the uint32_t value might represent or
00139        * be an index for. This is entirely for debugging purposes and is not
00140        * accessible with the associated read interface.
00141        */
00142       virtual void WriteInt32Debug(const char* key, int32_t value, 
00143          std::string debug_text) = 0;
00144 
00145       //------------------------------------------------------------------------
00146       /** \brief Writes a primitive to the file indicating the type of record
00147        * data that follows.
00148        */
00149       virtual void WriteRecordType(uint8_t value) = 0;
00150 
00151 
00152       //------------------------------------------------------------------------
00153       // Data used by Persistence class.
00154       //------------------------------------------------------------------------
00155       /** \brief Is a integer that can be used for reference counting.
00156        *
00157        * The Persistence class shares instances of PersistenceIFace
00158        * implementations. To enable this we use a small "hacked" shared pointer
00159        * which will allow this class to be reference counted.
00160        */
00161       int ref_count;
00162 
00163       //------------------------------------------------------------------------
00164    };
00165    //===========================================================================
00166 
00167 }
00168 
00169 
00170 #endif // EDOC_PERSISTENCEIFACE_H

Generated on Tue Jan 20 18:26:07 2009 for EDoc-0.2.1 by  doxygen 1.5.1