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

#ifndef SCRIPTNODE_H_
#define SCRIPTNODE_H_

class DataValue;

/** \ingroup missionScript
 *
 *  Abstract base class for nodes in tree-like scripts.
 *  Intended to allow missions to be scripted in a variety of formats.
 */
class ScriptNode
{
public:

    /// Destructor
    virtual ~ScriptNode() {};

    /// Returns true if the node contains child nodes
    virtual bool hasChildNodes() const = 0;

    /// Returns the child node, by name, or NULL if none.
    virtual ScriptNode* getNamedNode( const Str& nodeName ) = 0;

    /// Returns a new child node than can contain other nodes
    virtual ScriptNode* newChildNode( const Str& nodeName ) = 0;

    /// Returns a new child node that is a function
    virtual ScriptNode* newChildFunction( const Str& functionName,
                                          const Str& functionBody, Logger& logger ) = 0;

    /// Returns the number of indexed (array, or list-like) nodes
    /// Returns 0 is this is not a table.
    virtual int getNodeCount( const Str& nodeName ) const = 0;

    /// Returns the indexed (array, or list-like) node at the zero-based index, or NULL if none
    virtual ScriptNode* getIndexedNode( unsigned int index ) = 0;

    /// Returns the parent node, or NULL if this is the root.
    virtual ScriptNode* getParentNode() const = 0;

    /// Returns the index of the node, -1 if named
    virtual int getIndex() const = 0;

    /// Returns the name of the node, undefined if indexed
    virtual const Str& getName() const = 0;

    /// Sets readTo to the value of the node, as a boolean
    /// Returns true if read success
    virtual bool readBool( bool& readTo ) const = 0;

    /// Sets readTo to the value of the node, as a double
    /// Returns true if read success
    virtual bool readDouble( double& readTo ) const = 0;

    /// Sets readTo to the value of the node, unsigned char string
    /// Returns true if read success
    virtual bool readString( Str& readTo ) const = 0;

    /// If the node contains a dataValue, materialize such a dataValue
    /// Use the Unit + value paradigm, if possible
    virtual DataValue* asNewDataValue() = 0;

    /// Attempt to execute the function contained in this node.
    virtual bool execute( FlexArray<DataReader*>& inputs, FlexArray<SettingReader*>& settings,
                          FlexArray<DataWriter*>& outputs, FlexArray<const Unit*>& outUnits,
                          Logger& logger ) = 0;

    /// Attempt to execute the function contained in this node, returning
    /// only a single boolean value.
    virtual bool execute( FlexArray<DataReader*>& inputs, FlexArray<SettingReader*>& settings,
                          bool& boolOutput, Logger& logger ) = 0;

    /// Attempt to execute the function contained in this node, with no inputs and no return value.
    virtual bool execute( Logger& logger ) = 0;

    /// Returns a string representation of this node, with its ancestors,
    /// separated by "." characters.
    virtual Str toString() const = 0;

protected:

    /// Protected constructor for abstract base class.
    ScriptNode() {};

private:

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

};

#endif /* SCRIPTNODE_H_ */
