serializable.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__STDSN__SERIALIZABLE_HPP_ )
00038 #define _OESS_1__STDSN__SERIALIZABLE_HPP_
00039 
00040 #include <list>
00041 
00042 #include <cpp_util_2/h/nocopy.hpp>
00043 
00044 #include <auto_ptr_3/h/obj_ptr.hpp>
00045 
00046 #include <oess_1/stdsn/h/declspec.hpp>
00047 
00048 #include <oess_1/stdsn/h/ent.hpp>
00049 #include <oess_1/stdsn/h/macro.hpp>
00050 
00051 namespace oess_1 {
00052 
00053 namespace stdsn {
00054 
00055 //
00056 // unknown_extension_t
00057 //
00058 
00065 class OESS_1__STDSN__TYPE unknown_extension_t
00066   {
00067     private :
00069       std::string m_data;
00070 
00071     public :
00073       unknown_extension_t();
00075       explicit unknown_extension_t(
00076         const std::string & data );
00077 
00079       const std::string &
00080       get() const;
00081 
00083 
00087       void
00088       clear();
00089   };
00090 
00091 //
00092 // all_unknown_extension_t
00093 //
00094 
00095 struct  all_unknown_extensions_data_t;
00096 
00109 class OESS_1__STDSN__TYPE all_unknown_extensions_t
00110   {
00111     public :
00113       all_unknown_extensions_t();
00115       all_unknown_extensions_t(
00116         const all_unknown_extensions_t & o );
00117       ~all_unknown_extensions_t();
00118 
00120       all_unknown_extensions_t &
00121       operator=(
00122         const all_unknown_extensions_t & o );
00123 
00125 
00129       const unknown_extension_t &
00130       get( const std::string & type_name ) const;
00131 
00133 
00136       unknown_extension_t &
00137       get( const std::string & type_name );
00138 
00140       void
00141       drop();
00142 
00143     private :
00145       auto_ptr_3::obj_ptr_t< all_unknown_extensions_data_t >  m_data;
00146   };
00147 
00148 //
00149 // subclass_extension_path_t
00150 //
00151 
00167 class OESS_1__STDSN__TYPE
00168 subclass_extension_path_t
00169   {
00170     public :
00175       struct OESS_1__STDSN__TYPE
00176       item_t
00177         {
00179           std::string m_type_name;
00181           std::string m_scheme;
00182 
00184           item_t();
00186           item_t(
00187             const std::string & type_name,
00188             const std::string & scheme );
00190           item_t(
00191             const item_t & o );
00192 
00194           item_t &
00195           operator=( const item_t & o );
00196         };
00197 
00199       typedef std::list< item_t > list_t;
00201       typedef list_t::const_iterator  const_iterator;
00202 
00204       subclass_extension_path_t();
00206       subclass_extension_path_t(
00207         const subclass_extension_path_t & o );
00208       ~subclass_extension_path_t();
00209 
00211       subclass_extension_path_t &
00212       operator=(
00213         const subclass_extension_path_t & o );
00214 
00216       void
00217       push_back(
00219         const std::string & type_name,
00221         const std::string & type_scheme );
00222 
00224       oess_1::uint_t
00225       size() const;
00226 
00228       const_iterator
00229       begin() const;
00230 
00232 
00236       const_iterator
00237       end() const;
00238 
00244       bool
00245       operator==( const subclass_extension_path_t & o ) const;
00246 
00247     private :
00249       list_t  m_list;
00250   };
00251 
00252 //
00253 // serializable_t
00254 //
00255 
00260 class OESS_1__STDSN__TYPE serializable_t
00261   {
00262     // То, что скрывается за макросом OESS_SERIALIZER
00263     // в базовом классе должно быть реализовано явно.
00264     public :
00275       class OESS_1__STDSN__TYPE oess_serializer_t
00276         {
00277           public :
00278             static const std::string &  type_name();
00285             static oess_1::stdsn::serializable_t *  factory();
00286             static const std::string &  scheme();
00287         };
00288       friend class  oess_serializer_t;
00289 
00290     public :
00295       serializable_t();
00302       serializable_t(
00303         const serializable_t & o );
00304       virtual ~serializable_t();
00305 
00312       serializable_t &
00313       operator=( const serializable_t & o );
00314 
00316       virtual void
00317       oess_pack( oent_t & writter ) const = 0;
00318 
00320       virtual void
00321       oess_unpack( ient_t & reader ) = 0;
00322 
00324 
00327       virtual void *
00328       oess_cast( const std::string & type_name ) = 0;
00329 
00331       virtual const std::string &
00332       oess_type_name() const = 0;
00333 
00335 
00336       virtual const std::string &
00337       oess_scheme() const = 0;
00338 
00348       virtual void
00349       oess_get_subclass_extension_path(
00350         oess_1::stdsn::subclass_extension_path_t & path,
00351         const std::string & terminator ) const = 0;
00352 
00354 
00357       static std::string &
00358       oess_serializable_t_name();
00359 
00360     protected :
00363 
00367       virtual void
00368       oess_pre_pack() const;
00369 
00372 
00378       virtual void
00379       oess_post_pack() const;
00380 
00383 
00394       virtual void
00395       oess_pre_unpack();
00396 
00399 
00403       virtual void
00404       oess_post_unpack();
00405 
00408       public :
00424         void
00425         oess_store_unknown_subclass_extension_path(
00426           const subclass_extension_path_t & path );
00427 
00444         const subclass_extension_path_t *
00445         oess_unknown_subclass_extension_path() const;
00446 
00462         void
00463         oess_drop_unknown_extensions();
00464 
00465       protected :
00474         const unknown_extension_t &
00475         oess_unknown_subclass_extension() const;
00476 
00485         unknown_extension_t &
00486         oess_writeable_unknown_subclass_extension();
00487 
00494         const unknown_extension_t &
00495         oess_lo_unknown_extension(
00496           const std::string & type_name ) const;
00497 
00505         unknown_extension_t &
00506         oess_lo_writeable_unknown_extension(
00507           const std::string & type_name );
00508 
00509       private :
00521         auto_ptr_3::obj_ptr_t<
00522             subclass_extension_path_t >
00523           m_oess_unknown_subclass_extension_path;
00524 
00530         unknown_extension_t m_oess_unknown_subclass_extension;
00536         all_unknown_extensions_t  m_oess_unknown_extensions;
00538   };
00539 
00540 OESS_1__STDSN__FUNC( oent_t & )
00541 operator<<( oent_t & writter, const serializable_t & o );
00542 
00543 OESS_1__STDSN__FUNC( ient_t & )
00544 operator>>( ient_t & reader, serializable_t & o );
00545 
00546 //
00547 // pfn_factory
00548 //
00549 typedef serializable_t * (*pfn_factory_t)();
00550 
00551 //
00552 // factory_registrator_t
00553 //
00554 
00571 class OESS_1__STDSN__TYPE factory_registrator_t {
00572   public :
00573     factory_registrator_t(
00574       const char * type_name,
00575       pfn_factory_t factory );
00576     ~factory_registrator_t();
00577 
00578   private :
00579     std::string m_type_name;
00580     pfn_factory_t m_factory;
00581 };
00582 
00583 //
00584 // obj_factory_t
00585 //
00586 
00592 class OESS_1__STDSN__TYPE obj_factory_t {
00593   public :
00599     enum no_factory_action_t
00600     {
00602       throw_exception,
00605       no_throw_exception
00606     };
00607 
00608     static void
00609     reg(
00610       const std::string & type_name,
00611       pfn_factory_t factory );
00612 
00613     static void
00614     dereg(
00615       const std::string & type_name,
00616       pfn_factory_t factory );
00617 
00634     static serializable_t *
00635     create(
00637       const std::string & type_to_create,
00640       const std::string & type_to_cast,
00642       const no_factory_action_t & no_factory_action =
00643         throw_exception );
00644 };
00645 
00646 } /* namespace stdsn */
00647 
00648 } /* namespace oess_1 */
00649 
00650 #endif
00651 

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