source: cpp/gdk/neurofactory.cpp @ 5

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

added the GDK (Genotype Development Kit)

File size: 1.2 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 "neurofactory.h"
6#include "sstring.h"
7#include "param.h"
8#include "neuroimpl.h"
9#include "neuroimplfiles.h"
10
11int NeuroFactory::used=0;
12
13NeuroImpl* NeuroFactory::createNeuroImpl(NeuroClass *nc)
14{
15if (!nc) return 0;
16if (!nc->active) return 0;
17NeuroImpl* ni=(NeuroImpl*)nc->impl;
18if (!ni) return 0;
19return ni->makeNew();
20}
21
22NeuroImpl* NeuroFactory::setImplementation(const SString& classname,NeuroImpl *ni,bool deleteold)
23{
24NeuroClass *nc=Neuro::getClass(classname);
25if (!nc) return ni;
26return setImplementation(nc,ni,deleteold);
27}
28
29NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc,NeuroImpl *ni,bool deleteold)
30{
31NeuroImpl* old_ni=(NeuroImpl*)nc->impl;
32nc->impl=ni;
33if (deleteold && old_ni) delete old_ni;
34return old_ni;
35}
36
37#include "neuroimplfiles.h"
38#include "neurocls-factory.h"
39
40void NeuroFactory::setImplementation()
41{
42if (!used)
43        {
44        SETIMPLEMENTATION
45        }
46used++;
47}
48
49void NeuroFactory::freeImplementation()
50{
51used--;
52if (!used)
53        {
54        for(int i=0;i<Neuro::getClassCount();i++)
55                setImplementation(Neuro::getClass(i),0);
56        }
57}
58
Note: See TracBrowser for help on using the repository browser.