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

Last change on this file since 1316 was 973, checked in by Maciej Komosinski, 4 years ago

Increased SString and std::string compatibility: introduced length(), size(), and capacity(), and removed legacy methods that have std::string equivalents

  • Property svn:eol-style set to native
File size: 2.4 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[933]2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
[286]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
[933]24NeuroImpl* NeuroFactory::createNeuroImpl(NeuroClass *nc, Model::ShapeType shape_type)
[109]25{
[790]26        if (!nc) return 0;
27        if (!nc->active) return 0;
[935]28        if (!(nc->isShapeTypeSupported(shape_type)))
[933]29        {
30                logPrintf("NeuroFactory", "createNeuroImpl", LOG_WARN,
31                        "Neuro class '%s' does not support shape type '%d'", nc->name.c_str(), (int)shape_type);
32                return NULL;
33        }
[790]34        NeuroImpl* ni = getImplementation(nc);
35        if (!ni) return 0;
36        ni = ni->makeNew();
37        if (ni) ni->neuroclass = nc;
38        return ni;
[109]39}
40
[790]41NeuroImpl* NeuroFactory::setImplementation(const SString& classname, NeuroImpl *ni, bool deleteold)
[109]42{
[790]43        NeuroClass *nc = Neuro::getClass(classname);
44        if (!nc) return ni;
45        return setImplementation(nc, ni, deleteold);
[109]46}
47
[790]48NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc, NeuroImpl *ni, bool deleteold)
[109]49{
[790]50        if (nc == NULL) return NULL;
51        std::map<NeuroClass*, NeuroImpl*>::iterator it = impl.find(nc);
52        NeuroImpl* old_ni = NULL;
53        if (it == impl.end())
[109]54        {
[790]55                if (ni != NULL)
[109]56                {
[790]57                        impl[nc] = ni;
58                        nc->impl_count++;
[109]59                }
[790]60                return NULL;
[109]61        }
[790]62        else
[109]63        {
[790]64                old_ni = it->second;
65                if (ni)
66                        it->second = ni;
67                else
[109]68                {
[790]69                        impl.erase(it);
70                        nc->impl_count--;
[109]71                }
72        }
[790]73        if (deleteold && old_ni) delete old_ni;
74        return old_ni;
[109]75}
76
77#include NEURO_CLS_FACTORY
78
79void NeuroFactory::setStandardImplementation()
80{
[790]81        SETIMPLEMENTATION
[109]82}
83
84void NeuroFactory::freeImplementation()
85{
[790]86        for (int i = 0; i < Neuro::getClassCount(); i++)
87                setImplementation(Neuro::getClass(i), 0);
[109]88}
89
90void NeuroFactory::removeUnimplemented()
91{
[790]92        SString removed;
93        for (int i = 0; i < Neuro::getClassCount(); i++)
[109]94        {
[790]95                NeuroClass *nc = Neuro::getClass(i);
96                if (nc->impl_count == 0)
[109]97                {
[790]98                        removed += nc->getName();
99                        removed += " ";
100                        NeuroLibrary::staticlibrary.classes -= i;
101                        i--;
102                        delete nc;
[109]103                }
104        }
[973]105        if (removed.length())
[790]106                logPrintf("NeuroFactory", "removeUninmplemented", LOG_INFO,
[933]107                        "Removed Neuro classes: %s", removed.c_str());
[109]108}
Note: See TracBrowser for help on using the repository browser.