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

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

Code formatting

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