001/*
002// This software is subject to the terms of the Eclipse Public License v1.0
003// Agreement, available at the following URL:
004// http://www.eclipse.org/legal/epl-v10.html.
005// You must accept the terms of that agreement to use this software.
006//
007// Copyright (C) 1999-2005 Julian Hyde
008// Copyright (C) 2005-2006 Pentaho and others
009// All Rights Reserved.
010*/
011package mondrian.olap;
012
013import mondrian.calc.Calc;
014import mondrian.calc.ExpCompiler;
015import mondrian.mdx.ResolvedFunCall;
016
017import java.io.PrintWriter;
018
019/**
020 * Definition of an MDX function. See also {@link FunTable}.
021 *
022 * @author jhyde, 21 April, 1999
023 */
024public interface FunDef {
025    /**
026     * Returns the syntactic type of the function.
027     */
028    Syntax getSyntax();
029
030    /**
031     * Returns the name of this function.
032     */
033    String getName();
034
035    /**
036     * Returns the description of this function.
037     */
038    String getDescription();
039
040    /**
041     * Returns the {@link Category} code of the value returned by this
042     * function.
043     */
044    int getReturnCategory();
045
046    /**
047     * Returns the types of the arguments of this function. Values are the same
048     * as those returned by {@link Exp#getCategory()}. The 0<sup>th</sup>
049     * argument of methods and properties are the object they are applied
050     * to. Infix operators have two arguments, and prefix operators have one
051     * argument.
052     */
053    int[] getParameterCategories();
054
055    /**
056     * Creates an expression which represents a call to this function with
057     * a given set of arguments. The result is usually a {@link ResolvedFunCall} but
058     * not always.
059     */
060    Exp createCall(Validator validator, Exp[] args);
061
062    /**
063     * Returns an English description of the signature of the function, for
064     * example "&lt;Numeric Expression&gt; / &lt;Numeric Expression&gt;".
065     */
066    String getSignature();
067
068    /**
069     * Converts a function call into MDX source code.
070     */
071    void unparse(Exp[] args, PrintWriter pw);
072
073    /**
074     * Converts a call to this function into executable objects.
075     *
076     * <p>The result must implement the appropriate interface for the result
077     * type. For example, a function which returns an integer must return
078     * an object which implements {@link mondrian.calc.IntegerCalc}.
079     */
080    Calc compileCall(ResolvedFunCall call, ExpCompiler compiler);
081
082}
083
084// End FunDef.java