/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2020 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTH_EARTH_PLUGIN_SERIALIZER_H
#define OSGEARTH_EARTH_PLUGIN_SERIALIZER_H 1

#include <osgEarth/Config>
#include <osgEarth/MapNode>

namespace osgEarth_osgearth
{
    using namespace osgEarth;

    class EarthFileSerializer1
    {
    public:
        MapNode* deserialize( const Config& conf, const std::string& referrer ) const;
    };

    class EarthFileSerializer2
    {
    public:
        EarthFileSerializer2();

        /**
         * Relative pathnames in the earth file are relative to the earth file itself.
         * When storing a MapNode, the serializer will rewrite those relative paths
         * so they are relative to the new save location.
         *
         * Set this to false to disable this feature.
         */
        void setRewritePaths(bool value) { _rewritePaths = value; }

        /**
         * By default, when rewriting paths (see above), absolute paths in the earth
         * file will be skipped (not rewritten). Set this to true to tell the 
         * serializer to attempt to re-write absolute paths and make then relative
         * to the new save location.
         */
        void setRewriteAbsolutePaths(bool value) { _rewriteAbsolutePaths = value; }

    public:
        /**
         * Parse data in a Config structure into a new MapNode.
         * referrer = the location from which the Config was created; typically this
         * is the pathname of the .earth file.
         */
        osg::ref_ptr<osg::Node> deserialize( 
            const Config& conf, 
            const std::string& referrer,
            const osgDB::Options* readOptions) const;
        
        /**
         * Create a Config structure representing a MapNode.
         * referrer = the location to which the Config will be stored, typically this
         * is the pathname of the .earth file.
         */
        Config serialize( 
            const MapNode* mapNode, 
            const std::string& referrer ) const;

    private:

        bool _rewritePaths;
        bool _rewriteAbsolutePaths;
    };

} // namespace osgEarth_osgearth

#endif // OSGEARTH_EARTH_PLUGIN_SERIALIZER_H
