1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #include "neurolibrary.h" |
---|
6 | #include <frams/param/param.h> |
---|
7 | #include <frams/model/modelparts.h> |
---|
8 | |
---|
9 | NeuroLibrary NeuroLibrary::staticlibrary; |
---|
10 | |
---|
11 | int 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 | |
---|
22 | NeuroClass* 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 | |
---|
29 | SString NeuroLibrary::getClassName(int classindex) |
---|
30 | { |
---|
31 | NeuroClass *cl=getClass(classindex); |
---|
32 | return cl? cl->getName() : SString(); |
---|
33 | } |
---|
34 | |
---|
35 | NeuroClass *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 | |
---|
51 | void NeuroLibrary::addStandardClasses() |
---|
52 | { |
---|
53 | #include NEURO_CLS_LIBRARY |
---|
54 | } |
---|
55 | |
---|
56 | NeuroLibrary::NeuroLibrary() |
---|
57 | { |
---|
58 | addStandardClasses(); |
---|
59 | } |
---|
60 | |
---|
61 | NeuroLibrary::~NeuroLibrary() |
---|
62 | { |
---|
63 | FOREACH(NeuroClass*,cl,classes) |
---|
64 | delete cl; |
---|
65 | } |
---|
66 | |
---|
67 | void NeuroLibrary::removeClass(int i) |
---|
68 | { |
---|
69 | classes-=i; |
---|
70 | } |
---|
71 | |
---|
72 | void NeuroLibrary::clear() |
---|
73 | { |
---|
74 | while(getClassCount()>0) |
---|
75 | removeClass(getClassCount()-1); |
---|
76 | } |
---|
77 | |
---|