/* Copyright 2011-2015 Thibaut Paumard This file is part of Gyoto. Gyoto 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 3 of the License, or (at your option) any later version. Gyoto 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 Gyoto. If not, see . */ #include "ygyoto.h" #include "ygyoto_private.h" #include "yapi.h" #include "pstdlib.h" #ifdef GYOTO_USE_XERCES #include "GyotoFactory.h" #endif #include using namespace std; using namespace Gyoto; using namespace Gyoto::Astrobj; static char ygyoto_Astrobj_names[YGYOTO_TYPE_LEN][YGYOTO_MAX_REGISTERED] ={{0}}; static ygyoto_Astrobj_eval_worker_t *ygyoto_Astrobj_evals[YGYOTO_MAX_REGISTERED] ={0}; static int ygyoto_Astrobj_count=0; YGYOTO_YUSEROBJ(Astrobj, Astrobj::Generic) YGYOTO_BASE_CONSTRUCTOR1(Astrobj,astrobj) extern "C" { void gyoto_Astrobj_eval(void *obj, int argc) { GYOTO_DEBUG << endl; // If no parameters, return pointer if (argc==1 && yarg_nil(0)) { ypush_long((long)((gyoto_Astrobj*)obj)->smptr()); return; } // Try calling kind-specific worker int n=0; SmartPointer * OBJ = &(((gyoto_Astrobj*)obj)->smptr); const string kind = (*OBJ)->kind(); while (n((*OBJ)())) base = THINDISK; static char const * knames_thindisk[]={"unit", YGYOTO_THINDISK_GENERIC_KW, 0}; static char const * knames_generic[]={"unit", YGYOTO_ASTROBJ_GENERIC_KW, 0}; static long kglobs[YGYOTO_ASTROBJ_BASE_MAX_KW_N+2]; static int kiargs[YGYOTO_ASTROBJ_BASE_MAX_KW_N+1]; char ** knames=NULL; ygyoto_Astrobj_generic_eval_t * worker; // ThinDisk switch (base) { case GENERIC: knames=const_cast(knames_generic); worker = &ygyoto_Astrobj_generic_eval; break; case THINDISK: knames = const_cast(knames_thindisk); worker = &ygyoto_ThinDisk_generic_eval; break; default: y_error("BUG: unknown base type"); } yarg_kw_init(knames, kglobs, kiargs); while (iarg>=1) { iarg = yarg_kw(iarg, kglobs, kiargs); if (iarg>=1) { if (parg<4) piargs[parg++]=iarg--; else y_error("gyoto_Astrobj takes at most 4 positional arguments"); } } char * unit=NULL; int k =-1; /* UNIT */ YGYOTO_WORKER_SET_UNIT; (*worker)(OBJ, kiargs+k+1, piargs, rvset, paUsed, unit); } } void ygyoto_Astrobj_register(char const*const name, ygyoto_Astrobj_eval_worker_t* on_eval){ int n; if (ygyoto_Astrobj_count==YGYOTO_MAX_REGISTERED) y_error("Too many Astrobjs registered"); for (n=0; n*OBJ, int *kiargs, int *piargs, int *rvset, int *paUsed, char * unit) { int k=-1, iarg; char const * rmsg="Cannot set return value more than once"; char const * pmsg="Cannot use positional argument more than once"; // avoid ununsed warning if (rmsg && pmsg) {} if (debug()) for (int i=0; i