// This file is a part of Framsticks SDK. http://www.framsticks.com/ // Copyright (C) 1996-2019 Maciej Komosinski and Szymon Ulatowski. // See LICENSE.txt for details. #include "paramlist.h" #include int ParamList::getGroupCount() { int count = 0; for (int i = 0; i < list.size(); i++) count += ((ParamInterface*)list(i))->getGroupCount(); return count; } int ParamList::getPropCount() { int count = 0; for (int i = 0; i < list.size(); i++) count += ((ParamInterface*)list(i))->getPropCount(); return count; } int ParamList::getSubParam(int i, ParamInterface **sub_p, int *sub_i) { int n; ParamInterface *pi; for (int j = 0; j < list.size(); j++) { pi = (ParamInterface*)list(j); if (i < (n = pi->getPropCount())) { *sub_p = pi; *sub_i = i; return 1; } i -= n; } return 0; } int ParamList::getSubGroup(int i, ParamInterface **sub_p, int *sub_i) { int n; ParamInterface *pi; for (int j = 0; j < list.size(); j++) { pi = (ParamInterface*)list(j); if (i < (n = pi->getGroupCount())) { *sub_p = pi; *sub_i = i; return 1; } i -= n; } return 0; } #define FUN(_type_,_name_,_ret_) \ _type_ ParamList:: _name_ (int i) \ { \ int j; ParamInterface *pi; \ if (!getSubParam(i,&pi,&j)) return _ret_; \ return pi-> _name_ (j); \ } FUN(const char*, id, 0) FUN(const char*, name, 0) FUN(const char*, type, 0) FUN(const char*, help, 0) FUN(int, flags, 0) FUN(int, group, 0) FUN(SString, getString, SString()) FUN(paInt, getInt, 0) FUN(double, getDouble, 0) FUN(ExtValue, getExtValue, ExtValue((paInt)0)) FUN(ExtObject, getObject, ExtObject()) #define FUN2(_type_,_name_,_argt_) \ _type_ ParamList:: _name_ (int i,_argt_ v) \ { \ int j; ParamInterface *pi; \ if (!getSubParam(i,&pi,&j)) return 0; \ return pi-> _name_ (j,v); \ } FUN2(int, setInt, paInt) FUN2(int, setDouble, double) FUN2(int, setString, const SString &) FUN2(int, setObject, const ExtObject &) FUN2(int, setExtValue, const ExtValue &) void ParamList::call(int i, ExtValue* args, ExtValue *ret) { int j; ParamInterface *pi; if (!getSubParam(i, &pi, &j)) return; pi->call(j, args, ret); } const char *ParamList::grname(int i) { int j; ParamInterface *pi; if (!getSubGroup(i, &pi, &j)) return 0; return pi->grname(j); } int ParamList::grmember(int gi, int i) { int n; ParamInterface *pi; int count = 0; for (int j = 0; j < list.size(); j++) { pi = (ParamInterface*)list(j); if (gi < (n = pi->getGroupCount())) return count + pi->grmember(gi, i); count += pi->getPropCount(); gi -= n; } return -9999; }