SAGA Adaptor CPI v.1.0
serialization.hpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2009 Hartmut Kaiser
00002 // 
00003 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
00004 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00005 
00006 #ifndef SAGA_SAGA_ADAPTORS_SERIALIZATION_HPP
00007 #define SAGA_SAGA_ADAPTORS_SERIALIZATION_HPP
00008 
00009 #include <boost/plugin.hpp>
00010 #include <boost/plugin/export_plugin.hpp>
00011 
00012 #include <saga/saga/util.hpp>
00013 #include <saga/saga/object.hpp>
00014 
00016 #ifndef SAGA_PACKAGE_NAME
00017 # ifndef SAGA_ENGINE
00018 #   define SAGA_PACKAGE_NAME engine   // needed for get_name()
00019 # endif
00020 #endif
00021 
00023 #ifndef SAGA_PACKAGE_LIB_NAME
00024 // the serialization functions are defined in the cpi part of the package
00025 #define SAGA_PACKAGE_LIB_NAME SAGA_MANGLE_PACKAGE_NAME(SAGA_PACKAGE_NAME)
00026 #endif
00027 
00029 namespace saga { namespace adaptors
00030 {
00031     // serialize a saga::object into a string representation
00032     SAGA_EXPORT std::string serialize(saga::object obj);
00033     
00034     // create a saga::object from a given string representation
00035     SAGA_EXPORT saga::object deserialize(std::string const& data);
00036     SAGA_EXPORT saga::object deserialize(saga::session s, std::string const& data);
00037     
00038     // base class for all the package serialization functionality
00039     struct serialization
00040     {
00041         virtual ~serialization() {}
00042         virtual std::string serialize(TR1::shared_ptr<saga::impl::object>) = 0;
00043         virtual TR1::shared_ptr<saga::impl::object> deserialize(
00044             saga::session s, saga::object::type type, 
00045             std::string const& data) = 0;
00046     };
00047     
00049 }}  // namespace saga::adaptors
00050 
00052 namespace saga { namespace impl 
00053 {
00054     // serialization support for the engine
00055     class engine_serialization
00056     :   public saga::adaptors::serialization
00057     {
00058     public:
00059         ~engine_serialization();
00060         std::string serialize(TR1::shared_ptr<saga::impl::object>);
00061         TR1::shared_ptr<saga::impl::object> deserialize(
00062             saga::session s, saga::object::type type, std::string const& data);
00063     };
00064 
00066 }}    // namespace saga::impl
00067 
00069 //  Forward the SAGA_PACKAGE_REGISTER macro to the correct BOOST_PLUGIN macro 
00070 //  sequence
00071 #define SAGA_PACKAGE_REGISTER(ActualType)                                     \
00072         BOOST_PLUGIN_EXPORT_LIST (SAGA_PACKAGE_LIB_NAME)                      \
00073         BOOST_PLUGIN_EXPORT      (SAGA_PACKAGE_LIB_NAME,                      \
00074         saga::adaptors::serialization, ActualType, "serialization")           \
00075     
00076 
00077 #endif // !SAGA_SAGA_ADAPTORS_SERIALIZATION_HPP
00078 
00079 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines