headers.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 
00038 #if !defined( _OESS_1__DB__STORAGE__IMPL__HEADERS_HPP_ )
00039 #define _OESS_1__DB__STORAGE__IMPL__HEADERS_HPP_
00040 
00041 #include <set>
00042 #include <vector>
00043 
00044 #include <cpp_util_2/h/nocopy.hpp>
00045 
00046 #include <smart_ref_3/h/smart_ref.hpp>
00047 
00048 #include <oess_1/db/storage/h/page_index_calculator.hpp>
00049 
00050 #include <oess_1/db/storage/impl/h/segment_header_item.hpp>
00051 
00052 namespace oess_1 {
00053 
00054 namespace db {
00055 
00056 namespace storage {
00057 
00058 namespace impl {
00059 
00060 //
00061 // common_header_t
00062 //
00063 
00075 class common_header_t
00076   {
00077   public :
00079     common_header_t(
00081       const page_index_calculator_t & calculator );
00082 
00085 
00089     area_ordinal_t
00090     get_free_area() const;
00091 
00094 
00097     void
00098     remove_free_area(
00099       const area_ordinal_t & area );
00100 
00103 
00106     void
00107     return_free_area(
00108       const area_ordinal_t & area );
00109 
00111 
00114     void
00115     init_new();
00116 
00118 
00121     oess_1::io::ibinstream_t &
00122     read_from(
00123       oess_1::io::ibinstream_t & from );
00124 
00126 
00129     oess_1::io::obinstream_t &
00130     write_to(
00131       oess_1::io::obinstream_t & to ) const;
00132 
00134     bool
00135     is_changed() const;
00136 
00138     void
00139     force_not_changed();
00140 
00142 
00145     bool
00146     has_free_areas() const;
00147 
00148   private :
00150     page_index_calculator_t m_calculator;
00151 
00153     typedef std::set< area_ordinal_t > area_ordinal_set_t;
00154 
00156     area_ordinal_set_t  m_free_areas;
00157 
00159     bool  m_is_changed;
00160 
00162 
00168     area_ordinal_t  m_first_free_area;
00169   };
00170 
00172 inline oess_1::io::obinstream_t &
00173 operator<<(
00174   oess_1::io::obinstream_t & to,
00175   const common_header_t & what )
00176   {
00177     return what.write_to( to );
00178   }
00179 
00181 inline oess_1::io::ibinstream_t &
00182 operator>>(
00183   oess_1::io::ibinstream_t & from,
00184   common_header_t & what )
00185   {
00186     return what.read_from( from );
00187   }
00188 
00189 //
00190 // ref_common_header_t
00191 //
00192 
00193 SMART_REF_3_DECL_REF( common_header_t, class )
00194 
00195 //
00196 // area_header_t
00197 //
00198 
00199 
00210 class area_header_t
00211   {
00212   public :
00230     class io_buffer_t
00231       : private cpp_util_2::nocopy_t
00232       {
00233         public :
00235           io_buffer_t(
00236             const page_index_calculator_t & calculator );
00237           ~io_buffer_t();
00238 
00240           inline segment_ordinal_t
00241           size() const
00242             {
00243               return m_buffer.size();
00244             }
00245 
00247           inline segment_ordinal_t *
00248           get()
00249             {
00250               return &m_buffer[ 0 ];
00251             }
00252 
00253         private :
00255           std::vector< segment_ordinal_t >  m_buffer;
00256       };
00258     area_header_t(
00260       const page_index_calculator_t & calculator,
00262       const area_ordinal_t & ordinal );
00263 
00265     const area_ordinal_t &
00266     area_ordinal() const;
00267 
00270 
00274     segment_ordinal_t
00275     get_free_segment() const;
00276 
00279 
00282     void
00283     remove_free_segment(
00284       const segment_ordinal_t & segment );
00285 
00288 
00291     void
00292     return_free_segment(
00293       const segment_ordinal_t & segment );
00294 
00296 
00299     void
00300     init_new();
00301 
00303 
00306     oess_1::io::ibinstream_t &
00307     read_from(
00308       oess_1::io::ibinstream_t & from,
00309       io_buffer_t & io_buffer );
00310 
00312 
00315     oess_1::io::obinstream_t &
00316     write_to(
00317       oess_1::io::obinstream_t & to,
00318       io_buffer_t & io_buffer ) const;
00319 
00321     bool
00322     is_changed() const;
00323 
00325     void
00326     force_not_changed();
00327 
00329 
00332     bool
00333     has_free_segments() const;
00334 
00335   private :
00337     page_index_calculator_t m_calculator;
00338 
00340     area_ordinal_t m_area_ordinal;
00341 
00343     typedef std::set< segment_ordinal_t > segment_ordinal_set_t;
00344 
00346     segment_ordinal_set_t m_free_segments;
00347 
00349     bool  m_is_changed;
00350 
00352 
00358     segment_ordinal_t m_first_free_segment;
00359   };
00360 
00361 //
00362 // ref_area_header_t
00363 //
00364 
00365 SMART_REF_3_DECL_REF( area_header_t, class )
00366 
00367 //
00368 // segment_header_t
00369 //
00370 
00371 
00382 class segment_header_t
00383   {
00384   public :
00385 
00403     class io_buffer_t
00404       : private cpp_util_2::nocopy_t
00405       {
00406         public :
00408           io_buffer_t(
00409             const page_index_calculator_t & calculator );
00410           ~io_buffer_t();
00411 
00413           inline oess_1::uint_t
00414           size() const
00415             {
00416               return m_buffer.size();
00417             }
00418 
00420           inline oess_1::uint_t *
00421           get()
00422             {
00423               return &m_buffer[ 0 ];
00424             }
00425 
00426         private :
00428           std::vector< oess_1::uint_t > m_buffer;
00429       };
00430 
00432     segment_header_t(
00434       const page_index_calculator_t & calculator,
00436       const area_ordinal_t & area_ordinal,
00438       const segment_ordinal_t & ordinal );
00439 
00441     const area_ordinal_t &
00442     area_ordinal() const;
00443 
00445     const segment_ordinal_t &
00446     segment_ordinal() const;
00447 
00449 
00452     chain_id_t
00453     allocate_block();
00454 
00456 
00459     void
00460     deallocate_block(
00461       const chain_id_t & block_id );
00462 
00464 
00468     chain_id_t
00469     next(
00470       const chain_id_t & block_id ) const;
00471 
00473 
00479     void
00480     change_next(
00482       const chain_id_t & block_id,
00484       const chain_id_t & next );
00485 
00491     void
00492     ensure_allocated(
00494       const chain_id_t & block_id ) const;
00495 
00497 
00500     void
00501     init_new();
00502 
00504 
00507     oess_1::io::ibinstream_t &
00508     read_from(
00509       oess_1::io::ibinstream_t & from,
00510       io_buffer_t & io_buffer );
00511 
00513 
00516     oess_1::io::obinstream_t &
00517     write_to(
00518       oess_1::io::obinstream_t & to,
00519       io_buffer_t & io_buffer ) const;
00520 
00522     bool
00523     is_changed() const;
00524 
00526     void
00527     force_not_changed();
00528 
00530 
00533     bool
00534     has_free_blocks() const;
00535 
00536   private :
00538     page_index_calculator_t m_calculator;
00539 
00541     area_ordinal_t m_area_ordinal;
00542 
00544     segment_ordinal_t m_segment_ordinal;
00545 
00547     bool  m_is_changed;
00548 
00550     unsigned int m_total_block_count;
00551 
00553 
00557     unsigned int m_useful_block_count;
00558 
00560 
00564     chain_id_t  m_first_chain_id;
00565 
00567     chain_id_t  m_last_chain_id;
00568 
00570 
00573     chain_id_t  m_first_free_id;
00574 
00576     unsigned int  m_free_count;
00577 
00579 
00586     typedef std::pair< bool, chain_id_t > block_info_t;
00587 
00589 
00592     std::vector< block_info_t > m_items;
00593 
00595     unsigned int
00596     item_index( const chain_id_t & id ) const;
00597   };
00598 
00599 //
00600 // ref_segment_header_t
00601 //
00602 
00603 SMART_REF_3_DECL_REF( segment_header_t, class )
00604 
00605 } /* namespace impl */
00606 
00607 } /* namespace storage */
00608 
00609 } /* namespace db */
00610 
00611 } /* namespace oess_1 */
00612 
00613 #endif
00614 

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