source: cpp/frams/neuro/neurolibparam.cpp @ 1314

Last change on this file since 1314 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.0 KB
RevLine 
[286]1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
[973]2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
[286]3// See LICENSE.txt for details.
[138]4
5#include <ctype.h>
6#include "neurolibparam.h"
7#include <frams/neuro/neurolibrary.h>
8
9NeuroLibParam::NeuroLibParam(const char* gr, const char* name, const char* pref)
[790]10        :mygroup(gr), myname(name), myprefix(pref)
[138]11{
[790]12        anode = NeuroLibrary::staticlibrary.classes.l_add.add(
13                STATRICKCALLBACK(this, &NeuroLibParam::neuroclassAdded, 0));
14        dnode = NeuroLibrary::staticlibrary.classes.l_postdel.add(
15                STATRICKCALLBACK(this, &NeuroLibParam::neuroclassRemoved, 0));
[138]16}
17
18NeuroLibParam::~NeuroLibParam()
19{
[790]20        NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia
21        NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode);
[138]22}
23
[790]24void NeuroLibParam::neuroclassAdded(void* data, intptr_t i)
25{
26        onadd.action(i);
27}
28void NeuroLibParam::neuroclassRemoved(void* data, intptr_t i)
29{
30        ondelete.action(i);
31}
[138]32
33static bool isGoodName(const SString& name)
34{
[973]35        for (int i = 0; i < name.length(); i++)
[790]36                if (!isalnum(name[i])) return false;
37        return true;
[138]38}
39
40const char *NeuroLibParam::id(int i)
41{
[790]42        static SString t;
43        if (i >= Neuro::getClassCount()) return 0;
44        t = myprefix;
45        SString n = Neuro::getClass(i)->getName();
46        if (isGoodName(n))
47                t += n;
48        else
[138]49        {//jezeli w nazwie klasy neuronu sa "dziwne" znaki to zamiast tego uzywamy long name
[790]50                // * -> Constant, | -> Bend_muscle, @ -> Rotation_muscle
51                n = Neuro::getClass(i)->getLongName();
52                for (char* p = n.directWrite(); *p; p++)
53                        if (*p == ' ') *p = '_';
54                n.endWrite();
55                t += n;
[138]56        }
[790]57        return t.c_str();
[138]58}
59
60const char *NeuroLibParam::name(int i)
61{
[790]62        static SString t;
63        t = Neuro::getClass(i)->getLongName();
64        t += " ("; t += Neuro::getClassName(i); t += ")";
65        return t.c_str();
[138]66}
67
68const char *NeuroLibParam::help(int i)
69{
[790]70        static SString t;
71        t = Neuro::getClass(i)->getSummary();
72        return t.c_str();
[138]73}
74
[790]75int NeuroLibParam::grmember(int gi, int n)
[138]76{
[790]77        return (gi == 0) ?
78                ((n >= getPropCount()) ? -9999 : n)
79                :
80                -9999;
[138]81}
Note: See TracBrowser for help on using the repository browser.