std_cache.hpp

См. документацию.
00001 /*
00002 
00003 Copyright (c) 2002-2005, Yauheni Akhotnikau
00004 All rights reserved.
00005 
00006 Redistribution and use in source and binary forms, with or without
00007 modification, are permitted provided that the following conditions are met:
00008 
00009 - Redistributions of source code must retain the above copyright notice, this
00010 list of conditions and the following disclaimer.
00011 
00012 - Redistributions in binary form must reproduce the above copyright notice, this
00013 list of conditions and the following disclaimer in the documentation and/or
00014 other materials provided with the distribution.
00015 
00016 - The name of the author may not be used to endorse or promote products derived
00017 from this software without specific prior written permission.
00018 
00019 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00020 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00021 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00022 EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00024 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00027 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00028 OF SUCH DAMAGE.
00029 
00030 */
00031 
00037 #if !defined( _OESS_1__DB__STORAGE__IMPL__STD_CACHE_HPP_ )
00038 #define _OESS_1__DB__STORAGE__IMPL__STD_CACHE_HPP_
00039 
00040 #include <map>
00041 
00042 #include <oess_1/db/storage/impl/h/cache.hpp>
00043 
00044 namespace oess_1 {
00045 
00046 namespace db {
00047 
00048 namespace storage {
00049 
00050 namespace impl {
00051 
00056 class std_cache_t
00057   : public  cache_t
00058   {
00059   public :
00060     std_cache_t();
00061     virtual ~std_cache_t();
00062 
00065     virtual void
00066     reinit(
00067       oess_1::uint_t cache_size,
00068       oess_1::uint_t page_size );
00069 
00070     virtual void
00071     cleanup();
00072 
00073     virtual const oess_1::char_t *
00074     read_access(
00075       oess_1::uint_t ordinal );
00076 
00077     virtual oess_1::char_t *
00078     write_access(
00079       oess_1::uint_t ordinal );
00080 
00081     virtual oess_1::char_t *
00082     push(
00083       const ref_loaded_page_t & page,
00084       dirty_page_storage_t & storage,
00085       bool is_read_only_access );
00086 
00087     virtual void
00088     copy_all_dirties(
00089       dirty_page_storage_t & storage );
00090 
00091     virtual void
00092     clear_all_dirties();
00093 
00094     virtual void
00095     throw_away_all_dirties();
00097 
00101     struct  page_t
00102       {
00104         ref_loaded_page_t m_page;
00105 
00107         unsigned long m_last_access_time;
00108 
00110         bool  m_is_dirty;
00111 
00113         page_t()
00114           : m_last_access_time( 0 )
00115           , m_is_dirty( false )
00116           {}
00117 
00119         page_t(
00122           const ref_loaded_page_t & page,
00124           unsigned long last_access_time )
00125           : m_page( page )
00126           , m_last_access_time( last_access_time )
00127           , m_is_dirty( true )
00128           {
00129             if( m_page->has_previous() )
00130               m_is_dirty = false;
00131           }
00132 
00134         const ref_loaded_page_t &
00135         page() const
00136           {
00137             return m_page;
00138           }
00139 
00142         oess_1::char_t *
00143         current(
00144           unsigned long last_access_time )
00145           {
00146             m_last_access_time = last_access_time;
00147             return m_page->current();
00148           }
00149 
00152         const oess_1::char_t *
00153         current() const
00154           {
00155             return m_page->current();
00156           }
00157 
00159         unsigned long
00160         last_access_time() const
00161           {
00162             return m_last_access_time;
00163           }
00164 
00166         bool
00167         is_dirty() const
00168           {
00169             return m_is_dirty;
00170           }
00171 
00173         void
00174         make_dirty()
00175           {
00176             m_is_dirty = true;
00177           }
00178 
00180 
00184         void
00185         make_clear()
00186           {
00187             m_is_dirty = false;
00188             m_page->change_previous_by_current();
00189           }
00190       };
00191 
00193     typedef std::map< oess_1::uint_t, page_t >  page_map_t;
00194 
00195   private :
00197     oess_1::uint_t  m_max_size;
00199     oess_1::uint_t  m_page_size;
00200 
00202     unsigned int  m_timer;
00203 
00205     page_map_t  m_pages;
00206 
00210     oess_1::uint_t  m_last_accessed_page_index;
00212     page_t *  m_last_accessed_page;
00214 
00217     void
00218     push_out_some_page(
00220       dirty_page_storage_t & storage );
00221   };
00222 
00223 } /* namespace impl */
00224 
00225 } /* namespace storage */
00226 
00227 } /* namespace db */
00228 
00229 } /* namespace oess_1 */
00230 
00231 #endif
00232 

Документация по ObjESSty. Последние изменения: Fri Oct 13 18:35:35 2006. Создано системой  doxygen 1.4.7
Hosted by uCoz