RPL Global User-defined Functions -- 4-29-2009 (a) http://cadswes2.colorado.edu/~philw/2009/GlobalRplFunctions/ Invocation of Global RPL Functions: support specific to the caller's RPL Application type. This is important because Global RplObjs have their own application type (GLOBAL), but when called from, for example, a RuleSet or a SeriesSlot-with-RplExpression, values related to, for example, the "current timestep" need to be interpreted according to the caller's RPL application. See changes in these four classes: RplExpression, FuncCallExpr, RplObj and ValueConstraint. A "dynamic" Rpl Application Type override is governed by static settings in the RplExpression class, managed from FuncCallExpr::evaluate(). ------------------------------- RplExpression/RplExpression.hpp RplExpression/RplExpression.cpp ------------------------------- Revised RplExpression RplApplication::Type data members: RplApplication::Type _ownerAppType; // was 'appType' static RplApplication::Type _dynamicAppType; // NEW static int _dynamicAppTypeSemaphore; // NEW Revised RplExpression RplApplication::Type methods: // RplObj "Owner"-based RplApplication Type inline RplApplication::Type getOwnerAppType() const; void setApplicationType (RplApplication::Type newAppType); // Dynamic override of RplApplication Type, used for "dynamically scoped" // override of Global RPL functions using the _caller's_ application type. static RplApplication::Type getDynamicAppType(); static bool usingDynamicAppType(); static RplApplication::Type // returns current value to save (cachedType) startDynamicAppTypeOverride (RplApplication::Type overrideType); static void endDynamicAppTypeOverride (RplApplication::Type cachedType); // Switched (Owner vs. Dynamic) RplApplication Types inline RplApplication::Type getApplicationType() const; // owner or dynamic inline RplApplication* getApplication() const; // owner or dynamic ------------------------------ RplExpression/FuncCallExpr.cpp ------------------------------ In FuncCallExpr::evaluate(), if the function to be called is Global, override with the "active" (dynamic or owner) application type of 'this' RplExpression. const bool functionToCallIsGlobal = functionPtr->rplObjIsGlobal(); if (functionToCallIsGlobal) { // ----- Start Dynamic Application Type Override ----- const RplApplication::Type overrideType (getApplicationType()); const RplApplication::Type saveType = RplExpression::startDynamicAppTypeOverride (overrideType); // Evaluate the function. functionPtr->evaluate( actualArgs, result, slotsAccessed ); // ----- End Dynamic Application Type Override ----- RplExpression::endDynamicAppTypeOverride (saveType); } else // (not functionToCallIsGlobal) { // Evaluate the function. functionPtr->evaluate( actualArgs, result, slotsAccessed ); } -------------- Rpl/RplObj.cpp Rpl/RplObj.hpp Rpl/ValueConstraint.cpp Rpl/ValueConstraint.hpp -------------- Revised RplObj and ValueConstraint RplApplication::Type DATA MEMBERS: OLD: RplApplication::Type _appType; NEW: RplApplication::Type _ownerAppType; Revised RplObj and ValueConstraint RplApplication::Type METHODS: (Comment text is for RplObj change, similar for ValueConstraint): // RplObj "Owner"-based RplApplication Type inline RplApplication::Type getOwnerAppType() const; void setApplicationType (RplApplication::Type newAppType); // Switched (Owner vs. Dynamic) RplApplication Types. // If the static RplExpression dynamic application type override state // is active, these methods return that mechanisms's dynamic applicatieon // type instead of the local RplObj "Owner"-based application type. inline RplApplication::Type getApplicationType() const; // owner or dynamic inline RplApplication* getApplication() const; // owner or dynamic ------------------------ QtRpl/RplBaseDlg.cpp QtRpl/RplBlockDlg.cpp QtRpl/RplDlgMgr.cpp QtRpl/RplFrame.cpp QtRpl/RplFunctionDlg.cpp QtRpl/RplGroupDlg.cpp QtRpl/RplListView.cpp QtRpl/RplSetDlg.cpp ------------------------ For retrieving the RplObj RplApplication::Type, use 'getOwnerAppType()' instead of 'getApplicationType()'. The latter incorporates the dynamic RPL application type override, if active, which isn't what's wanted in the GUI. ---