source: cpp/frams/neuro/neurofactory.cpp @ 415

Last change on this file since 415 was 375, checked in by Maciej Komosinski, 10 years ago

Renamed logging functions to more intuitive and simple names

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
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.
4
5#include "neurofactory.h"
6#include <frams/util/sstring.h>
7#include <frams/param/param.h>
8#include "neuroimpl.h"
9#include "neurolibrary.h"
10
11#include NEURO_IMPL_FILES
12
13NeuroImpl* NeuroFactory::getImplementation(NeuroClass *nc)
14{
15if (nc!=NULL)
16        {
17        std::map<NeuroClass*,NeuroImpl*>::iterator it=impl.find(nc);
18        if (it!=impl.end())
19                return it->second;
20        }
21return NULL;
22}
23
24NeuroImpl* NeuroFactory::createNeuroImpl(NeuroClass *nc)
25{
26if (!nc) return 0;
27if (!nc->active) return 0;
28NeuroImpl* ni=getImplementation(nc);
29if (!ni) return 0;
30ni=ni->makeNew();
31if (ni) ni->neuroclass=nc;
32return ni;
33}
34
35NeuroImpl* NeuroFactory::setImplementation(const SString& classname,NeuroImpl *ni,bool deleteold)
36{
37NeuroClass *nc=Neuro::getClass(classname);
38if (!nc) return ni;
39return setImplementation(nc,ni,deleteold);
40}
41
42NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc,NeuroImpl *ni,bool deleteold)
43{
44if (nc==NULL) return NULL;
45std::map<NeuroClass*,NeuroImpl*>::iterator it=impl.find(nc);
46NeuroImpl* old_ni=NULL;
47if (it==impl.end())
48        {
49        if (ni!=NULL)
50                {
51                impl[nc]=ni;
52                nc->impl_count++;
53                }
54        return NULL;
55        }
56else
57        {
58        old_ni=it->second;
59        if (ni)
60                it->second=ni;
61        else
62                {
63                impl.erase(it);
64                nc->impl_count--;
65                }
66        }
67if (deleteold && old_ni) delete old_ni;
68return old_ni;
69}
70
71#include NEURO_CLS_FACTORY
72
73void NeuroFactory::setStandardImplementation()
74{
75SETIMPLEMENTATION
76}
77
78void NeuroFactory::freeImplementation()
79{
80for(int i=0;i<Neuro::getClassCount();i++)
81        setImplementation(Neuro::getClass(i),0);
82}
83
84void NeuroFactory::removeUnimplemented()
85{
86SString removed;
87for(int i=0;i<Neuro::getClassCount();i++)
88        {
89        NeuroClass *nc=Neuro::getClass(i);
90        if (nc->impl_count==0)
91                {
92                removed+=nc->getName();
93                removed+=" ";
94                NeuroLibrary::staticlibrary.classes-=i;
95                i--;
96                delete nc;
97                }
98        }
99if (removed.len())
100        logPrintf("NeuroFactory","removeUninmplemented",LOG_INFO,
101         "Removed Neuro classes: %s",removed.c_str());
102}
103
Note: See TracBrowser for help on using the repository browser.