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

Last change on this file since 387 was 348, checked in by Maciej Komosinski, 10 years ago
  • explicit c_str() in SString instead of (const char*) cast
  • genetic converters and GenMan? are now thread-local which enables multi-threaded simulator separation
  • Property svn:eol-style set to native
File size: 1.9 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 <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{
12anode=NeuroLibrary::staticlibrary.classes.l_add.add(
13        STATRICKCALLBACK(this,&NeuroLibParam::neuroclassAdded,0));
14dnode=NeuroLibrary::staticlibrary.classes.l_postdel.add(
15        STATRICKCALLBACK(this,&NeuroLibParam::neuroclassRemoved,0));
16}
17
18NeuroLibParam::~NeuroLibParam()
19{
20NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia
21NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode);
22}
23
24void NeuroLibParam::neuroclassAdded(void* data,intptr_t i)
25{onadd.action(i);}
26void NeuroLibParam::neuroclassRemoved(void* data,intptr_t i)
27{ondelete.action(i);}
28
29static bool isGoodName(const SString& name)
30{
31for(int i=0;i<name.len();i++)
32        if (!isalnum(name[i])) return false;
33return true;
34}
35
36const char *NeuroLibParam::id(int i)
37{
38static SString t;
39if (i>=Neuro::getClassCount()) return 0;
40t=myprefix;
41SString n=Neuro::getClass(i)->getName();
42if (isGoodName(n))
43        t+=n;
44else
45        {//jezeli w nazwie klasy neuronu sa "dziwne" znaki to zamiast tego uzywamy long name
46        // * -> Constant, | -> Bend_muscle, @ -> Rotation_muscle
47        n=Neuro::getClass(i)->getLongName();
48        for(char* p=n.directWrite();*p;p++)
49                if (*p==' ') *p='_';
50        n.endWrite();
51        t+=n;
52        }
53return t.c_str();
54}
55
56const char *NeuroLibParam::name(int i)
57{
58static SString t;
59t=Neuro::getClass(i)->getLongName();
60t+=" ("; t+=Neuro::getClassName(i); t+=")";
61return t.c_str();
62}
63
64const char *NeuroLibParam::help(int i)
65{
66static SString t;
67t=Neuro::getClass(i)->getSummary();
68return t.c_str();
69}
70
71int NeuroLibParam::grmember(int gi,int n)
72{
73return (gi==0)?
74        ((n>=getPropCount())?-9999:n)
75        :
76        -9999;
77}
78
Note: See TracBrowser for help on using the repository browser.