[286] | 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. |
---|
[109] | 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 | { |
---|
[790] | 13 | NeuroClass* cl; |
---|
| 14 | for (int i = 0; cl = (NeuroClass*)classes(i); i++) |
---|
[109] | 15 | { |
---|
[790] | 16 | if (activeonly && !cl->active) continue; |
---|
| 17 | if (classname == cl->getName()) return i; |
---|
[109] | 18 | } |
---|
[790] | 19 | return -1; |
---|
[109] | 20 | } |
---|
| 21 | |
---|
| 22 | NeuroClass* NeuroLibrary::findClass(const SString & classname, bool activeonly) |
---|
| 23 | { |
---|
[790] | 24 | int i = findClassIndex(classname, activeonly); |
---|
| 25 | if (i < 0) return 0; |
---|
| 26 | return getClass(i); |
---|
[109] | 27 | } |
---|
| 28 | |
---|
| 29 | SString NeuroLibrary::getClassName(int classindex) |
---|
| 30 | { |
---|
[790] | 31 | NeuroClass *cl = getClass(classindex); |
---|
| 32 | return cl ? cl->getName() : SString(); |
---|
[109] | 33 | } |
---|
| 34 | |
---|
[790] | 35 | NeuroClass *NeuroLibrary::addClass(NeuroClass *cls, bool replace) |
---|
[109] | 36 | { |
---|
[790] | 37 | NeuroClass *old = findClass(cls->getName()); |
---|
| 38 | if (old) |
---|
[109] | 39 | { |
---|
[790] | 40 | if (replace) |
---|
[109] | 41 | { |
---|
[790] | 42 | classes -= old; |
---|
| 43 | classes += cls; |
---|
[109] | 44 | } |
---|
| 45 | } |
---|
[790] | 46 | else |
---|
| 47 | classes += cls; |
---|
| 48 | return old; |
---|
[109] | 49 | } |
---|
| 50 | |
---|
| 51 | void NeuroLibrary::addStandardClasses() |
---|
| 52 | { |
---|
| 53 | #include NEURO_CLS_LIBRARY |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | NeuroLibrary::NeuroLibrary() |
---|
| 57 | { |
---|
[790] | 58 | addStandardClasses(); |
---|
[109] | 59 | } |
---|
| 60 | |
---|
| 61 | NeuroLibrary::~NeuroLibrary() |
---|
| 62 | { |
---|
[790] | 63 | FOREACH(NeuroClass*, cl, classes) |
---|
| 64 | delete cl; |
---|
[109] | 65 | } |
---|
| 66 | |
---|
| 67 | void NeuroLibrary::removeClass(int i) |
---|
| 68 | { |
---|
[790] | 69 | classes -= i; |
---|
[109] | 70 | } |
---|
| 71 | |
---|
| 72 | void NeuroLibrary::clear() |
---|
| 73 | { |
---|
[790] | 74 | while (getClassCount() > 0) |
---|
| 75 | removeClass(getClassCount() - 1); |
---|
[109] | 76 | } |
---|