/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2008-2013 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 OSGEARTHFEATURES_FEATURE_H
#define OSGEARTHFEATURES_FEATURE_H 1

#include <osgEarthFeatures/Common>
#include <osgEarthFeatures/FilterContext>
#include <osgEarthSymbology/Geometry>
#include <osgEarthSymbology/Style>
#include <osgEarth/GeoCommon>
#include <osgEarth/SpatialReference>
#include <osg/Array>
#include <osg/Shape>
#include <map>
#include <list>

namespace osgEarth { namespace Features
{
    using namespace osgEarth;
    using namespace osgEarth::Symbology;
    class FilterContext;

    /**
     * Metadata and schema information for feature data.
     */
    class OSGEARTHFEATURES_EXPORT FeatureProfile : public osg::Referenced
    {
    public:        
        FeatureProfile( const GeoExtent& extent );

        virtual ~FeatureProfile() { }

        /** Gets the spatial extents of the features in this profile. */
        const GeoExtent& getExtent() const {
            return _extent; }

        /** Gets the spatial reference system of feature shapes in this class. */
        const SpatialReference* getSRS() const {
            return _extent.getSRS(); }

        bool getTiled() const;
        void setTiled(bool tiled);

        int getFirstLevel() const;
        void setFirstLevel(int firstLevel );

        int getMaxLevel() const;
        void setMaxLevel(int maxLevel);

        const osgEarth::Profile* getProfile() const;
        void setProfile( const osgEarth::Profile* profile );

    protected:
        osg::ref_ptr< const osgEarth::Profile > _profile;
        GeoExtent _extent;
        bool _tiled;
        int _firstLevel;
        int _maxLevel;
    };

    struct AttributeValueUnion
    {
        std::string stringValue;
        double      doubleValue;
        int         intValue;
        bool        boolValue;

        //Whether the value is set.  A value of false means the value is effectively NULL
        bool        set;
    };

    enum AttributeType
    {
        ATTRTYPE_UNSPECIFIED,
        ATTRTYPE_STRING,
        ATTRTYPE_INT,
        ATTRTYPE_DOUBLE,
        ATTRTYPE_BOOL
    };

    struct OSGEARTHFEATURES_EXPORT AttributeValue : public std::pair<AttributeType,AttributeValueUnion>
    {    
        std::string getString() const;
        double getDouble( double defaultValue =0.0 ) const;
        int getInt( int defaultValue =0 ) const;
        bool getBool( bool defaultValue =false ) const;              
    };

    typedef std::map<std::string, AttributeValue> AttributeTable;

    typedef unsigned long FeatureID;

    /**
     * Wraps a FeatureID in a referenced object.
     */
    class RefFeatureID : public osg::Referenced
    {
    public:
        RefFeatureID( FeatureID fid ) : _fid(fid) { }
        virtual ~RefFeatureID() { }

        operator FeatureID () const { return _fid; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   