source: cpp/gdk/neurolibrary.cpp @ 57

Last change on this file since 57 was 5, checked in by sz, 16 years ago

added the GDK (Genotype Development Kit)

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