- Timestamp:
- 05/29/18 15:46:35 (7 years ago)
- Location:
- cpp/frams/neuro
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/neuro/neurofactory.cpp
r375 r790 13 13 NeuroImpl* NeuroFactory::getImplementation(NeuroClass *nc) 14 14 { 15 if (nc!=NULL)15 if (nc != NULL) 16 16 { 17 std::map<NeuroClass*,NeuroImpl*>::iterator it=impl.find(nc);18 if (it!=impl.end())19 return it->second;17 std::map<NeuroClass*, NeuroImpl*>::iterator it = impl.find(nc); 18 if (it != impl.end()) 19 return it->second; 20 20 } 21 return NULL;21 return NULL; 22 22 } 23 23 24 24 NeuroImpl* NeuroFactory::createNeuroImpl(NeuroClass *nc) 25 25 { 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;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; 33 33 } 34 34 35 NeuroImpl* NeuroFactory::setImplementation(const SString& classname, NeuroImpl *ni,bool deleteold)35 NeuroImpl* NeuroFactory::setImplementation(const SString& classname, NeuroImpl *ni, bool deleteold) 36 36 { 37 NeuroClass *nc=Neuro::getClass(classname);38 if (!nc) return ni;39 return setImplementation(nc,ni,deleteold);37 NeuroClass *nc = Neuro::getClass(classname); 38 if (!nc) return ni; 39 return setImplementation(nc, ni, deleteold); 40 40 } 41 41 42 NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc, NeuroImpl *ni,bool deleteold)42 NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc, NeuroImpl *ni, bool deleteold) 43 43 { 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())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()) 48 48 { 49 if (ni!=NULL)49 if (ni != NULL) 50 50 { 51 impl[nc]=ni;52 nc->impl_count++;51 impl[nc] = ni; 52 nc->impl_count++; 53 53 } 54 return NULL;54 return NULL; 55 55 } 56 else56 else 57 57 { 58 old_ni=it->second;59 if (ni)60 it->second=ni;61 else58 old_ni = it->second; 59 if (ni) 60 it->second = ni; 61 else 62 62 { 63 impl.erase(it);64 nc->impl_count--;63 impl.erase(it); 64 nc->impl_count--; 65 65 } 66 66 } 67 if (deleteold && old_ni) delete old_ni;68 return old_ni;67 if (deleteold && old_ni) delete old_ni; 68 return old_ni; 69 69 } 70 70 … … 73 73 void NeuroFactory::setStandardImplementation() 74 74 { 75 SETIMPLEMENTATION75 SETIMPLEMENTATION 76 76 } 77 77 78 78 void NeuroFactory::freeImplementation() 79 79 { 80 for(int i=0;i<Neuro::getClassCount();i++)81 setImplementation(Neuro::getClass(i),0);80 for (int i = 0; i < Neuro::getClassCount(); i++) 81 setImplementation(Neuro::getClass(i), 0); 82 82 } 83 83 84 84 void NeuroFactory::removeUnimplemented() 85 85 { 86 SString removed;87 for(int i=0;i<Neuro::getClassCount();i++)86 SString removed; 87 for (int i = 0; i < Neuro::getClassCount(); i++) 88 88 { 89 NeuroClass *nc=Neuro::getClass(i);90 if (nc->impl_count==0)89 NeuroClass *nc = Neuro::getClass(i); 90 if (nc->impl_count == 0) 91 91 { 92 removed+=nc->getName();93 removed+=" ";94 NeuroLibrary::staticlibrary.classes-=i;95 i--;96 delete nc;92 removed += nc->getName(); 93 removed += " "; 94 NeuroLibrary::staticlibrary.classes -= i; 95 i--; 96 delete nc; 97 97 } 98 98 } 99 if (removed.len())100 logPrintf("NeuroFactory","removeUninmplemented",LOG_INFO,101 "Removed Neuro classes: %s",removed.c_str());99 if (removed.len()) 100 logPrintf("NeuroFactory", "removeUninmplemented", LOG_INFO, 101 "Removed Neuro classes: %s", removed.c_str()); 102 102 } 103 -
cpp/frams/neuro/neurofactory.h
r286 r790 13 13 class NeuroFactory 14 14 { 15 std::map<NeuroClass*,NeuroImpl*> impl;15 std::map<NeuroClass*, NeuroImpl*> impl; 16 16 public: 17 NeuroImpl* setImplementation(NeuroClass *nc,NeuroImpl *ni,bool deleteold=1); 18 NeuroImpl* setImplementation(const SString& classname,NeuroImpl *ni,bool deleteold=1); 19 NeuroImpl* getImplementation(NeuroClass *nc); 20 class NeuroImpl* createNeuroImpl(Neuro *n) 21 {NeuroClass *nc=n->getClass(); if (!nc) return 0; return createNeuroImpl(nc);} 22 class NeuroImpl* createNeuroImpl(NeuroClass *nc); 17 NeuroImpl* setImplementation(NeuroClass *nc, NeuroImpl *ni, bool deleteold = 1); 18 NeuroImpl* setImplementation(const SString& classname, NeuroImpl *ni, bool deleteold = 1); 19 NeuroImpl* getImplementation(NeuroClass *nc); 20 class NeuroImpl* createNeuroImpl(Neuro *n) 21 { 22 NeuroClass *nc = n->getClass(); if (!nc) return 0; return createNeuroImpl(nc); 23 } 24 class NeuroImpl* createNeuroImpl(NeuroClass *nc); 23 25 24 void setStandardImplementation();25 void freeImplementation();26 void removeUnimplemented();26 void setStandardImplementation(); 27 void freeImplementation(); 28 void removeUnimplemented(); 27 29 }; 28 30 -
cpp/frams/neuro/neuroimplfiles-SDK.h
r288 r790 14 14 #include "impl/neuroimpl-vmot.hpp" 15 15 #endif 16 -
cpp/frams/neuro/neurolibparam.cpp
r348 r790 8 8 9 9 NeuroLibParam::NeuroLibParam(const char* gr, const char* name, const char* pref) 10 :mygroup(gr), myname(name),myprefix(pref)10 :mygroup(gr), myname(name), myprefix(pref) 11 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));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 16 } 17 17 18 18 NeuroLibParam::~NeuroLibParam() 19 19 { 20 NeuroLibrary::staticlibrary.classes.l_add.removeNode(anode);// remove(anode) tez powinno byc ok - do sprawdzenia21 NeuroLibrary::staticlibrary.classes.l_postdel.removeNode(dnode);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 22 } 23 23 24 void NeuroLibParam::neuroclassAdded(void* data,intptr_t i) 25 {onadd.action(i);} 26 void NeuroLibParam::neuroclassRemoved(void* data,intptr_t i) 27 {ondelete.action(i);} 24 void NeuroLibParam::neuroclassAdded(void* data, intptr_t i) 25 { 26 onadd.action(i); 27 } 28 void NeuroLibParam::neuroclassRemoved(void* data, intptr_t i) 29 { 30 ondelete.action(i); 31 } 28 32 29 33 static bool isGoodName(const SString& name) 30 34 { 31 for(int i=0;i<name.len();i++)32 if (!isalnum(name[i])) return false;33 return true;35 for (int i = 0; i < name.len(); i++) 36 if (!isalnum(name[i])) return false; 37 return true; 34 38 } 35 39 36 40 const char *NeuroLibParam::id(int i) 37 41 { 38 static SString t;39 if (i>=Neuro::getClassCount()) return 0;40 t=myprefix;41 SString n=Neuro::getClass(i)->getName();42 if (isGoodName(n))43 t+=n;44 else42 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 45 49 {//jezeli w nazwie klasy neuronu sa "dziwne" znaki to zamiast tego uzywamy long name 46 // * -> Constant, | -> Bend_muscle, @ -> Rotation_muscle47 n=Neuro::getClass(i)->getLongName();48 for(char* p=n.directWrite();*p;p++)49 if (*p==' ') *p='_';50 n.endWrite();51 t+=n;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; 52 56 } 53 return t.c_str();57 return t.c_str(); 54 58 } 55 59 56 60 const char *NeuroLibParam::name(int i) 57 61 { 58 static SString t;59 t=Neuro::getClass(i)->getLongName();60 t+=" ("; t+=Neuro::getClassName(i); t+=")";61 return t.c_str();62 static SString t; 63 t = Neuro::getClass(i)->getLongName(); 64 t += " ("; t += Neuro::getClassName(i); t += ")"; 65 return t.c_str(); 62 66 } 63 67 64 68 const char *NeuroLibParam::help(int i) 65 69 { 66 static SString t;67 t=Neuro::getClass(i)->getSummary();68 return t.c_str();70 static SString t; 71 t = Neuro::getClass(i)->getSummary(); 72 return t.c_str(); 69 73 } 70 74 71 int NeuroLibParam::grmember(int gi, int n)75 int NeuroLibParam::grmember(int gi, int n) 72 76 { 73 return (gi==0)?74 ((n>=getPropCount())?-9999:n)75 :76 -9999;77 return (gi == 0) ? 78 ((n >= getPropCount()) ? -9999 : n) 79 : 80 -9999; 77 81 } 78 -
cpp/frams/neuro/neurolibparam.h
r286 r790 9 9 #include <frams/model/modelparts.h> 10 10 11 class NeuroLibParam : public MutableParamInterface11 class NeuroLibParam : public MutableParamInterface 12 12 { 13 const char* mygroup;14 const char* myname;15 const char* myprefix;16 CallbackNode *anode,*dnode;13 const char* mygroup; 14 const char* myname; 15 const char* myprefix; 16 CallbackNode *anode, *dnode; 17 17 18 19 NeuroLibParam(const char* gr=0, const char* name=0, const char* pref=0);20 ~NeuroLibParam();18 public: 19 NeuroLibParam(const char* gr = 0, const char* name = 0, const char* pref = 0); 20 ~NeuroLibParam(); 21 21 22 22 #define STATRICKCLASS NeuroLibParam 23 VIRTCALLBACKDEF(neuroclassAdded);24 VIRTCALLBACKDEF(neuroclassRemoved);23 VIRTCALLBACKDEF(neuroclassAdded); 24 VIRTCALLBACKDEF(neuroclassRemoved); 25 25 #undef STATRICKCLASS 26 26 27 int getGroupCount() {return 1;}28 int getPropCount() {return Neuro::getClassCount();}27 int getGroupCount() { return 1; } 28 int getPropCount() { return Neuro::getClassCount(); } 29 29 30 const char* getName() {return myname;}31 const char *grname(int gi) {return (gi==0)?mygroup:0;}30 const char* getName() { return myname; } 31 const char *grname(int gi) { return (gi == 0) ? mygroup : 0; } 32 32 33 const char *id(int i);34 const char *name(int i);35 const char *help(int i);36 const char *type(int i) {return "d 0 1";}37 int flags(int i) {return 0;}38 int group(int i) {return 0;}39 int grmember(int gi,int n);40 void call(int i,ExtValue* args,ExtValue *ret) {}33 const char *id(int i); 34 const char *name(int i); 35 const char *help(int i); 36 const char *type(int i) { return "d 0 1"; } 37 int flags(int i) { return 0; } 38 int group(int i) { return 0; } 39 int grmember(int gi, int n); 40 void call(int i, ExtValue* args, ExtValue *ret) {} 41 41 42 SString getString(int i) {return SString();}43 double getDouble(int) {return 0;}44 ExtObject getObject(int i) {return ExtObject();}45 ExtValue getExtValue(int i) {return ExtValue();}46 int setDouble(int i, double) {return 0;}47 int setString(int i, const SString &v) {return 0;}48 int setObject(int i, const ExtObject &v) {return 0;}49 int setExtValue(int i, const ExtValue &v) {return 0;}42 SString getString(int i) { return SString(); } 43 double getDouble(int) { return 0; } 44 ExtObject getObject(int i) { return ExtObject(); } 45 ExtValue getExtValue(int i) { return ExtValue(); } 46 int setDouble(int i, double) { return 0; } 47 int setString(int i, const SString &v) { return 0; } 48 int setObject(int i, const ExtObject &v) { return 0; } 49 int setExtValue(int i, const ExtValue &v) { return 0; } 50 50 }; 51 51 -
cpp/frams/neuro/neurolibrary.cpp
r286 r790 11 11 int NeuroLibrary::findClassIndex(const SString & classname, bool activeonly) 12 12 { 13 NeuroClass* cl;14 for(int i=0;cl=(NeuroClass*)classes(i);i++)13 NeuroClass* cl; 14 for (int i = 0; cl = (NeuroClass*)classes(i); i++) 15 15 { 16 if (activeonly && !cl->active) continue;17 if (classname == cl->getName()) return i;16 if (activeonly && !cl->active) continue; 17 if (classname == cl->getName()) return i; 18 18 } 19 return -1;19 return -1; 20 20 } 21 21 22 22 NeuroClass* NeuroLibrary::findClass(const SString & classname, bool activeonly) 23 23 { 24 int i=findClassIndex(classname,activeonly);25 if (i<0) return 0;26 return getClass(i);24 int i = findClassIndex(classname, activeonly); 25 if (i < 0) return 0; 26 return getClass(i); 27 27 } 28 28 29 29 SString NeuroLibrary::getClassName(int classindex) 30 30 { 31 NeuroClass *cl=getClass(classindex);32 return cl? cl->getName() : SString();31 NeuroClass *cl = getClass(classindex); 32 return cl ? cl->getName() : SString(); 33 33 } 34 34 35 NeuroClass *NeuroLibrary::addClass(NeuroClass *cls, bool replace)35 NeuroClass *NeuroLibrary::addClass(NeuroClass *cls, bool replace) 36 36 { 37 NeuroClass *old=findClass(cls->getName());38 if (old)37 NeuroClass *old = findClass(cls->getName()); 38 if (old) 39 39 { 40 if (replace)40 if (replace) 41 41 { 42 classes-=old;43 classes+=cls;42 classes -= old; 43 classes += cls; 44 44 } 45 45 } 46 else47 classes+=cls;48 return old;46 else 47 classes += cls; 48 return old; 49 49 } 50 50 … … 56 56 NeuroLibrary::NeuroLibrary() 57 57 { 58 addStandardClasses();58 addStandardClasses(); 59 59 } 60 60 61 61 NeuroLibrary::~NeuroLibrary() 62 62 { 63 FOREACH(NeuroClass*,cl,classes)64 delete cl;63 FOREACH(NeuroClass*, cl, classes) 64 delete cl; 65 65 } 66 66 67 67 void NeuroLibrary::removeClass(int i) 68 68 { 69 classes-=i;69 classes -= i; 70 70 } 71 71 72 72 void NeuroLibrary::clear() 73 73 { 74 while(getClassCount()>0)75 removeClass(getClassCount()-1);74 while (getClassCount() > 0) 75 removeClass(getClassCount() - 1); 76 76 } 77 -
cpp/frams/neuro/neurolibrary.h
r286 r790 13 13 class NeuroLibrary 14 14 { 15 16 static NeuroLibrary staticlibrary;17 NeuroLibrary();18 ~NeuroLibrary();19 AdvList classes;20 NeuroClass* findClass(const SString& classname, bool activeonly=1);21 void addStandardClasses();22 int findClassIndex(const SString& classname, bool activeonly=1);23 NeuroClass* getClass(int classindex) {return (NeuroClass*)classes(classindex);}24 SString getClassName(int classindex);25 int getClassCount() {return classes.size();}26 void removeClass(int i);27 void clear();28 NeuroClass *addClass(NeuroClass *cls,bool replace=1);15 public: 16 static NeuroLibrary staticlibrary; 17 NeuroLibrary(); 18 ~NeuroLibrary(); 19 AdvList classes; 20 NeuroClass* findClass(const SString& classname, bool activeonly = 1); 21 void addStandardClasses(); 22 int findClassIndex(const SString& classname, bool activeonly = 1); 23 NeuroClass* getClass(int classindex) { return (NeuroClass*)classes(classindex); } 24 SString getClassName(int classindex); 25 int getClassCount() { return classes.size(); } 26 void removeClass(int i); 27 void clear(); 28 NeuroClass *addClass(NeuroClass *cls, bool replace = 1); 29 29 }; 30 30
Note: See TracChangeset
for help on using the changeset viewer.