aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source/flitem.cpp
blob: 3dec59659495226d3670ea073986da400e736a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* 

flext - C++ layer for Max/MSP and pd (pure data) externals

Copyright (c) 2001-2004 Thomas Grill (xovo@gmx.net)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.  

*/

/*! \file flitem.cpp
    \brief Processing of method and attribute lists.
*/
 
#include "flext.h"
#include <string.h>

void flext_base::ItemCont::Add(Item *item,const t_symbol *tag,int inlet)
{
    FLEXT_ASSERT(inlet >= -1);
    if(!Contained(inlet)) resize(inlet+2);
    ItemSet &set = GetInlet(inlet);
    set[tag].push_back(item);
    members++;
}

bool flext_base::ItemCont::Remove(Item *item,const t_symbol *tag,int inlet)
{
    FLEXT_ASSERT(inlet >= -1);
    if(Contained(inlet)) {
        ItemSet &set = GetInlet(inlet);
        ItemSet::iterator it = set.find(tag);
        if(it != set.end()) {
            ItemList &lst = it->second;
            for(ItemList::iterator lit = lst.begin(); lit != lst.end(); ++lit) {
                if(*lit == item) {
                    delete *lit;
                    lst.erase(lit);
                    return true;
                }
            }
        }
    }
    return false;
}

flext_base::ItemList *flext_base::ItemCont::FindList(const t_symbol *tag,int inlet)
{
    FLEXT_ASSERT(inlet >= -1);
    if(Contained(inlet)) {
        ItemSet &ai = GetInlet(inlet);
        ItemSet::iterator as = ai.find(tag); 
        if(as != ai.end()) return &as->second;
    }
    return NULL;
}

// --- class item lists (methods and attributes) ----------------

typedef std::map<flext_base::t_classid,flext_base::ItemCont *> ClassMap;
typedef std::vector<ClassMap> ClassArr;

static ClassArr classarr;

flext_base::ItemCont *flext_base::GetClassArr(t_classid c,int ix) 
{
    if(ix >= (int)classarr.size()) classarr.resize(ix+1);
    ClassMap &map = classarr[ix];
    ClassMap::iterator it = map.find(c);
    if(it == map.end()) {
        ItemCont *cont = new ItemCont;
        map[c] = cont;
        return cont;
    }
    else
        return it->second;
}