/** \file
 *
 *  Contains the SettingReader class definition.
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 *
 */

#ifndef SETTINGREADER_H_
#define SETTINGREADER_H_

#include "data/ElementURI.h"
#include "utils/Str.h"
#include "utils/Timestamp.h"

class Component;
class DataValue;
class Timespan;
class Unit;
class ValueClause;

/**
 *  Reads values from mission settings.
 *
 *  \ingroup missionScript
 */
class SettingReader
{
public:

    SettingReader( const SettingURI& settingURI, ValueClause* valueClause );

    virtual ~SettingReader();

    //===============================================================
    /// Status and state functions

    bool isActive();

    //===============================================================
    /// Get functions
    bool read( const Unit& unit, unsigned char& readTo );

    bool read( const Unit& unit, double& readTo );

    bool read( const Unit& unit, float& readTo );

    bool read( const Unit& unit, int& readTo );

    bool read( bool& readTo );

    bool read( Timespan& readTo );

    bool read( DataValue& readTo );

    int asInt( const Unit& unit );

    double asDouble( const Unit& unit ) __attribute__( ( deprecated ) );

    Str asString( const Unit& unit );

    const SettingURI& getSettingURI()
    {
        return settingURI_;
    }

    const DataValue* getDefaultValue()
    {
        return defaultValue_;
    }

    const Unit* getDefaultUnit();

    // If input values have changed since last run of a component
    bool wasTouchedSinceLastRun( const Component* component );

    // Returns most recent timestamp of input values
    Timestamp getMostRecentTimestamp( );

protected:

    const SettingURI settingURI_;
    const DataValue* defaultValue_;
    bool deleteDefaultValue_;
    ValueClause* valueClause_;

    bool evalValueClause();

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    SettingReader( const SettingReader& old ); // disallow copy constructor

    friend class Behavior;

    SettingReader( const SettingURI& settingURI, const DataValue* defaultValue,
                   bool deleteDefaultValue = true );

    void setDefaultValue( const DataValue* defaultValue,
                          bool deleteDefaultValue = true )
    {
        defaultValue_ = defaultValue;
        deleteDefaultValue_ = deleteDefaultValue;
    }

    void setValueClause( ValueClause* valueClause )
    {
        valueClause_ = valueClause;
    }

};

#endif /*SETTINGREADER_H_*/
