source: cpp/frams/param/paramlist.cpp @ 1315

Last change on this file since 1315 was 1250, checked in by Maciej Komosinski, 15 months ago

Added class ParamList? implementing ParamInterface?

File size: 2.6 KB
Line 
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
8int 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
16int 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
24int 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
42int 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{ \
63int j; ParamInterface *pi; \
64if (!getSubParam(i,&pi,&j)) return _ret_; \
65return pi-> _name_ (j); \
66}
67
68FUN(const char*, id, 0)
69FUN(const char*, name, 0)
70FUN(const char*, type, 0)
71FUN(const char*, help, 0)
72FUN(int, flags, 0)
73FUN(int, group, 0)
74FUN(SString, getString, SString())
75FUN(paInt, getInt, 0)
76FUN(double, getDouble, 0)
77FUN(ExtValue, getExtValue, ExtValue((paInt)0))
78FUN(ExtObject, getObject, ExtObject())
79
80#define FUN2(_type_,_name_,_argt_) \
81_type_ ParamList:: _name_ (int i,_argt_ v) \
82{ \
83int j; ParamInterface *pi; \
84if (!getSubParam(i,&pi,&j)) return 0; \
85return pi-> _name_ (j,v); \
86}
87
88FUN2(int, setInt, paInt)
89FUN2(int, setDouble, double)
90FUN2(int, setString, const SString &)
91FUN2(int, setObject, const ExtObject &)
92FUN2(int, setExtValue, const ExtValue &)
93
94void 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
101const 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
108int 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}
Note: See TracBrowser for help on using the repository browser.