Source: kalamaris/mapvararg.h


Annotated List
Files
Globals
Hierarchy
Index
/*  mapvararg.h - 
    This file is part of Kalamaris
    Copyright (C) 2000  Antonio Larrosa Jimenez
    Kalamaris' homepage : http://www.arrakis.es/~rlarrosa/kalamaris.html

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 

    Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>

 ***************************************************************************/
#ifndef _MAPVARARG_H
#define _MAPVARARG_H

#include "map.h"

/**
 * A Map with variable arguments . It's also used to do lazy function evaluation
 * Example:
 * When f(x) is defined as f(x)=x+2, it stores:
 *
 *   f(x) (Map)
 *    | 
 *    + (Operator)
 *   / \
 *  x   2 (Constant)
 * (Var.) 
 *
 * If we then define g(x) as g(x)=3*f(x), it stores:
 *
 *    g(x) (Map)
 *     |
 *     *
 *    / \
 *   3   f(x) (MVA)
 * (Cte.)
 *
 * Then, when we evaluate g(1), it evaluates the following tree ...
 *
 *       g(x) (MVA)
 *        |
 *       g(x) (Map) (constructed from Factory when evaluating)
 *        |
 *        *
 *       / \
 *      3   f(x) (MVA)
 *           |
 *          f(x) (constructed from Factory when evaluating)
 *           |
 *           +
 *          / \
 *         x   2
 * 
 */
 /**
  *  ... as follows : 
  *
  *       g(1) ----> (g's first parameter name)=1 == x=1
  *        |   
  *       g(x) ----> x=x
  *        |
  *        *
  *       / \
  *      3   f(x) ----> x=eval(x)=1
  *           |
  *          f(x) ----> x=x
  *           |
  *           +
  *          / \
  *         x   2
  * 
 */

class MapVariableArguments : public Map
{
protected:
  
  unsigned int m_maxParameters;

  void allocParameter(unsigned int i, Parameter *parameter);
  void freeParameter(unsigned int i);

public:
  MapVariableArguments ( const QString &decl = QString(), const QString &nam = QString(), 
      				bool parsedefinition=true );
  MapVariableArguments (const MapVariableArguments &m);
  ~MapVariableArguments ();

  virtual Map *copy(void) const;
   
  virtual void setParameterExpression(unsigned int i,const QString &expr);
  virtual void setParameterExpression(unsigned int i, Map *expr);
  virtual void setParameterExpression(unsigned int i, Parameter *expr);
  void addParameterName(const QString &name);
  void delParameterName(const QString &name);
                                                                                  
  /**
   * When doing lazy evaluation, mimetizeFunction is used to get as much information
   * from m as needed to evaluate this function. That is, number of parameter,
   * parameter names, and most important, the map's tree.
   * Note that this method also removes the parameters in m, moving them to this
   * object
   */
  void mimetizeFunction(Map *m);

  /**
   * Checks if we're doing lazy function evaluation, and calls setFunction if
   * appropiate. Then, it calls Map::eval.
   */
  virtual Map * eval(const QDict<Map> &);

  virtual Map *derive(const class Variable &var, const QDict <Map> &vars);

  virtual QString string(void) const;
    
  /**
   * Returns the index of the argument with name nam (in the range 0..nparams)
   * Returns -1 if there's no parameter with that name
   */
  int argumentIndex(const QString &nam) const;
  int isArgumentName(const QString &nam) const;
};

#endif

Generated by: antlarr@terminus on Mon Jun 5 03:54:02 2000, using kdoc 2.0a22.