[1250] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/
|
---|
| 2 | // Copyright (C) 1996-2019 Maciej Komosinski and Szymon Ulatowski.
|
---|
| 3 | // See LICENSE.txt for details.
|
---|
| 4 |
|
---|
| 5 | #include "paramlist.h"
|
---|
| 6 | #include <frams/util/extvalue.h>
|
---|
| 7 |
|
---|
| 8 | int ParamList::getGroupCount()
|
---|
| 9 | {
|
---|
| 10 | int count = 0;
|
---|
| 11 | for (int i = 0; i < list.size(); i++)
|
---|
| 12 | count += ((ParamInterface*)list(i))->getGroupCount();
|
---|
| 13 | return count;
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | int ParamList::getPropCount()
|
---|
| 17 | {
|
---|
| 18 | int count = 0;
|
---|
| 19 | for (int i = 0; i < list.size(); i++)
|
---|
| 20 | count += ((ParamInterface*)list(i))->getPropCount();
|
---|
| 21 | return count;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | int ParamList::getSubParam(int i, ParamInterface **sub_p, int *sub_i)
|
---|
| 25 | {
|
---|
| 26 | int n;
|
---|
| 27 | ParamInterface *pi;
|
---|
| 28 | for (int j = 0; j < list.size(); j++)
|
---|
| 29 | {
|
---|
| 30 | pi = (ParamInterface*)list(j);
|
---|
| 31 | if (i < (n = pi->getPropCount()))
|
---|
| 32 | {
|
---|
| 33 | *sub_p = pi;
|
---|
| 34 | *sub_i = i;
|
---|
| 35 | return 1;
|
---|
| 36 | }
|
---|
| 37 | i -= n;
|
---|
| 38 | }
|
---|
| 39 | return 0;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | int ParamList::getSubGroup(int i, ParamInterface **sub_p, int *sub_i)
|
---|
| 43 | {
|
---|
| 44 | int n;
|
---|
| 45 | ParamInterface *pi;
|
---|
| 46 | for (int j = 0; j < list.size(); j++)
|
---|
| 47 | {
|
---|
| 48 | pi = (ParamInterface*)list(j);
|
---|
| 49 | if (i < (n = pi->getGroupCount()))
|
---|
| 50 | {
|
---|
| 51 | *sub_p = pi;
|
---|
| 52 | *sub_i = i;
|
---|
| 53 | return 1;
|
---|
| 54 | }
|
---|
| 55 | i -= n;
|
---|
| 56 | }
|
---|
| 57 | return 0;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | #define FUN(_type_,_name_,_ret_) \
|
---|
| 61 | _type_ ParamList:: _name_ (int i) \
|
---|
| 62 | { \
|
---|
| 63 | int j; ParamInterface *pi; \
|
---|
| 64 | if (!getSubParam(i,&pi,&j)) return _ret_; \
|
---|
| 65 | return pi-> _name_ (j); \
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | FUN(const char*, id, 0)
|
---|
| 69 | FUN(const char*, name, 0)
|
---|
| 70 | FUN(const char*, type, 0)
|
---|
| 71 | FUN(const char*, help, 0)
|
---|
| 72 | FUN(int, flags, 0)
|
---|
| 73 | FUN(int, group, 0)
|
---|
| 74 | FUN(SString, getString, SString())
|
---|
| 75 | FUN(paInt, getInt, 0)
|
---|
| 76 | FUN(double, getDouble, 0)
|
---|
| 77 | FUN(ExtValue, getExtValue, ExtValue((paInt)0))
|
---|
| 78 | FUN(ExtObject, getObject, ExtObject())
|
---|
| 79 |
|
---|
| 80 | #define FUN2(_type_,_name_,_argt_) \
|
---|
| 81 | _type_ ParamList:: _name_ (int i,_argt_ v) \
|
---|
| 82 | { \
|
---|
| 83 | int j; ParamInterface *pi; \
|
---|
| 84 | if (!getSubParam(i,&pi,&j)) return 0; \
|
---|
| 85 | return pi-> _name_ (j,v); \
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | FUN2(int, setInt, paInt)
|
---|
| 89 | FUN2(int, setDouble, double)
|
---|
| 90 | FUN2(int, setString, const SString &)
|
---|
| 91 | FUN2(int, setObject, const ExtObject &)
|
---|
| 92 | FUN2(int, setExtValue, const ExtValue &)
|
---|
| 93 |
|
---|
| 94 | void ParamList::call(int i, ExtValue* args, ExtValue *ret)
|
---|
| 95 | {
|
---|
| 96 | int j; ParamInterface *pi;
|
---|
| 97 | if (!getSubParam(i, &pi, &j)) return;
|
---|
| 98 | pi->call(j, args, ret);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | const char *ParamList::grname(int i)
|
---|
| 102 | {
|
---|
| 103 | int j; ParamInterface *pi;
|
---|
| 104 | if (!getSubGroup(i, &pi, &j)) return 0;
|
---|
| 105 | return pi->grname(j);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | int ParamList::grmember(int gi, int i)
|
---|
| 109 | {
|
---|
| 110 | int n; ParamInterface *pi;
|
---|
| 111 | int count = 0;
|
---|
| 112 | for (int j = 0; j < list.size(); j++)
|
---|
| 113 | {
|
---|
| 114 | pi = (ParamInterface*)list(j);
|
---|
| 115 | if (gi < (n = pi->getGroupCount()))
|
---|
| 116 | return count + pi->grmember(gi, i);
|
---|
| 117 | count += pi->getPropCount();
|
---|
| 118 | gi -= n;
|
---|
| 119 | }
|
---|
| 120 | return -9999;
|
---|
| 121 | }
|
---|