source: cpp/frams/neuro/neurolibrary.cpp @ 1282

Last change on this file since 1282 was 790, checked in by Maciej Komosinski, 7 years ago

Code formatting

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
4
5#include "neurolibrary.h"
6#include <frams/param/param.h>
7#include <frams/model/modelparts.h>
8
9NeuroLibrary NeuroLibrary::staticlibrary;
10
11int NeuroLibrary::findClassIndex(const SString & classname, bool activeonly)
12{
13        NeuroClass* cl;
14        for (int i = 0; cl = (NeuroClass*)classes(i); i++)
15        {
16                if (activeonly && !cl->active) continue;
17                if (classname == cl->getName()) return i;
18        }
19        return -1;
20}
21
22NeuroClass* NeuroLibrary::findClass(const SString & classname, bool activeonly)
23{
24        int i = findClassIndex(classname, activeonly);
25        if (i < 0) return 0;
26        return getClass(i);
27}
28
29SString NeuroLibrary::getClassName(int classindex)
30{
31        NeuroClass *cl = getClass(classindex);
32        return cl ? cl->getName() : SString();
33}
34
35NeuroClass *NeuroLibrary::addClass(NeuroClass *cls, bool replace)
36{
37        NeuroClass *old = findClass(cls->getName());
38        if (old)
39        {
40                if (replace)
41                {
42                        classes -= old;
43                        classes += cls;
44                }
45        }
46        else
47                classes += cls;
48        return old;
49}
50
51void NeuroLibrary::addStandardClasses()
52{
53#include NEURO_CLS_LIBRARY
54}
55
56NeuroLibrary::NeuroLibrary()
57{
58        addStandardClasses();
59}
60
61NeuroLibrary::~NeuroLibrary()
62{
63        FOREACH(NeuroClass*, cl, classes)
64                delete cl;
65}
66
67void NeuroLibrary::removeClass(int i)
68{
69        classes -= i;
70}
71
72void NeuroLibrary::clear()
73{
74        while (getClassCount() > 0)
75                removeClass(getClassCount() - 1);
76}
Note: See TracBrowser for help on using the repository browser.