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

Last change on this file since 1064 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
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
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)
10        :mygroup(gr), myname(name), myprefix(pref)
11{
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));
16}
17
18NeuroLibParam::~NeuroLibParam()
19{
20        NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia
21        NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode);
22}
23
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}
32
33static bool isGoodName(const SString& name)
34{
35        for (int i = 0; i < name.length(); i++)
36                if (!isalnum(name[i])) return false;
37        return true;
38}
39
40const char *NeuroLibParam::id(int i)
41{
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
49        {//jezeli w nazwie klasy neuronu sa "dziwne" znaki to zamiast tego uzywamy long name
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;
56        }
57        return t.c_str();
58}
59
60const char *NeuroLibParam::name(int i)
61{
62        static SString t;
63        t = Neuro::getClass(i)->getLongName();
64        t += " ("; t += Neuro::getClassName(i); t += ")";
65        return t.c_str();
66}
67
68const char *NeuroLibParam::help(int i)
69{
70        static SString t;
71        t = Neuro::getClass(i)->getSummary();
72        return t.c_str();
73}
74
75int NeuroLibParam::grmember(int gi, int n)
76{
77        return (gi == 0) ?
78                ((n >= getPropCount()) ? -9999 : n)
79                :
80                -9999;
81}
Note: See TracBrowser for help on using the repository browser.