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

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

Code formatting

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[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
9NeuroLibrary NeuroLibrary::staticlibrary;
10
11int 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
22NeuroClass* 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
29SString NeuroLibrary::getClassName(int classindex)
30{
[790]31        NeuroClass *cl = getClass(classindex);
32        return cl ? cl->getName() : SString();
[109]33}
34
[790]35NeuroClass *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
51void NeuroLibrary::addStandardClasses()
52{
53#include NEURO_CLS_LIBRARY
54}
55
56NeuroLibrary::NeuroLibrary()
57{
[790]58        addStandardClasses();
[109]59}
60
61NeuroLibrary::~NeuroLibrary()
62{
[790]63        FOREACH(NeuroClass*, cl, classes)
64                delete cl;
[109]65}
66
67void NeuroLibrary::removeClass(int i)
68{
[790]69        classes -= i;
[109]70}
71
72void NeuroLibrary::clear()
73{
[790]74        while (getClassCount() > 0)
75                removeClass(getClassCount() - 1);
[109]76}
Note: See TracBrowser for help on using the repository browser.