/************************************************************************
 * sleargs.h -- routines for reading the parameters to compiled 
 *              Exluna shaders.
 *
 * (c) Copyright 2001 Exluna, Inc.  All rights reserved.
 *
 * $Revision: 1.3 $   $Date: 2001/06/30 00:07:51 $
 ************************************************************************/

#ifndef SLEARGS_H
#define SLEARGS_H


class sleArgs {
public:
    // Make a simple enumerated type that we can use to relay information
    // about datatypes and shader types.
    enum Type {
	TYPE_ERROR = -1,
	TYPE_UNKNOWN = 0,
	// Data types
	TYPE_FLOAT = 1, TYPE_COLOR, TYPE_POINT, TYPE_VECTOR, TYPE_NORMAL,
	TYPE_MATRIX, TYPE_STRING,
	// Shader types
	TYPE_SURFACE = 16, TYPE_DISPLACEMENT, TYPE_LIGHT,
	TYPE_VOLUME, TYPE_IMAGER
    };

    // Make a structure that can hold all the information (including the
    // value) of a single shader parameter.
    struct Symbol {
	const char *name;           // argument name
	Type type;                  // data type
	int arraylen;               // array length, or 0 if not an array
	bool output, varying;       // is it an output param?  is it varying?
	const char *spacename;      // name of space, or NULL if not applicable
	void *valp;                 // pointer to default value, or NULL if
	                            //   we couldn't discern the value
	Symbol() : valp(NULL), arraysyms(NULL) { }
	bool valisvalid () const { return valp!=NULL; }
	float floatval(int i) const { return ((float *)valp)[i]; }
	const char *stringval(int i) const { return ((const char **)valp)[i]; }
	Symbol *arraysyms;
    };

    // Constructor: must pass shader name; optionally pass shader search path
    // The constructor reads the shader and stashes args in private data.
    sleArgs (const char *shadername, const char *searchpath=NULL);

    // Destructor automatically cleans up and frees all allocated memory
    ~sleArgs ();

    // Ask for the type of the shader we read, will return TYPE_ERROR
    // if we weren't able to find the shader or couldn't open it.
    Type shadertype (void) const { return shadtype; }

    // Get the name of the shader, or NULL if we couldn't open it.
    const char *shadername (void) const { return shadname; }

    // How many shader arguments (parameters) did the shader have?
    int nargs (void) const { return numargs; }

    // Get a Symbol* for an argument, searching by name or by number
    const Symbol *getarg (const char *name) const;
    const Symbol *getarg (int i) const { return &(args[i]); }

    // For arrays, get a particular element
    const Symbol *getarrayelement (const Symbol *array, int index) const;
    // Some helper functions for your convenience...
    static const char *typestr (Type t);   // String rep of the type
private:
    // Internal storage.  Users should not look behind the curtain.
    Type shadtype;
    Symbol *args;
    const char *shadname;
    int numargs, alloced;
    friend class SLCArgsParser;
};



#endif /* SLEARGS_H */
