2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET
4 * Copyright (C) 2014 - Scilab Enterprises - Cedric Delamarre
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
21 class UserType : public GenericType
25 virtual ~UserType() {}
27 /*** non virtual function to prevent overriding in user derived class ***/
29 inline ScilabType getType(void)
31 return ScilabUserType;
34 inline ScilabId getId(void)
45 /*** User will be asked to implement the following methods ***/
46 /*** in order Scilab engine to manage correctly this user type ***/
48 std::wstring getTypeStr() = 0;
49 std::wstring getShortTypeStr() = 0;
50 InternalType* clone() = 0;
53 /*** User can overload these methode ***/
54 /*** all methode not overloaded will call scilab overload ***/
56 // hasToString return false so scilab will call overload %..._p
57 // and toString method is useless
58 // if user overload hasToString for return true, he must overload toString method
59 // bool toString(std::wostringstream& ostr)
60 virtual bool hasToString()
65 // overload this methode if hasToString methode return true
66 virtual bool toString(std::wostringstream& /*ostr*/)
72 // _pArs is a list of scilab types:: of where we want to extract
73 // _pSource is what we wan to insert
74 virtual InternalType* insert(typed_list* /*_pArgs*/, InternalType* /*_pSource*/)
79 // this methode is called to perform an extraction by field. ie : a = myUserType.myfield
80 // name is the field name
81 // out contain extraction of field
82 virtual bool extract(const std::wstring & /*name*/, InternalType *& /*out*/)
87 // extraction by value, this methode can be only called by "invoke" methode below.
88 // _pArs is a list of scilab types:: of where we want to extract
89 // return all element extracted, in case when multiple elements returned
90 // these elements must be stored in a types::List
91 virtual InternalType* extract(typed_list* /*_pArgs*/)
96 // if return false , Scilab will never call "invoke" method
97 virtual bool isInvokable() const
102 // invoke method is called when a UserType is called with "(...)" ie : a = myUserType(...)
103 // This implementation allow the use of extract method above, but it can be overloaded.
105 // in : contain input arguments myUserType(arg1,arg2,...)
106 // opt : contain optional input arguments myUserType(arg1=..., arg2=..., ...)
107 // _iRetCount : is the number of output arguments (ie : [a,b] = myUserType(...), _iRetCount = 2)
108 // out : after "invoke" execution, will contain results
109 // execFunc : is used in case of macro call : Overload::call(L"A_Macro", in, _iRetCount, out, execFunc);
110 // e : Generally used to return the Location when thowing an error. ie : throw ast::ScilabError(L"error message", 999, e.getLocation());
112 // if false, Scilab will call the macro %UserType_e,where UserType is the string return by the methode getShortTypeStr()
113 // if true, Scilab will set each elements of out in Scilab variables
114 virtual bool invoke(types::typed_list & in, types::optional_list & /*opt*/, int /*_iRetCount*/, types::typed_list & out, ast::ConstVisitor & /*execFunc*/, const ast::Exp & /*e*/)
116 InternalType* pIT = extract(&in);
126 // used to compute the iterator in scilab loop "for"
127 // when type is a two dimensions array
128 // _iPos is the column position
129 virtual GenericType* getColumnValues(int /*_iPos*/)
137 #endif /* !__USER_HXX__ */