chain_storage.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__CHAIN_STORAGE_HPP_ )
00039 #define _OESS_1__DB__STORAGE__CHAIN_STORAGE_HPP_
00040 
00041 #include <memory>
00042 
00043 #include <cpp_util_2/h/nocopy.hpp>
00044 
00045 #include <oess_1/defs/h/types.hpp>
00046 
00047 #include <oess_1/io/h/stream.hpp>
00048 #include <oess_1/io/h/mem_buf.hpp>
00049 
00050 #include <oess_1/stdsn/h/ent_std.hpp>
00051 
00052 #include <oess_1/db/h/declspec.hpp>
00053 
00054 #include <oess_1/db/storage/h/chain_id.hpp>
00055 #include <oess_1/db/storage/h/config.hpp>
00056 
00057 namespace oess_1 {
00058 
00059 namespace db {
00060 
00061 namespace storage {
00062 
00063 //
00064 // no_chain_length_limit
00065 //
00066 
00075 const oess_1::uint_t no_chain_length_limit =
00076     static_cast< oess_1::uint_t >( -1 );
00077 
00078 //
00079 // chain_storage_t
00080 //
00081 
00092 class OESS_1__DB__TYPE  chain_storage_t
00093   : private cpp_util_2::nocopy_t
00094   {
00095   public :
00096     virtual ~chain_storage_t();
00097 
00101 
00105     virtual void
00106     trx_start() = 0;
00107 
00109 
00112     virtual void
00113     trx_commit() = 0;
00114 
00116 
00119     virtual void
00120     trx_rollback() = 0;
00122 
00126 
00129     virtual chain_id_t
00130     chain_create(
00132       oess_1::io::istream_t & from,
00134       oess_1::uint_t length ) = 0;
00135 
00137     virtual void
00138     chain_destroy(
00140       const chain_id_t & chain ) = 0;
00141 
00143 
00148     virtual void
00149     chain_load(
00151       const chain_id_t & chain,
00153       oess_1::io::ostream_t & to,
00155       oess_1::uint_t max_length ) = 0;
00156 
00158 
00162     virtual void
00163     chain_update(
00165       const chain_id_t & chain,
00167       oess_1::io::istream_t & from,
00169       oess_1::uint_t length ) = 0;
00171   };
00172 
00175 
00176 //
00177 // create_chain_storage
00178 //
00179 
00195 OESS_1__DB__FUNC(std::auto_ptr< chain_storage_t >)
00196 create_chain_storage(
00198   const std::string & physic_name,
00200   const config_t & config,
00202   oess_1::io::istream_t & from,
00205   oess_1::uint_t length,
00207   chain_id_t & first_chain );
00208 
00209 //
00210 // open_chain_storage
00211 //
00212 
00233 OESS_1__DB__FUNC(std::auto_ptr< chain_storage_t >)
00234 open_chain_storage(
00236   const std::string & physic_name,
00238   const config_t & config,
00240   bool is_read_only,
00242   bool is_auto_repair_enabled,
00244   oess_1::io::ostream_t & to,
00247   oess_1::uint_t length,
00249   chain_id_t & first_chain );
00250 
00251 //
00252 // is_chain_storage_exists
00253 //
00254 
00263 OESS_1__DB__FUNC(bool)
00264 is_chain_storage_exists(
00266   const std::string & physic_name );
00267 
00268 //
00269 // destroy_chain_storage
00270 //
00271 
00279 OESS_1__DB__FUNC(void)
00280 destroy_chain_storage(
00282   const std::string & physic_name );
00283 
00285 
00290 
00291 template< class T >
00292 chain_id_t
00293 create_in_storage(
00294   chain_storage_t & storage, const T & what )
00295   {
00296     oess_1::io::mem_buf_t stream;
00297     oess_1::stdsn::oent_std_t oent( stream );
00298     oent << what;
00299     stream.set_pos( 0 );
00300 
00301     return storage.chain_create( stream, stream.size() );
00302   }
00303 
00305 template< class T >
00306 void
00307 load_from_storage(
00308   chain_storage_t & storage,
00309   const chain_id_t & chain,
00310   T & what,
00311   oess_1::uint_t length = no_chain_length_limit )
00312   {
00313     oess_1::io::mem_buf_t stream;
00314     storage.chain_load( chain, stream, length );
00315 
00316     stream.set_pos( 0 );
00317     oess_1::stdsn::ient_std_t ient( stream );
00318     ient >> what;
00319   }
00320 
00322 template< class T >
00323 void
00324 update_in_storage(
00325   chain_storage_t & storage,
00326   const chain_id_t & chain,
00327   const T & what )
00328   {
00329     oess_1::io::mem_buf_t stream;
00330     oess_1::stdsn::oent_std_t oent( stream );
00331     oent << what;
00332     stream.set_pos( 0 );
00333 
00334     return storage.chain_update( chain, stream, stream.size() );
00335   }
00336 
00339 } /* namespace storage */
00340 
00341 } /* namespace db */
00342 
00343 } /* namespace oess_1 */
00344 
00345 #endif
00346 

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