- Timestamp:
- 07/23/13 18:15:30 (11 years ago)
- Location:
- cpp/gdk
- Files:
-
- 10 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/gdk/Makefile
r89 r104 14 14 # defassign-f0_neuroconn.h f0def.xml neurocls-library.h neurocls-factory.h model.def 15 15 16 TARGETS=convtest gdktest genotest neurotest loadertest f0def.xml model.def16 TARGETS=convtest gdktest genotest neurotest loadertest serialtest f0def.xml model.def 17 17 18 18 all: $(TARGETS) … … 28 28 GDKOBJS=list.o advlist.o param.o sstring.o 3d.o model.o modelparts.o errmanager.o \ 29 29 neurolibrary.o geno.o genoconv.o extvalue.o framsg.o callbacks.o syntparam.o \ 30 multirange.o multimap.o paramtabobj.o defgenoconv.o sstringutils.o paramobj.o rndutil.o \ 30 multirange.o multimap.o paramtabobj.o defgenoconv.o sstringutils.o paramobj.o \ 31 rndutil.o collectionobj.o hashtable.o stderrors.o 3dobject.o \ 31 32 $(CONVMODULES) 32 33 … … 58 59 loadertest: libgdk.a $(LOADERTESTOBJS) 59 60 g++ $(LOADERTESTOBJS) -L. -lgdk -o $@ 61 62 SERIALTESTOBJS=serialtest.o virtfile.o stdiofile-autoinit.o stdiofile.o nonstd_stdio.o 63 64 serialtest: libgdk.a $(SERIALTESTOBJS) 65 g++ $(SERIALTESTOBJS) -L. -lgdk -o $@ 60 66 61 67 neurocls-library.h: f0.def neurocls-library.m4 … … 103 109 # DO NOT DELETE 104 110 105 3d.o: nonstd.h 3d.h framsg.h 111 3d.o: nonstd_math.h framsg.h 3d.h 112 3dobject.o: 3d.h 3dobject.h extvalue.h sstring.h param.h list.h nonstd.h 113 3dobject.o: statrick.h virtfile.h framsg.h nonstd_stl.h threads.h 114 3dobject.o: collectionobj.h hashtable.h 106 115 advlist.o: advlist.h list.h nonstd.h callbacks.h statrick.h 107 116 callbacks.o: callbacks.h list.h nonstd.h statrick.h 117 collectionobj.o: collectionobj.h param.h sstring.h list.h nonstd.h statrick.h 118 collectionobj.o: virtfile.h framsg.h extvalue.h nonstd_stl.h threads.h 119 collectionobj.o: hashtable.h 3d.h nonstd_math.h stderrors.h sstringutils.h 108 120 conv_f1.o: conv_f1.h genoconv.h geno.h sstring.h extvalue.h param.h list.h 109 conv_f1.o: nonstd.h statrick.h virtfile.h model.h modelparts.h 3d.h 110 conv_f1.o: sstringutils.h syntparam.h usertags.h paramtabobj.h advlist.h 111 conv_f1.o: callbacks.h framsg.h multirange.h multimap.h 121 conv_f1.o: nonstd.h statrick.h virtfile.h framsg.h nonstd_stl.h threads.h 122 conv_f1.o: model.h nonstd_math.h modelparts.h 3d.h sstringutils.h syntparam.h 123 conv_f1.o: usertags.h paramtabobj.h advlist.h callbacks.h multirange.h 124 conv_f1.o: multimap.h 112 125 convtest.o: genoconv.h geno.h sstring.h extvalue.h param.h list.h nonstd.h 113 convtest.o: statrick.h virtfile.h model.h modelparts.h 3d.h sstringutils.h114 convtest.o: syntparam.h usertags.h paramtabobj.h advlist.h callbacks.h115 convtest.o: multimap.h multirange.h conv_f1.h printconvmap.h stdouterr.h116 convtest.o: errmanager.h framsg.h126 convtest.o: statrick.h virtfile.h framsg.h nonstd_stl.h threads.h model.h 127 convtest.o: nonstd_math.h modelparts.h 3d.h sstringutils.h syntparam.h 128 convtest.o: usertags.h paramtabobj.h advlist.h callbacks.h multimap.h 129 convtest.o: multirange.h conv_f1.h printconvmap.h stdouterr.h errmanager.h 117 130 defgenoconv.o: defgenoconv.h genoconv.h geno.h sstring.h extvalue.h param.h 118 defgenoconv.o: list.h nonstd.h statrick.h virtfile.h gen-config.h conv_f1.h 119 defgenoconv.o: model.h modelparts.h 3d.h sstringutils.h syntparam.h 120 defgenoconv.o: usertags.h paramtabobj.h advlist.h callbacks.h 121 errmanager.o: errmanager.h list.h nonstd.h sstring.h framsg.h 131 defgenoconv.o: list.h nonstd.h statrick.h virtfile.h framsg.h nonstd_stl.h 132 defgenoconv.o: threads.h 133 errmanager.o: errmanager.h list.h nonstd.h sstring.h framsg.h threads.h 122 134 extvalue.o: extvalue.h sstring.h param.h list.h nonstd.h statrick.h 123 extvalue.o: virtfile.h framsg.h 124 framsg.o: nonstd.h framsg.h 125 gdktest.o: model.h modelparts.h 3d.h genoconv.h geno.h sstring.h extvalue.h 126 gdktest.o: param.h list.h nonstd.h statrick.h virtfile.h sstringutils.h 127 gdktest.o: syntparam.h usertags.h paramtabobj.h advlist.h callbacks.h 128 gdktest.o: defgenoconv.h stdouterr.h errmanager.h framsg.h 135 extvalue.o: virtfile.h framsg.h nonstd_stl.h threads.h sstringutils.h 136 extvalue.o: collectionobj.h hashtable.h 3d.h 3dobject.h 137 framsg.o: framsg.h nonstd_stdio.h 138 fullprops.o: stdiofile.h virtfile.h sstring.h nonstd_dir.h model.h 139 fullprops.o: nonstd_math.h modelparts.h 3d.h genoconv.h geno.h extvalue.h 140 fullprops.o: param.h list.h nonstd.h statrick.h framsg.h nonstd_stl.h 141 fullprops.o: threads.h sstringutils.h syntparam.h usertags.h paramtabobj.h 142 fullprops.o: advlist.h callbacks.h defgenoconv.h stdouterr.h errmanager.h 143 gdktest.o: stdiofile.h virtfile.h sstring.h nonstd_dir.h model.h 144 gdktest.o: nonstd_math.h modelparts.h 3d.h genoconv.h geno.h extvalue.h 145 gdktest.o: param.h list.h nonstd.h statrick.h framsg.h nonstd_stl.h threads.h 146 gdktest.o: sstringutils.h syntparam.h usertags.h paramtabobj.h advlist.h 147 gdktest.o: callbacks.h defgenoconv.h stdouterr.h errmanager.h 129 148 genoconv.o: nonstd.h genoconv.h geno.h sstring.h extvalue.h param.h list.h 130 genoconv.o: statrick.h virtfile.h multimap.h multirange.h 149 genoconv.o: statrick.h virtfile.h framsg.h nonstd_stl.h threads.h multimap.h 150 genoconv.o: multirange.h 131 151 geno.o: geno.h sstring.h extvalue.h param.h list.h nonstd.h statrick.h 132 geno.o: virtfile.h genoconv.h model.h modelparts.h 3d.h sstringutils.h 133 geno.o: syntparam.h usertags.h paramtabobj.h advlist.h callbacks.h 152 geno.o: virtfile.h framsg.h nonstd_stl.h threads.h genoconv.h model.h 153 geno.o: nonstd_math.h modelparts.h 3d.h sstringutils.h syntparam.h usertags.h 154 geno.o: paramtabobj.h advlist.h callbacks.h 134 155 genotest.o: geno.h sstring.h extvalue.h param.h list.h nonstd.h statrick.h 135 genotest.o: virtfile.h genoconv.h stdiofile.h sstringutils.h defgenoconv.h 156 genotest.o: virtfile.h framsg.h nonstd_stl.h threads.h genoconv.h stdiofile.h 157 genotest.o: nonstd_dir.h sstringutils.h defgenoconv.h 136 158 genotypeloader.o: genotypeloader.h sstring.h multiparamload.h param.h list.h 137 genotypeloader.o: nonstd.h statrick.h virtfile.h 159 genotypeloader.o: nonstd.h statrick.h virtfile.h framsg.h extvalue.h 160 genotypeloader.o: nonstd_stl.h threads.h 161 hashtable.o: hashtable.h sstring.h 138 162 list.o: list.h nonstd.h 139 163 loadertest.o: genotypeloader.h sstring.h multiparamload.h param.h list.h 140 loadertest.o: nonstd.h statrick.h virtfile.h 141 model.o: nonstd.h model.h modelparts.h 3d.h genoconv.h geno.h sstring.h 142 model.o: extvalue.h param.h list.h statrick.h virtfile.h sstringutils.h 143 model.o: syntparam.h usertags.h paramtabobj.h advlist.h callbacks.h framsg.h 144 model.o: multimap.h multirange.h errmanager.h 164 loadertest.o: nonstd.h statrick.h virtfile.h framsg.h extvalue.h nonstd_stl.h 165 loadertest.o: threads.h 166 model.o: nonstd_math.h model.h modelparts.h 3d.h genoconv.h geno.h sstring.h 167 model.o: extvalue.h param.h list.h nonstd.h statrick.h virtfile.h framsg.h 168 model.o: nonstd_stl.h threads.h sstringutils.h syntparam.h usertags.h 169 model.o: paramtabobj.h advlist.h callbacks.h multimap.h multirange.h 170 model.o: errmanager.h 145 171 modelparts.o: modelparts.h 3d.h genoconv.h geno.h sstring.h extvalue.h 146 modelparts.o: param.h list.h nonstd.h statrick.h virtfile.h sstringutils.h 147 modelparts.o: syntparam.h usertags.h paramtabobj.h model.h advlist.h 148 modelparts.o: callbacks.h neurolibrary.h multirange.h defassign-f0_neuro.h 172 modelparts.o: param.h list.h nonstd.h statrick.h virtfile.h framsg.h 173 modelparts.o: nonstd_stl.h threads.h sstringutils.h syntparam.h usertags.h 174 modelparts.o: paramtabobj.h model.h nonstd_math.h advlist.h callbacks.h 175 modelparts.o: neurolibrary.h multirange.h defassign-f0_neuro.h 149 176 modelparts.o: defassign-f0_part.h defassign-f0_joint.h f0classes.h 150 177 modelparts.o: defassign-f0_neuroconn.h 151 178 multimap.o: multimap.h multirange.h list.h nonstd.h 152 179 multiparamload.o: multiparamload.h param.h sstring.h list.h nonstd.h 153 multiparamload.o: statrick.h virtfile.h framsg.h 154 multirange.o: multirange.h list.h nonstd.h 180 multiparamload.o: statrick.h virtfile.h framsg.h extvalue.h nonstd_stl.h 181 multiparamload.o: threads.h 182 multirange.o: multirange.h list.h nonstd.h nonstd_stl.h 155 183 neurofactory.o: neurofactory.h modelparts.h 3d.h genoconv.h geno.h sstring.h 156 184 neurofactory.o: extvalue.h param.h list.h nonstd.h statrick.h virtfile.h 157 neurofactory.o: sstringutils.h syntparam.h usertags.h paramtabobj.h 158 neurofactory.o: neuroimpl.h model.h advlist.h callbacks.h framsg.h 159 neurofactory.o: neuroimplfiles.h neuroimpl-simple.h neuroimpl-channels.h 160 neurofactory.o: neuroimpl-fuzzy.h neuroimpl-body-gdk.h neurocls-factory.h 161 neuroimpl-channels.o: neuroimpl-channels.h neuroimpl.h model.h modelparts.h 162 neuroimpl-channels.o: 3d.h genoconv.h geno.h sstring.h extvalue.h param.h 163 neuroimpl-channels.o: list.h nonstd.h statrick.h virtfile.h sstringutils.h 164 neuroimpl-channels.o: syntparam.h usertags.h paramtabobj.h advlist.h 165 neuroimpl-channels.o: callbacks.h framsg.h 166 neuroimpl.o: neuroimpl.h model.h modelparts.h 3d.h genoconv.h geno.h 167 neuroimpl.o: sstring.h extvalue.h param.h list.h nonstd.h statrick.h 168 neuroimpl.o: virtfile.h sstringutils.h syntparam.h usertags.h paramtabobj.h 169 neuroimpl.o: advlist.h callbacks.h framsg.h neurofactory.h 170 neuroimpl-fuzzy.o: neuroimpl-fuzzy.h neuroimpl.h model.h modelparts.h 3d.h 171 neuroimpl-fuzzy.o: genoconv.h geno.h sstring.h extvalue.h param.h list.h 172 neuroimpl-fuzzy.o: nonstd.h statrick.h virtfile.h sstringutils.h syntparam.h 173 neuroimpl-fuzzy.o: usertags.h paramtabobj.h advlist.h callbacks.h framsg.h 185 neurofactory.o: framsg.h nonstd_stl.h threads.h sstringutils.h syntparam.h 186 neurofactory.o: usertags.h paramtabobj.h neuroimpl.h model.h nonstd_math.h 187 neurofactory.o: advlist.h callbacks.h neurolibrary.h 188 neuroimpl-channels.o: neuroimpl-channels.h neuroimpl.h model.h nonstd_math.h 189 neuroimpl-channels.o: modelparts.h 3d.h genoconv.h geno.h sstring.h 190 neuroimpl-channels.o: extvalue.h param.h list.h nonstd.h statrick.h 191 neuroimpl-channels.o: virtfile.h framsg.h nonstd_stl.h threads.h 192 neuroimpl-channels.o: sstringutils.h syntparam.h usertags.h paramtabobj.h 193 neuroimpl-channels.o: advlist.h callbacks.h 194 neuroimpl.o: neuroimpl.h model.h nonstd_math.h modelparts.h 3d.h genoconv.h 195 neuroimpl.o: geno.h sstring.h extvalue.h param.h list.h nonstd.h statrick.h 196 neuroimpl.o: virtfile.h framsg.h nonstd_stl.h threads.h sstringutils.h 197 neuroimpl.o: syntparam.h usertags.h paramtabobj.h advlist.h callbacks.h 198 neuroimpl.o: neurofactory.h rndutil.h 199 neuroimpl-fuzzy.o: neuroimpl-fuzzy.h neuroimpl.h model.h nonstd_math.h 200 neuroimpl-fuzzy.o: modelparts.h 3d.h genoconv.h geno.h sstring.h extvalue.h 201 neuroimpl-fuzzy.o: param.h list.h nonstd.h statrick.h virtfile.h framsg.h 202 neuroimpl-fuzzy.o: nonstd_stl.h threads.h sstringutils.h syntparam.h 203 neuroimpl-fuzzy.o: usertags.h paramtabobj.h advlist.h callbacks.h 174 204 neuroimpl-fuzzy.o: neuroimpl-fuzzy-f0.h 175 neuroimpl-fuzzy-f0.o: neuroimpl-fuzzy-f0.h sstring.h nonstd.h 176 neuroimpl-simple.o: neuroimpl-simple.h neuroimpl.h model.h modelparts.h 3d.h 177 neuroimpl-simple.o: genoconv.h geno.h sstring.h extvalue.h param.h list.h 178 neuroimpl-simple.o: nonstd.h statrick.h virtfile.h sstringutils.h syntparam.h 179 neuroimpl-simple.o: usertags.h paramtabobj.h advlist.h callbacks.h framsg.h 205 neuroimpl-fuzzy-f0.o: neuroimpl-fuzzy-f0.h sstring.h nonstd_stl.h 206 neuroimpl-simple.o: neuroimpl-simple.h neuroimpl.h model.h nonstd_math.h 207 neuroimpl-simple.o: modelparts.h 3d.h genoconv.h geno.h sstring.h extvalue.h 208 neuroimpl-simple.o: param.h list.h nonstd.h statrick.h virtfile.h framsg.h 209 neuroimpl-simple.o: nonstd_stl.h threads.h sstringutils.h syntparam.h 210 neuroimpl-simple.o: usertags.h paramtabobj.h advlist.h callbacks.h 180 211 neurolibrary.o: neurolibrary.h advlist.h list.h nonstd.h callbacks.h 181 neurolibrary.o: statrick.h param.h sstring.h virtfile.h modelparts.h 3d.h182 neurolibrary.o: genoconv.h geno.h extvalue.h sstringutils.h syntparam.h183 neurolibrary.o: usertags.h paramtabobj.h neurocls-library.h212 neurolibrary.o: statrick.h param.h sstring.h virtfile.h framsg.h modelparts.h 213 neurolibrary.o: 3d.h genoconv.h geno.h extvalue.h nonstd_stl.h threads.h 214 neurolibrary.o: sstringutils.h syntparam.h usertags.h paramtabobj.h 184 215 neurotest.o: geno.h sstring.h extvalue.h param.h list.h nonstd.h statrick.h 185 neurotest.o: virtfile.h genoconv.h stdiofile.h sstringutils.h defgenoconv.h 186 neurotest.o: neuroimpl.h model.h modelparts.h 3d.h syntparam.h usertags.h 187 neurotest.o: paramtabobj.h advlist.h callbacks.h framsg.h neurofactory.h 216 neurotest.o: virtfile.h framsg.h nonstd_stl.h threads.h genoconv.h 217 neurotest.o: stdiofile.h nonstd_dir.h sstringutils.h defgenoconv.h 218 neurotest.o: neuroimpl.h model.h nonstd_math.h modelparts.h 3d.h syntparam.h 219 neurotest.o: usertags.h paramtabobj.h advlist.h callbacks.h neurofactory.h 188 220 neurotest.o: stdouterr.h errmanager.h 189 param.o: param.h sstring.h list.h nonstd.h statrick.h virtfile.h extvalue.h 190 param.o: framsg.h sstringutils.h 221 nonstd_stdio.o: nonstd_stdio.h 222 param.o: param.h sstring.h list.h nonstd.h statrick.h virtfile.h framsg.h 223 param.o: extvalue.h nonstd_stl.h threads.h sstringutils.h 191 224 paramobj.o: paramobj.h param.h sstring.h list.h nonstd.h statrick.h 192 paramobj.o: virtfile.h extvalue.h225 paramobj.o: virtfile.h framsg.h extvalue.h nonstd_stl.h threads.h 193 226 paramtabobj.o: paramtabobj.h param.h sstring.h list.h nonstd.h statrick.h 194 paramtabobj.o: virtfile.h 227 paramtabobj.o: virtfile.h framsg.h 195 228 printconvmap.o: printconvmap.h sstring.h multimap.h multirange.h list.h 196 229 printconvmap.o: nonstd.h 197 sstring.o: sstring.h nonstd.h 230 rndutil.o: rndutil.h nonstd.h nonstd_math.h 231 serialtest.o: collectionobj.h param.h sstring.h list.h nonstd.h statrick.h 232 serialtest.o: virtfile.h framsg.h extvalue.h nonstd_stl.h threads.h 233 serialtest.o: hashtable.h 3d.h 234 sstring.o: sstring.h nonstd_stl.h extvalue.h param.h list.h nonstd.h 235 sstring.o: statrick.h virtfile.h framsg.h threads.h 198 236 sstringutils.o: sstringutils.h sstring.h virtfile.h framsg.h 199 stdiofile-autoinit.o: stdiofile.h virtfile.h sstring.h 200 stdiofile.o: stdiofile.h virtfile.h sstring.h nonstd.h nonstd_io.h 237 stderrors.o: stderrors.h list.h nonstd.h sstring.h sstringutils.h virtfile.h 238 stderrors.o: framsg.h 239 stdiofile-autoinit.o: stdiofile.h virtfile.h sstring.h nonstd_dir.h 240 stdiofile.o: stdiofile.h virtfile.h sstring.h nonstd_dir.h nonstd_stdio.h 241 stdiofile.o: framsg.h 201 242 stdouterr.o: stdouterr.h errmanager.h list.h nonstd.h sstring.h framsg.h 243 stdouterr.o: threads.h virtfile.h 202 244 syntparam.o: nonstd.h syntparam.h param.h sstring.h list.h statrick.h 203 syntparam.o: virtfile.h paramobj.h245 syntparam.o: virtfile.h framsg.h paramobj.h 204 246 virtfile.o: virtfile.h -
cpp/gdk/callbacks.h
r66 r104 39 39 void (*fun)(void*,long); 40 40 public: 41 FunctionCallbackNode(void (*f)(void*,long),void *d): fun(f),userdata(d) {}41 FunctionCallbackNode(void (*f)(void*,long),void *d):userdata(d),fun(f) {} 42 42 void action(long calldata) {(*fun)(userdata,calldata);} 43 43 int equals(CallbackNode*); … … 51 51 void (*fun)(void*,void*,long); 52 52 public: 53 StatrickCallbackNode(void *o,void (*f)(void*,void*,long),void *d):object(o), fun(f),userdata(d) {}53 StatrickCallbackNode(void *o,void (*f)(void*,void*,long),void *d):object(o),userdata(d),fun(f) {} 54 54 void action(long calldata) {(*fun)(object,userdata,calldata);} 55 55 int equals(CallbackNode*); -
cpp/gdk/conv_f1.cpp
r95 r104 261 261 lastNeuroClassParam(); 262 262 if (neuro_cls_param) 263 neuro_cls_param->setById(name,ExtValue(value)); 263 { 264 ExtValue e(value); 265 const ExtValue &re(e); 266 neuro_cls_param->setById(name,re); 267 } 264 268 } 265 269 -
cpp/gdk/errmanager.cpp
r66 r104 5 5 #include "errmanager.h" 6 6 7 ErrorManager globalErrorManager;8 7 9 8 void FramMessage(const char *o,const char *m,const char *bl,int w) 10 9 { 11 globalErrorManager.send(o,m,bl,w);10 ErrorManager::instance.getref().send(o,m,bl,w); 12 11 } 12 13 ThreadSingleton<ErrorManager> ErrorManager::instance; 13 14 14 15 void ErrorManager::send(int level,const char *o,const char *m,const char *bl,int w) … … 76 77 { 77 78 if (isEnabled()) return; 78 globalErrorManager.add(this);79 ErrorManager::instance.getref().add(this); 79 80 } 80 81 … … 82 83 { 83 84 if (!isEnabled()) return; 84 globalErrorManager.remove(this);85 ErrorManager::instance.getref().remove(this); 85 86 } 86 87 -
cpp/gdk/errmanager.h
r66 r104 9 9 #include "sstring.h" 10 10 #include "framsg.h" 11 #include "threads.h" 11 12 12 13 class ErrorHandlerBase; … … 26 27 {send(handlers.size()-1,o,m,bl,w);} 27 28 ~ErrorManager() {removeAll();} 29 30 static ThreadSingleton<ErrorManager> instance; 28 31 }; 29 30 extern ErrorManager globalErrorManager;31 32 32 33 //////////////////////////////////////// … … 51 52 void disable(); 52 53 53 ErrorHandlerBase(int opts=0): options(opts),mgr(0)54 ErrorHandlerBase(int opts=0):mgr(0),options(opts) 54 55 {if (!(options&DontEnable)) enable();} 55 56 ~ErrorHandlerBase() … … 87 88 }; 88 89 90 class ErrorRedirector: public ErrorHandlerBase 91 { 92 ErrorManager *other_mgr; 93 public: 94 ErrorRedirector(ErrorManager *om) 95 :ErrorHandlerBase(),other_mgr(om) {} 96 97 void handle(const char *o,const char *m,const char *bl,int w) 98 { 99 other_mgr->send(o,m,bl,w); 100 } 101 }; 102 89 103 #endif 90 104 -
cpp/gdk/extvalue.cpp
r92 r104 5 5 #include "extvalue.h" 6 6 #include "param.h" 7 #include "sstringutils.h" 7 8 #include <math.h> 9 #include <ctype.h> 10 #include "collectionobj.h" 11 #include "3dobject.h" 8 12 9 13 SString ExtObject::toString() const 10 14 { 11 15 if (isEmpty()) return SString("<empty object>"); 12 ParamInterface *p=getParamInterface(); 16 Param tmp_param; 17 ParamInterface *p=getParamInterface(tmp_param); 13 18 int tostr=p->findId("toString"); 14 19 if (tostr>=0) … … 25 30 return tmp; 26 31 } 32 } 33 34 ThreadSingleton<ExtObject::Serialization> ExtObject::serialization; 35 36 void ExtObject::Serialization::begin() 37 { 38 if (level==0) 39 refs.clear(); 40 level++; 41 } 42 43 int ExtObject::Serialization::add(const ExtObject &o) 44 { 45 if (o.isEmpty()) return -1; 46 for(int i=0;i<refs.size();i++) 47 { 48 ExtObject& r=refs[i]; 49 if (r==o) return i; 50 } 51 refs.push_back(o); 52 return -1; 53 } 54 55 void ExtObject::Serialization::replace(const ExtObject& o,const ExtObject& other) 56 { 57 if (o.isEmpty()) return; 58 for(int i=0;i<refs.size();i++) 59 { 60 ExtObject& r=refs[i]; 61 if (r==o) 62 { 63 r=other; 64 return; 65 } 66 } 67 } 68 69 void ExtObject::Serialization::remove(const ExtObject& o) 70 { 71 if (o.isEmpty()) return; 72 for(int i=0;i<refs.size();i++) 73 { 74 ExtObject& r=refs[i]; 75 if (o==r) refs.erase(refs.begin()+i); 76 } 77 } 78 79 const ExtObject* ExtObject::Serialization::get(int ref) 80 { 81 if (ref<0) return NULL; 82 if (ref>=refs.size()) return NULL; 83 return &refs[ref]; 84 } 85 86 void ExtObject::Serialization::end() 87 { 88 level--; 89 if (level==0) 90 refs.clear(); 91 } 92 93 SString ExtObject::serialize_inner() const 94 { 95 int ref=serialization.getref().add(*this); 96 if (ref>=0) 97 { 98 SString ret; 99 sprintf(ret.directAppend(20),"^%d",ref);ret.endAppend(); 100 return ret; 101 } 102 103 if (isEmpty()) return SString(); 104 VectorObject *vec=VectorObject::fromObject(*this); 105 if (vec) 106 return vec->serialize(); 107 DictionaryObject *dic=DictionaryObject::fromObject(*this); 108 if (dic) 109 return dic->serialize(); 110 Param tmp_param; 111 ParamInterface *p=getParamInterface(tmp_param); 112 int m=p->findId("toVector"); 113 if (m<0) 114 m=p->findId("toDictionary"); 115 if (m>=0) 116 { 117 ExtObject o(p->getObject(m)); 118 SString ret=SString(interfaceName())+o.serialize(); 119 return ret; 120 } 121 m=p->findId("toString"); 122 if (m>=0) 123 { 124 SString str=p->getString(m); 125 sstringQuote(str); 126 SString ret=SString(interfaceName())+"\""+str+"\""; 127 return ret; 128 } 129 130 SString ret=interfaceName(); 131 sprintf(ret.directAppend(30),"<%p>",object?object:paraminterface);ret.endAppend(); 132 return ret; 133 } 134 135 SString ExtObject::serialize() const 136 { 137 serialization.getref().begin(); 138 SString ret=serialize_inner(); 139 serialization.getref().end(); 140 return ret; 27 141 } 28 142 … … 297 411 } 298 412 413 SString ExtValue::serialize() const 414 { 415 switch(type) 416 { 417 case TString: 418 { 419 SString q=sdata(); 420 sstringQuote(q); 421 return SString("\"")+q+SString("\""); 422 } 423 case TInt: 424 { 425 SString tmp; 426 sprintf(tmp.directAppend(20),"%d",idata()); 427 tmp.endAppend(); 428 return tmp; 429 } 430 case TDouble: 431 { 432 SString tmp; 433 sprintf(tmp.directAppend(20),"%.15g",ddata()); 434 tmp.endAppend(); 435 if ((!strchr(tmp,'.'))&&(!strchr(tmp,'e'))) tmp+=".0"; 436 return tmp; 437 } 438 case TObj: 439 return odata().serialize(); 440 case TInvalid: 441 return SString("undefined"); 442 default: 443 return SString("null"); 444 } 445 } 446 447 //returns the first character after the parsed number or NULL if not a number 448 const char* ExtValue::parseNumber(const char* in) 449 { 450 if (isdigit(*in)||((*in=='-')&&(isdigit(in[1])))) 451 { 452 const char* p=in; 453 if (*p=='-') p++; 454 while(isdigit(*p)) p++; 455 bool fp=false; 456 if ((*p=='.') && isdigit(p[1])) 457 { 458 p++; 459 while(isdigit(*p)) p++; 460 fp=true; 461 } 462 if (((*p=='e')||(*p=='E')) && (isdigit(p[1]) || (((p[1]=='-') || (p[1]=='+')) && isdigit(p[2])))) 463 { 464 p++; 465 if ((*p=='-')||(*p=='+')) p++; 466 while(isdigit(*p)) p++; 467 fp=true; 468 } 469 470 if (fp) 471 { 472 setDouble(atof(in)); 473 return p; 474 } 475 else 476 { 477 setInt(atol(in)); 478 return p; 479 } 480 } 481 return NULL; 482 } 483 484 PtrListTempl<ParamInterface*> ExtValue::deserializable_classes; 485 486 void ExtValue::initDeserializableClasses() 487 { 488 deserializable_classes+=&Pt3D_Ext::getStaticParam(); 489 deserializable_classes+=&Orient_Ext::getStaticParam(); 490 } 491 492 ParamInterface *ExtValue::findDeserializableClass(const char* name) 493 { 494 FOREACH(ParamInterface*,cls,deserializable_classes) 495 if (!strcmp(cls->getName(),name)) 496 return cls; 497 return NULL; 498 } 499 500 static const char* skipWord(const char* in) 501 { 502 while(isalpha(*in)) 503 in++; 504 return in; 505 } 506 507 //returns the first character after the parsed portion or NULL if invalid format 508 const char* ExtValue::deserialize_inner(const char* in) 509 { 510 const char* ret=parseNumber(in); 511 if (ret) 512 return ret; 513 else if (*in=='\"') 514 { 515 ret=skipQuoteString(in+1,NULL); 516 SString s(in+1,ret-(in+1)); 517 sstringUnquote(s); 518 setString(s); 519 if (*ret=='\"') 520 return ret+1; 521 else 522 return NULL; 523 } 524 else if (*in=='[') 525 { 526 VectorObject *vec=new VectorObject; 527 ExtObject o(&VectorObject::par,vec); 528 ExtObject::serialization.getref().add(o); 529 const char* p=in+1; 530 ExtValue tmp; 531 while(*p) 532 { 533 if (*p==']') {p++;break;} 534 ret=tmp.deserialize(p); 535 if (ret) 536 { 537 vec->data+=new ExtValue(tmp); 538 p=ret; 539 if (*p==',') p++; 540 } 541 else 542 { 543 p=NULL; 544 break; 545 } 546 } 547 setObject(o); 548 return p; 549 } 550 else if (*in=='{') 551 { 552 DictionaryObject *dic=new DictionaryObject; 553 ExtObject o(&DictionaryObject::par,dic); 554 ExtObject::serialization.getref().add(o); 555 const char* p=in+1; 556 ExtValue args[2]/*={value,key}*/, dummy_ret; 557 while(*p) 558 { 559 if (*p=='}') {p++;break;} 560 ret=args[1].deserialize(p); 561 if ((!ret)||(args[1].getType()!=TString)) {p=NULL;break;} 562 p=ret; 563 if (*p!=':') {p=NULL;break;} 564 p++; 565 ret=args[0].deserialize(p); 566 if (!ret) {p=NULL;break;} 567 p=ret; 568 dic->p_set(args,&dummy_ret); 569 if (*p==',') p++; 570 } 571 setObject(o); 572 return p; 573 } 574 else if (!strncmp(in,"null",4)) 575 { 576 setEmpty(); 577 return in+4; 578 } 579 else if (!strncmp(in,"undefined",9)) 580 { 581 setInvalid(); 582 return in+9; 583 } 584 else if (*in=='<') 585 { //unserializable object 586 setInvalid(); 587 while(*in) 588 if (*in=='>') 589 return in+1; 590 else in++; 591 return in; 592 } 593 else if (*in=='^') 594 { 595 in++; 596 ExtValue ref; 597 ret=ref.parseNumber(in); 598 if (ret && (ref.getType()==TInt)) 599 { 600 const ExtObject* o=ExtObject::serialization.getref().get(ref.getInt()); 601 if (o) 602 { 603 setObject(*o); 604 return ret; 605 } 606 } 607 return NULL; 608 } 609 else if ((ret=skipWord(in))&&(ret!=in)) 610 { 611 SString clsname(in,ret-in); 612 ExtValue tmp; 613 ret=tmp.deserialize(ret); 614 ParamInterface *cls=findDeserializableClass(clsname); 615 if (cls && (tmp.getType()!=TUnknown) && (tmp.getType()!=TInvalid)) 616 { 617 VectorObject *vec=VectorObject::fromObject(tmp.getObject()); 618 if (vec) 619 { 620 int m=cls->findId("newFromVector"); 621 if (m>=0) 622 { 623 cls->call(m,&tmp,this); 624 ExtObject::serialization.getref().replace(tmp.getObject(),getObject()); 625 return ret; 626 } 627 } 628 DictionaryObject *dic=DictionaryObject::fromObject(tmp.getObject()); 629 if (dic) 630 { 631 int m=cls->findId("newFromDictionary"); 632 if (m>=0) 633 { 634 cls->call(m,&tmp,this); 635 ExtObject::serialization.getref().replace(tmp.getObject(),getObject()); 636 return ret; 637 } 638 } 639 if (tmp.getType()==TString) 640 { 641 int m=cls->findId("newFromString"); 642 if (m>=0) 643 { 644 cls->call(m,&tmp,this); 645 ExtObject::serialization.getref().replace(tmp.getObject(),getObject()); 646 return ret; 647 } 648 } 649 ExtObject::serialization.getref().remove(tmp.getObject()); 650 setEmpty(); 651 } 652 FMprintf("ExtValue","deserialize",FMLV_WARN,"object of class \"%s\" could not be deserialized",(const char*)clsname); 653 return ret; 654 } 655 return NULL; 656 } 657 658 const char* ExtValue::deserialize(const char* in) 659 { 660 ExtObject::serialization.getref().begin(); 661 const char* ret=deserialize_inner(in); 662 ExtObject::serialization.getref().end(); 663 return ret; 664 } 665 299 666 ExtObject ExtValue::getObject() const 300 667 { … … 307 674 if (getType()!=TObj) return ExtValue((long)getType()); 308 675 ExtObject& o=odata(); 309 return ExtValue(SString(o.isEmpty()?"":o. getParamInterface()->getName()));310 } 676 return ExtValue(SString(o.isEmpty()?"":o.interfaceName())); 677 } -
cpp/gdk/extvalue.h
r92 r104 8 8 #include "sstring.h" 9 9 #include "param.h" 10 #include "nonstd_stl.h" 11 #include "threads.h" 10 12 11 13 #define EXTVALUEUNION … … 48 50 void* operator new(size_t s) {return malloc(sizeof(ExtObject));} 49 51 void operator delete(void* mem) {free(mem);} 50 51 ParamInterface *getParamInterface() const {if(subtype&2){param->select(object);return param;} return paraminterface;} 52 const char* interfaceName() const {if (isEmpty()) return "Empty"; return getParamInterface()->getName();} 52 ///@param tmp_param can be used for temporary storage, the result ParamInterface* is only valid for as long as tmp_param is valid 53 ParamInterface *getParamInterface(Param &tmp_param) const {if(subtype&2){tmp_param.setParamTab(param->getParamTab());tmp_param.select(object);return &tmp_param;} return paraminterface;} 54 const char* interfaceName() const {if (isEmpty()) return "Empty"; return (subtype&2)?param->getName():paraminterface->getName();} 55 bool matchesInterfaceName(ParamInterface* pi) const {return !strcmp(interfaceName(),pi->getName());} 53 56 void* getTarget() const {return (subtype&1)?dbobject:object;} 54 57 void* getTarget(const char* classname) const {return strcmp(interfaceName(),classname)?0:getTarget();} 58 void setEmpty() {decref();subtype=0;param=NULL;object=NULL;} 55 59 int isEmpty() const {return !param;} 56 60 ExtObject(const ExtObject& src) {src.incref();copyFrom(src);} 57 61 void operator=(const ExtObject& src) {src.incref();decref();copyFrom(src);} 58 62 59 int operator==(const ExtObject& src) {if (object!=src.object) return 0; return (object==0)?(param==src.param):1;}63 int operator==(const ExtObject& src) const {if (object!=src.object) return 0; return (object==0)?(!strcmp(param->getName(),src.param->getName())):1;} 60 64 61 65 SString toString() const; 66 SString serialize_inner() const; 67 SString serialize() const; 62 68 63 69 ExtObject(Param *p,void *o):subtype(2),object(o),param(p){} … … 67 73 68 74 ~ExtObject(){decref();} 75 76 class Serialization 77 { 78 std::vector<ExtObject> refs; 79 int level; 80 public: 81 void begin(); 82 void end(); 83 int add(const ExtObject& o); 84 void replace(const ExtObject& o,const ExtObject& other); 85 void remove(const ExtObject& o); 86 const ExtObject* get(int ref); 69 87 }; 70 88 89 static ThreadSingleton<Serialization> serialization; 90 }; 71 91 72 92 class ExtValue … … 124 144 double getDouble() const; 125 145 SString getString() const; 146 SString serialize() const; 126 147 ExtObject getObject() const; 148 const char* parseNumber(const char* in); 149 const char* deserialize(const char* in);//< @return first character after the succesfully parsed string or NULL if failed 150 const char* deserialize_inner(const char* in); 151 static PtrListTempl<ParamInterface*> deserializable_classes; 152 static ParamInterface *findDeserializableClass(const char* name); 153 static void initDeserializableClasses(); 127 154 128 155 ExtValue getExtType(); -
cpp/gdk/framsg.cpp
r82 r104 11 11 #endif 12 12 13 static const char *warn="[warn] "; 14 static const char *err="[ERROR] "; 13 char* MSG_LEVEL[]={"DEBUG","INFO","WARN","ERROR","CRITICAL"}; 15 14 16 15 /* TODO integracja z error managerem 17 16 void FramMessage(const char *o,const char *m,const char *bl,int w) 18 17 { 19 const char *lvl=""; 20 if (w==1) lvl=warn; else if (w>1) lvl=err; 18 const char *lvl=MSG_LEVEL[w+1]; 21 19 #ifdef SHP 22 20 //jesli chcemy zeby nawet w trybie release wysylal komunikaty: -
cpp/gdk/framsg.h
r82 r104 4 4 #include <stdarg.h> 5 5 6 extern char* MSG_LEVEL[]; 7 6 8 void FMprintf(const char *o,const char *m,int w,const char *bl, ...); 7 9 void FMprintf(const char *o,const char *m,int w,const char *bl,va_list va); 8 void FMprintf(const char *bl,...); // dla leniwych - zastepujeprintf10 void FMprintf(const char *bl,...); //for lazy people - instead of printf 9 11 void FramMessage(const char *o,const char *m,const char *bl,int w); 10 12 … … 17 19 /* 18 20 w: weight (importance) of a message 19 -1:debugging information, not needed for final users 20 0: information 21 1: warning or corrected error 22 2: uncorrected error. can cause malfunction 23 3: serious error, causes side effects. user should save what can be 24 21 22 -1: debugging information, not needed for final users 23 0: information 24 1: warning or corrected error 25 2: uncorrected error. can cause malfunction 26 3: serious error, causes side effects. user should save what can be saved and restart the application 25 27 */ 26 28 -
cpp/gdk/gdktest.cpp
r81 r104 28 28 " ########################################\n",title); 29 29 } 30 void printProperties(Param Interface&pi)30 void printProperties(Param &pi) 31 31 { 32 32 printf(" # id type name group (%d properties)\n",pi.getPropCount()); … … 39 39 } 40 40 41 void changeOneProperty(ParamInterface &pi) 41 #define PRINT_PROPERTIES(p) {Param tmp_param(p); printProperties(tmp_param);} 42 43 void changeOneProperty(Param &pi) 42 44 { 43 45 if (pi.getPropCount()<=0) return; … … 54 56 } 55 57 58 #define CHANGE_ONE_PROPERTY(p) {Param tmp_param(p); changeOneProperty(tmp_param);} 59 56 60 void moreAboutPart(Part* p) 57 61 { … … 61 65 "and should be handled with care, because they influence other elements of the model.\n\n" 62 66 " [this data is provided by Part::properties() ]\n"); 63 printProperties(p->properties());67 PRINT_PROPERTIES(p->properties()); 64 68 printf("\nHowever, there is a subset of properties which may be modified more freely.\n" 65 69 "Properties on this list are related only to this part and can be changed\n" … … 67 71 "will be silently repaired.\n" 68 72 "\n [this data is provided by Part::extraProperties() ]\n"); 69 printProperties(p->extraProperties());73 PRINT_PROPERTIES(p->extraProperties()); 70 74 printf("\nThis set of properties can vary from release to release,\n" 71 75 "but can be safely accessed by using extraProperties() call.\n" … … 74 78 "Now we will try to change some of properties:\n\n"); 75 79 p->getModel().open(); 76 changeOneProperty(p->extraProperties());80 CHANGE_ONE_PROPERTY(p->extraProperties()); 77 81 p->getModel().close(); 78 82 printf("\nLet's see f0... (check out part #%d !)\n\n%s\n", p->refno, (const char*)p->getModel().getF0Geno().getGene()); … … 127 131 { 128 132 printf("Similarly as with Part, the full list of properties comes first:\n\n"); 129 printProperties(j->properties());133 CHANGE_ONE_PROPERTY(j->properties()); 130 134 printf("\nActually, there are two kinds of Joints: delta and absolute.\n" 131 135 "For this object, Joint::isDelta() returns %d, so this is the %s Joint.\n", … … 147 151 "The other properties are available from Joint::extraProperties()\n" 148 152 "and at the moment are defined as follows:\n\n"); 149 printProperties(j->extraProperties());153 PRINT_PROPERTIES(j->extraProperties()); 150 154 printf("\nThey can be changed just like Part's extra properties:\n"); 151 155 j->getModel().open(); 152 changeOneProperty(j->extraProperties());156 CHANGE_ONE_PROPERTY(j->extraProperties()); 153 157 j->getModel().close(); 154 158 printf("And after that we have this genotype:\n\n%s\n", (const char*)j->getModel().getF0Geno().getGene()); … … 161 165 printf("Basic features of Neuro object are similar to those of Part and Joint.\n" 162 166 "We can request a property list:\n\n"); 163 printProperties(n->properties());167 PRINT_PROPERTIES(n->properties()); 164 168 printf("\n...and extra properties (which are designed to be always valid and easy to change):\n\n"); 165 printProperties(n->extraProperties());169 PRINT_PROPERTIES(n->extraProperties()); 166 170 printf("\nAs usual, we will change something:\n"); 167 171 n->getModel().open(); 168 changeOneProperty(n->extraProperties());172 CHANGE_ONE_PROPERTY(n->extraProperties()); 169 173 n->getModel().close(); 170 174 printf("Each neuron can have any number of inputs = weighted connections\n with other neurons.\n" -
cpp/gdk/genoconv.cpp
r82 r104 32 32 { 33 33 if (i>=gcm->converters.size()) return 0; 34 static char t[20]; 35 sprintf(t,"genkonw%d",i); 36 return t; 34 sprintf(tmp_id,"genkonw%d",i); 35 return tmp_id; 37 36 } 38 37 … … 174 173 { 175 174 if (in.getFormat()==format) return in; 176 staticchar path[10];175 char path[10]; 177 176 int dep; 178 177 char *ret; -
cpp/gdk/genoconv.h
r66 r104 21 21 GenoConvManager *gcm; 22 22 std::vector<std::string> gcnames; 23 char tmp_id[20]; 23 24 void freetab(); 24 25 public: -
cpp/gdk/genotypeloader.cpp
r66 r104 22 22 void MiniGenotypeLoader::init() 23 23 { 24 add Class(&genotype_param);24 addObject(&genotype_param); 25 25 breakOn(MultiParamLoader::OnError + MultiParamLoader::AfterObject); 26 26 } … … 29 29 { 30 30 genotype_object.clear(); 31 if ((go()==AfterObject)&&(get Class()==&genotype_param))31 if ((go()==AfterObject)&&(getObject().matchesInterfaceName(&genotype_param))) 32 32 return &genotype_object; 33 33 else -
cpp/gdk/list.h
r66 r104 57 57 SListTempl(const SListTempl<T>& src):have(0),used(0),mem(0),pos(0) 58 58 {(*this)=src;} 59 SListTempl():have(0),used(0), mem(0),pos(0)59 SListTempl():have(0),used(0),pos(0),mem(0) 60 60 {} 61 61 ~SListTempl() -
cpp/gdk/model.cpp
r89 r104 382 382 SString gen; 383 383 384 staticParam modelparam(f0_model_paramtab);385 staticParam partparam(f0_part_paramtab);386 staticParam jointparam(f0_joint_paramtab);387 staticParam neuroparam(f0_neuro_paramtab);388 staticParam connparam(f0_neuroconn_paramtab);384 Param modelparam(f0_model_paramtab); 385 Param partparam(f0_part_paramtab); 386 Param jointparam(f0_joint_paramtab); 387 Param neuroparam(f0_neuro_paramtab); 388 Param connparam(f0_neuroconn_paramtab); 389 389 390 390 static Part defaultpart; … … 563 563 if (!strncmp(t,"p:",2)) 564 564 { 565 staticParam partparam(f0_part_paramtab);565 Param partparam(f0_part_paramtab); 566 566 Part *p=new Part(); 567 567 partparam.select(p); … … 576 576 if (!strncmp(t,"m:",2)) 577 577 { 578 staticParam modelparam(f0_model_paramtab);578 Param modelparam(f0_model_paramtab); 579 579 modelparam.select(this); 580 580 pos+=2; … … 584 584 else if (!strncmp(t,"j:",2)) 585 585 { 586 staticParam jointparam(f0_joint_paramtab);586 Param jointparam(f0_joint_paramtab); 587 587 Joint *j=new Joint(); 588 588 jointparam.select(j); … … 610 610 else if (!strncmp(t,"n:",2)) // neuro (or the old neuro object as the special case) 611 611 { 612 staticParam neuroparam(f0_neuro_paramtab);612 Param neuroparam(f0_neuro_paramtab); 613 613 Neuro *nu=new Neuro(); 614 614 neuroparam.select(nu); … … 674 674 else if (!strncmp(t,"c:",2)) // add input 675 675 { 676 staticParam ncparam(f0_neuroconn_paramtab);676 Param ncparam(f0_neuroconn_paramtab); 677 677 NeuroConn c; 678 678 ncparam.select(&c); … … 696 696 { 697 697 // we always use old layout for "ni:" 698 staticParam neuroitemparam(f0_neuroitem_paramtab);698 Param neuroitemparam(f0_neuroitem_paramtab); 699 699 Neuro *nu=new Neuro(); 700 700 neuroitemparam.select(nu); … … 1085 1085 } 1086 1086 1087 const Geno& Model::getF0Geno() 1088 { 1089 static Geno invalidgeno("",'0',"","invalid"); 1087 const Geno Model::getF0Geno() 1088 { 1090 1089 if (buildstatus==building) 1091 1090 FMprintf("Model","getGeno",FMLV_WARN,"model was not completed - missing close()"); 1092 1091 if (buildstatus!=valid) 1093 return invalidgeno;1092 return Geno("",'0',"","invalid"); 1094 1093 if (!f0genoknown) 1095 1094 { -
cpp/gdk/model.h
r82 r104 212 212 don't use between open()-close() 213 213 */ 214 const Geno &getF0Geno();214 const Geno getF0Geno(); 215 215 216 216 /// make f0 genotype from current construction (low level version of getF0Geno) -
cpp/gdk/modelparts.cpp
r81 r104 97 97 int _prefinputs,int _prefoutput,int _preflocation, 98 98 int *_vectordata,bool own_vd,int vhints) 99 :longname(_props->id), 100 name(_props->name), 101 description(_description), 99 :ownedvectordata(own_vd), 100 name(_props->name),longname(_props->id),description(_description), 102 101 props(_props), 103 102 prefinputs(_prefinputs), 104 103 prefoutput(_prefoutput), 105 104 preflocation(_preflocation), 106 vectordata(_vectordata), ownedvectordata(own_vd),107 visualhints(vhints),impl (0),active(1),genactive(0)105 vectordata(_vectordata), 106 visualhints(vhints),impl_count(0),/*impl(0),*/active(1),genactive(0) 108 107 {} 109 108 … … 114 113 115 114 NeuroClass::NeuroClass() 116 :name("Invalid"),props(empty_paramtab), 115 :ownedvectordata(0), 116 name("Invalid"), 117 props(empty_paramtab), 117 118 prefinputs(0), prefoutput(0), 118 preflocation(0), vectordata(0), ownedvectordata(0),119 impl(0),active(1), genactive(0)119 preflocation(0), vectordata(0), 120 visualhints(0),impl_count(0), /*impl(0),*/ active(1), genactive(0) 120 121 {} 121 122 … … 176 177 177 178 Neuro::Neuro(double _state,double _inertia,double _force,double _sigmo) 178 : state(_state),PartBase(getDefaultStyle())179 :PartBase(getDefaultStyle()),state(_state) 179 180 #ifdef MODEL_V1_COMPATIBLE 180 181 ,inertia(_inertia),force(_force),sigmo(_sigmo) … … 187 188 myclass=0; 188 189 knownclass=1; 190 part_refno=-1; joint_refno=-1; 189 191 } 190 192 … … 204 206 #endif 205 207 flags=0; 208 part_refno=-1; joint_refno=-1; 206 209 } 207 210 … … 614 617 /////////////////////////////////////// 615 618 616 const SString&Part::getDefaultStyle()617 { static SString s("part"); return s;}618 const SString&Joint::getDefaultStyle()619 { static SString s("joint"); return s;}619 SString Part::getDefaultStyle() 620 {return SString("part");} 621 SString Joint::getDefaultStyle() 622 {return SString("joint");} 620 623 /* 621 624 const SString& Neuro::getDefaultStyle() … … 624 627 {static SString s("neuroitem"); return s;} 625 628 */ 626 const SString&Neuro::getDefaultStyle()627 { static SString s("neuro"); return s;}629 SString Neuro::getDefaultStyle() 630 {return SString("neuro");} 628 631 629 632 Part::Part():PartBase(getDefaultStyle()) … … 776 779 }; 777 780 778 static Param staticparam; 779 780 ParamInterface &Part::extraProperties() 781 { 782 staticparam.setParamTab(f0_part_xtra_paramtab); 783 staticparam.select(this); 784 return staticparam; 785 } 786 787 ParamInterface &Joint::extraProperties() 788 { 789 staticparam.setParamTab(f0_joint_xtra_paramtab); 790 staticparam.select(this); 791 return staticparam; 792 } 793 794 ParamInterface &Neuro::extraProperties() 795 { 796 staticparam.setParamTab(f0_neuro_xtra_paramtab); 797 staticparam.select(this); 798 return staticparam; 799 } 800 801 ParamInterface &Part::properties() 802 { 803 staticparam.setParamTab(f0_part_paramtab); 804 staticparam.select(this); 805 return staticparam; 806 } 807 808 ParamInterface &Joint::properties() 809 { 810 staticparam.setParamTab(usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab); 811 staticparam.select(this); 812 return staticparam; 813 } 814 815 ParamInterface &Neuro::properties() 816 { 817 staticparam.setParamTab(f0_neuro_paramtab); 818 staticparam.select(this); 819 return staticparam; 781 Param Part::extraProperties() 782 { 783 return Param(f0_part_xtra_paramtab,this); 784 } 785 786 Param Joint::extraProperties() 787 { 788 return Param(f0_joint_xtra_paramtab,this); 789 } 790 791 Param Neuro::extraProperties() 792 { 793 return Param(f0_neuro_xtra_paramtab,this); 794 } 795 796 Param Part::properties() 797 { 798 return Param(f0_part_paramtab,this); 799 } 800 801 Param Joint::properties() 802 { 803 return Param(usedelta?f0_joint_paramtab:f0_nodeltajoint_paramtab,this); 804 } 805 806 Param Neuro::properties() 807 { 808 return Param(f0_neuro_paramtab,this); 820 809 } 821 810 -
cpp/gdk/modelparts.h
r81 r104 35 35 PartBase(const SString& s):vis_style(s),mapped(0) {} 36 36 ~PartBase(); 37 static const SString& getDefaultStyle(){static SString s("none"); return s;}37 static SString getDefaultStyle(){return SString("none");} 38 38 MultiRange *mapped; 39 39 enum PartBaseFlags { Selected=1 }; … … 68 68 { 69 69 friend class Model; 70 static const SString&getDefaultStyle();70 static SString getDefaultStyle(); 71 71 Part(double _mass,double _size,double _density,double _friction,double _ingest,double _assim) 72 :mass(_mass),size(_size),density(_density),friction(_friction),ingest(_ingest),assim(_assim), 73 PartBase(getDefaultStyle()) 72 :PartBase(getDefaultStyle()),mass(_mass),size(_size),density(_density),friction(_friction),ingest(_ingest),assim(_assim) 74 73 {} 75 74 public: … … 78 77 Orient o; ///< orientation in 3d space (rotation matrix) 79 78 /// ParamInterface object is preferred way to get/set other properties. 80 Param Interface &extraProperties();81 Param Interface &properties();79 Param extraProperties(); 80 Param properties(); 82 81 long refno; 83 82 Pt3D rot; … … 104 103 { 105 104 friend class Model; 106 static const SString&getDefaultStyle();105 SString getDefaultStyle(); 107 106 Joint(double _stamina,double _stif,double _rotstif,double _d) 108 : stamina(_stamina),stif(_stif),rotstif(_rotstif),PartBase(getDefaultStyle())107 :PartBase(getDefaultStyle()),stamina(_stamina),stif(_stif),rotstif(_rotstif) 109 108 {d=Pt3D(_d,0,0);} 110 109 public: … … 144 143 145 144 /// ParamInterface object is preferred way to get/set other properties. 146 Param Interface &extraProperties();147 Param Interface &properties();145 Param extraProperties(); 146 Param properties(); 148 147 149 148 // do not touch these: … … 182 181 long visualhints; 183 182 184 void *impl; 183 //void *impl; 184 int impl_count; 185 185 bool active; 186 186 int genactive; … … 290 290 { 291 291 friend class Model; 292 static const SString&getDefaultStyle();292 static SString getDefaultStyle(); 293 293 294 294 struct NInput { Neuro *n; double weight; SString *info; … … 307 307 public: 308 308 enum NeuroFlags { HoldState=2 }; 309 Param Interface &properties();310 Param Interface &extraProperties();309 Param properties(); 310 Param extraProperties(); 311 311 312 312 void setInputInfo(int i,const SString& name,const SString &value); -
cpp/gdk/multiparamload.cpp
r81 r104 19 19 breakcond=OnError; 20 20 emptyparam.setParamTab(empty_paramtab); 21 } 22 23 int MultiParamLoader::findObject(const ExtObject &o) 24 { 25 for(int i=0;i<objects.size();i++) 26 if ((*objects(i))==o) 27 return i; 28 return -1; 29 } 30 31 void MultiParamLoader::removeObject(const ExtObject &o) 32 { 33 int i=findObject(o); 34 if (i>=0) 35 { 36 delete objects(i); 37 objects-=i; 38 } 39 } 40 41 void MultiParamLoader::clearObjects() 42 { 43 FOREACH(ExtObject*,o,objects) 44 delete o; 45 objects.clear(); 21 46 } 22 47 … … 102 127 while (!finished()) 103 128 { 104 if ((status==BeforeObject) || ((status==BeforeUnknown)&&lastclass)) 105 { 106 lastclass->load(file); 129 if ((status==BeforeObject) || ((status==BeforeUnknown) && !lastobject.isEmpty())) 130 { 131 Param tmp_param; 132 ParamInterface *pi=lastobject.getParamInterface(tmp_param); 133 pi->load(file); 107 134 if ((status!=Finished) && maybeBreak(AfterObject)) 108 135 break; … … 155 182 lastunknown=0; 156 183 lastunknown.append(t,linlen-1); 157 last class=0;158 FOREACH( ParamInterface*,pi,params)159 { 160 if (!strcmp( pi->getName(),lastunknown)) { lastclass=pi; break;}161 } 162 if ( lastclass)184 lastobject.setEmpty(); 185 FOREACH(ExtObject*,o,objects) 186 { 187 if (!strcmp(o->interfaceName(),lastunknown)) {lastobject=*o; break;} 188 } 189 if (!lastobject.isEmpty()) 163 190 { 164 191 if (maybeBreak(BeforeObject)) … … 244 271 } 245 272 246 int MultiParamLoader::loadObjectNow(ParamInterface *pi) 247 { 273 int MultiParamLoader::loadObjectNow(const ExtObject& o) 274 { 275 Param tmp_param; 276 ParamInterface *pi=o.getParamInterface(tmp_param); 248 277 pi->load(file); 249 278 status=AfterObject; -
cpp/gdk/multiparamload.h
r74 r104 9 9 #include "param.h" 10 10 #include "virtfile.h" 11 #include "extvalue.h" 11 12 12 13 /** This is the general "framsticks-format" file parser for loading multiple objects. … … 37 38 SListTempl<VirtFILE*> filestack; 38 39 char ownfile; 39 SList params;40 PtrListTempl<ExtObject*> objects; 40 41 int status; 41 42 SString lasterror, lastcomment, lastunknown; 42 ParamInterface *lastclass;43 ExtObject lastobject; 43 44 int breakcond; 44 45 Param emptyparam; 45 46 46 47 void init(); 47 void load();48 48 49 49 int maybeBreak(int cond) … … 58 58 MultiParamLoader(const char* filename) {init(); load(filename);} 59 59 60 ~MultiParamLoader() {abort(); }60 ~MultiParamLoader() {abort();clearObjects();} 61 61 62 62 void reset(); 63 63 64 void load(); //< use previously opened file 64 65 void load(VirtFILE *f); 65 66 void load(const char* filename); … … 69 70 Note that registered classes will only work when the record name matches the class name, otherwise breakOn(BeforeUnknown) must be used and then getClassName() to check for the expected record. 70 71 */ 71 void addClass(ParamInterface *pi) {params+=pi;} 72 void removeClass(ParamInterface *pi) {params-=pi;} 73 void clearClasses() {params.clear();} 72 void addObject(ParamInterface *pi) {objects+=new ExtObject(pi);} 73 void removeObject(ParamInterface *pi) {removeObject(ExtObject(pi));} 74 void addObject(const ExtObject &o) {objects+=new ExtObject(o);} 75 void removeObject(const ExtObject &o); 76 int findObject(const ExtObject &o); 77 void clearObjects(); 74 78 75 79 /** To be used in the main loop: while(event=loader.go()) { ... } … … 107 111 108 112 /** Can be used BeforeObject and AfterObject */ 109 ParamInterface *getClass() {return lastclass;}113 ExtObject &getObject() {return lastobject;} 110 114 /** Can be used BeforeUnknown, BeforeObject, AfterObject */ 111 const SString& get ClassName() {return lastunknown;}112 const void set ClassName(SString n) {lastunknown=n;}115 const SString& getObjectName() {return lastunknown;} 116 const void setObjectName(SString n) {lastunknown=n;} 113 117 /** Unknown object will be loaded if you set its class BeforeUnknown */ 114 void setClass(ParamInterface *pi) {lastclass=pi;} 118 void setObject(ParamInterface *pi) {lastobject=ExtObject(pi);} 119 void setObject(const ExtObject& o) {lastobject=o;} 115 120 /** Can be used OnComment */ 116 121 const SString& getComment() {return lastcomment;} … … 118 123 const SString& getError() {return lasterror;} 119 124 /** Can be used BeforeObject and BeforeUnknown */ 120 int loadObjectNow(ParamInterface *pi); 125 int loadObjectNow(ParamInterface *pi) {return loadObjectNow(ExtObject(pi));} 126 int loadObjectNow(const ExtObject &o); 121 127 /** Can be used BeforeObject */ 122 int loadObjectNow() {return loadObjectNow(get Class());}128 int loadObjectNow() {return loadObjectNow(getObject());} 123 129 /** Can be used BeforeObject and BeforeUnknown. 124 130 Object data will not be loaded. */ -
cpp/gdk/neurofactory.cpp
r81 r104 7 7 #include "param.h" 8 8 #include "neuroimpl.h" 9 #include "neurolibrary.h" 10 9 11 #include NEURO_IMPL_FILES 10 12 11 int NeuroFactory::used=0; 13 NeuroImpl* NeuroFactory::getImplementation(NeuroClass *nc) 14 { 15 if (nc!=NULL) 16 { 17 std::map<NeuroClass*,NeuroImpl*>::iterator it=impl.find(nc); 18 if (it!=impl.end()) 19 return it->second; 20 } 21 return NULL; 22 } 12 23 13 24 NeuroImpl* NeuroFactory::createNeuroImpl(NeuroClass *nc) … … 15 26 if (!nc) return 0; 16 27 if (!nc->active) return 0; 17 NeuroImpl* ni= (NeuroImpl*)nc->impl;28 NeuroImpl* ni=getImplementation(nc); 18 29 if (!ni) return 0; 19 30 ni=ni->makeNew(); … … 31 42 NeuroImpl* NeuroFactory::setImplementation(NeuroClass *nc,NeuroImpl *ni,bool deleteold) 32 43 { 33 NeuroImpl* old_ni=(NeuroImpl*)nc->impl; 34 nc->impl=ni; 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 { 49 if (ni!=NULL) 50 { 51 impl[nc]=ni; 52 nc->impl_count++; 53 } 54 return NULL; 55 } 56 else 57 { 58 old_ni=it->second; 59 if (ni) 60 it->second=ni; 61 else 62 { 63 impl.erase(it); 64 nc->impl_count--; 65 } 66 } 35 67 if (deleteold && old_ni) delete old_ni; 36 68 return old_ni; … … 39 71 #include NEURO_CLS_FACTORY 40 72 41 void NeuroFactory::set Implementation()73 void NeuroFactory::setStandardImplementation() 42 74 { 43 if (!used) 44 { 45 SETIMPLEMENTATION 46 } 47 used++; 75 SETIMPLEMENTATION 48 76 } 49 77 50 78 void NeuroFactory::freeImplementation() 51 79 { 52 used--; 53 if (!used) 54 { 55 for(int i=0;i<Neuro::getClassCount();i++) 56 setImplementation(Neuro::getClass(i),0); 57 } 80 for(int i=0;i<Neuro::getClassCount();i++) 81 setImplementation(Neuro::getClass(i),0); 58 82 } 59 83 84 void NeuroFactory::removeUnimplemented() 85 { 86 SString removed; 87 for(int i=0;i<Neuro::getClassCount();i++) 88 { 89 NeuroClass *nc=Neuro::getClass(i); 90 if (nc->impl_count==0) 91 { 92 removed+=nc->getName(); 93 removed+=" "; 94 NeuroLibrary::staticlibrary.classes-=i; 95 i--; 96 delete nc; 97 } 98 } 99 if (removed.len()) 100 FMprintf("NeuroFactory","removeUninmplemented",FMLV_INFO, 101 "Removed Neuro classes: %s",(const char*)removed); 102 } 103 -
cpp/gdk/neurofactory.h
r66 r104 7 7 8 8 #include "modelparts.h" 9 #include <map> 9 10 10 11 class NeuroImpl; … … 12 13 class NeuroFactory 13 14 { 15 std::map<NeuroClass*,NeuroImpl*> impl; 14 16 public: 15 static NeuroImpl* setImplementation(NeuroClass *nc,NeuroImpl *ni,bool deleteold=1); 16 static NeuroImpl* setImplementation(const SString& classname,NeuroImpl *ni,bool deleteold=1); 17 static class NeuroImpl* createNeuroImpl(Neuro *n) 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) 18 21 {NeuroClass *nc=n->getClass(); if (!nc) return 0; return createNeuroImpl(nc);} 19 staticclass NeuroImpl* createNeuroImpl(NeuroClass *nc);22 class NeuroImpl* createNeuroImpl(NeuroClass *nc); 20 23 21 static int used;22 static void setImplementation();23 static void freeImplementation();24 void setStandardImplementation(); 25 void freeImplementation(); 26 void removeUnimplemented(); 24 27 }; 25 28 -
cpp/gdk/neuroimpl.cpp
r81 r104 32 32 #undef FIELDSTRUCT 33 33 34 NeuroNetConfig::NeuroNetConfig( )34 NeuroNetConfig::NeuroNetConfig(NeuroFactory *fac) 35 35 :par(nncfg_paramtab,this), 36 36 randominit(0.01), 37 37 nnoise(0), 38 touchrange(1) 38 touchrange(1), 39 factory(fac) 39 40 {} 40 41 NeuroNetConfig& NeuroNetConfig::getGlobalConfig()42 {43 static NeuroNetConfig globalconfig;44 return globalconfig;45 }46 41 47 42 ///////////////////////////////////////////////////////////////// … … 74 69 for (i=0;n=mod.getNeuro(i);i++) 75 70 { 76 ni= NeuroFactory::createNeuroImpl(n);71 ni=conf.factory->createNeuroImpl(n); 77 72 n->userdata[mytags_id]=ni; 78 73 if (!ni) { errorcount++; … … 205 200 chstate=chnewstate; 206 201 neuro->state=newstate; 207 if ( NeuroNetConfig::getGlobalConfig().nnoise>0.0)202 if (owner->getConfig().nnoise>0.0) 208 203 { 209 neuro->state+=RndGen.GaussStd()* NeuroNetConfig::getGlobalConfig().nnoise;204 neuro->state+=RndGen.GaussStd()*owner->getConfig().nnoise; 210 205 if (channels>1) 211 206 for(int i=0;i<chstate.size();i++) 212 chstate(0)+=RndGen.GaussStd()* NeuroNetConfig::getGlobalConfig().nnoise;207 chstate(0)+=RndGen.GaussStd()*owner->getConfig().nnoise; 213 208 } 214 209 } … … 272 267 void NeuroImpl::readParam() 273 268 { 274 staticParam par;269 Param par; 275 270 if (!paramentries) return; 276 271 par.setParamTab(paramentries); -
cpp/gdk/neuroimpl.h
r81 r104 17 17 18 18 class Creature; 19 class NeuroLibrary; 20 class NeuroFactory; 19 21 20 22 class NeuroNetConfig 21 23 { 22 24 public: 23 NeuroNetConfig( );25 NeuroNetConfig(NeuroFactory *fac); 24 26 25 27 Param par; … … 28 30 double touchrange; 29 31 30 static NeuroNetConfig& getGlobalConfig(); 32 NeuroFactory *factory; 33 //static NeuroNetConfig& getGlobalConfig(); 31 34 }; 32 35 … … 40 43 public: 41 44 42 NeuroSignals(NeuroImpl *n): owner(n),cr(0) {}45 NeuroSignals(NeuroImpl *n):cr(0),owner(n) {} 43 46 44 47 #define STATRICKCLASS NeuroSignals … … 74 77 static double getStateFromNeuro(Neuro *n); 75 78 int getErrorCount() {return errorcount;} 76 NeuroNetImpl(Model& model, NeuroNetConfig& conf = NeuroNetConfig::getGlobalConfig() 79 NeuroNetConfig &getConfig() {return config;} 80 NeuroNetImpl(Model& model, NeuroNetConfig& conf 77 81 #ifdef NEURO_SIGNALS 78 82 , ChannelSpace *ch=0 … … 198 202 /** don't access directly */ 199 203 double newstate; 204 NeuroNetImpl *owner; 205 /** will be used by readParam() method, if not null */ 206 ParamEntry *paramentries; // no extra properties if ==0 200 207 201 208 #ifdef NEURO_SIGNALS 202 209 NeuroSignals sigs; 203 #endif204 NeuroNetImpl *owner;205 210 ExtObject sigs_obj; 211 #endif 206 212 207 213 /** "virtual constructor" - NeuroFactory uses this method to create the proper implementation object. 208 214 subclasses must return new object here. */ 209 215 virtual NeuroImpl* makeNew() {return 0;} // 210 /** will be used by readParam() method, if not null */211 ParamEntry *paramentries; // no extra properties if ==0212 216 /** read additional properties from "moredata" field of the originating Neuro */ 213 217 void readParam(); … … 247 251 void validateNeuroState(double& st) {if (st<=-1e10) st=-1e10; else if (st>1e10) st=1e10;} 248 252 249 NeuroImpl(): owner(0),neuro(0),newstate(0),paramentries(0),simorder(1),status(BeforeInit),channels(1),fields_param(0),fields_object(0)253 NeuroImpl():simorder(1),channels(1),fields_param(0),fields_object(0),status(BeforeInit),neuro(0),newstate(0),owner(0),paramentries(0) 250 254 #ifdef NEURO_SIGNALS 251 255 ,sigs(this),sigs_obj(&NeuroSignals::getStaticParam(),&sigs) -
cpp/gdk/neurolibrary.cpp
r81 r104 25 25 if (i<0) return 0; 26 26 return getClass(i); 27 } 28 29 SString NeuroLibrary::getClassName(int classindex) 30 { 31 NeuroClass *cl=getClass(classindex); 32 return cl? cl->getName() : SString(); 27 33 } 28 34 -
cpp/gdk/neurolibrary.h
r66 r104 22 22 int findClassIndex(const SString& classname, bool activeonly=1); 23 23 NeuroClass* getClass(int classindex) {return (NeuroClass*)classes(classindex);} 24 SString getClassName(int classindex); 24 25 int getClassCount() {return classes.size();} 25 26 void removeClass(int i); -
cpp/gdk/neurotest.cpp
r70 r104 80 80 if (!m.getNeuroCount()) {puts("no neural network");return 1;} 81 81 printf("%d neurons,",m.getNeuroCount()); 82 NeuroFactory::setImplementation(); 83 NeuroNetImpl *nn=new NeuroNetImpl(m); 82 NeuroFactory neurofac; 83 neurofac.setStandardImplementation(); 84 NeuroNetConfig nn_config(&neurofac); 85 NeuroNetImpl *nn=new NeuroNetImpl(m,nn_config); 84 86 int i; Neuro *n; 85 87 if (!nn->getErrorCount()) printf(" no errors\n"); … … 138 140 nn->simulateNeuroNet(); 139 141 } 140 NeuroFactory::freeImplementation();142 neurofac.freeImplementation(); 141 143 } -
cpp/gdk/param.cpp
r93 r104 231 231 } 232 232 233 const char* ParamInterface::SERIALIZATION_PREFIX="@Serialized:"; 234 233 235 int ParamInterface::saveprop(VirtFILE* f,int i,const char* p,bool force) 234 236 { … … 243 245 err|=(fputs(p,f)==EOF); fputc(':',f); 244 246 cr=0; 245 ws=get(i); 247 if (*typ=='x') 248 { 249 ExtValue ex; 250 get(i,ex); 251 ws=SString(SERIALIZATION_PREFIX)+ex.serialize(); 252 } 253 else 254 ws=get(i); 246 255 quoteTilde(ws); 247 256 w=ws; … … 497 506 { 498 507 ExtValue e; 499 if (isdigit(*v)||((*v=='-')&&isdigit(v[1]))) 500 { 501 if (strchr(v,'.')) e.setDouble(atof(v)); 502 else e.setInt(atol(v)); 508 const char* after; 509 if (!strncmp(v,SERIALIZATION_PREFIX,strlen(SERIALIZATION_PREFIX))) 510 { 511 after=e.deserialize(v+strlen(SERIALIZATION_PREFIX)); 512 if ((after==NULL)||(*after)) 513 FMprintf("ParamInterface","set",FMLV_WARN,"serialization format mismatch in %s.%s",(getName()?getName():"<Unknown>"),id(i)); 514 } 515 else if ((after=e.parseNumber(v))&&(*after==0)) //consumed the whole string 516 { 517 //OK! 503 518 } 504 519 else … … 566 581 long SimpleAbstractParam::getInt(int i) 567 582 { 568 staticExtValue v;583 ExtValue v; 569 584 ParamEntry *pe=entry(i); 570 585 if (pe->fun1) … … 582 597 double SimpleAbstractParam::getDouble(int i) 583 598 { 584 staticExtValue v;599 ExtValue v; 585 600 ParamEntry *pe=entry(i); 586 601 if (pe->fun1) … … 598 613 SString SimpleAbstractParam::getString(int i) 599 614 { 600 staticExtValue v;615 ExtValue v; 601 616 ParamEntry *pe=entry(i); 602 617 if (pe->fun1) … … 614 629 ExtObject SimpleAbstractParam::getObject(int i) 615 630 { 616 staticExtValue v;631 ExtValue v; 617 632 ParamEntry *pe=entry(i); 618 633 if (pe->fun1) … … 630 645 ExtValue SimpleAbstractParam::getExtValue(int i) 631 646 { 632 staticExtValue v;647 ExtValue v; 633 648 ParamEntry *pe=entry(i); 634 649 if (pe->fun1) … … 649 664 int SimpleAbstractParam::setInt(int i,long x) 650 665 { 651 staticExtValue v;666 ExtValue v; 652 667 ParamEntry *pe=entry(i); 653 668 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 654 long xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below669 long xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 655 670 long a=0,b=0; 656 671 int result=0; … … 684 699 int SimpleAbstractParam::setDouble(int i,double x) 685 700 { 686 staticExtValue v;701 ExtValue v; 687 702 ParamEntry *pe=entry(i); 688 703 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 689 double xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below704 double xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 690 705 double a=0,b=0; 691 706 int result=0; … … 719 734 int SimpleAbstractParam::setString(int i,const SString& x) 720 735 { 721 staticExtValue v;722 staticSString vs;736 ExtValue v; 737 SString vs; 723 738 const SString *xx=&x; 724 739 ParamEntry *pe=entry(i); 725 740 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 726 SString xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below741 SString xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 727 742 const char* t=pe->type+1; 728 743 while(*t) if (*t==' ') break; else t++; … … 759 774 int SimpleAbstractParam::setObject(int i,const ExtObject& x) 760 775 { 761 staticExtValue v;776 ExtValue v; 762 777 ParamEntry *pe=entry(i); 763 778 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 764 ExtObject xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below779 ExtObject xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 765 780 if (pe->fun2) 766 781 { -
cpp/gdk/param.h
r93 r104 151 151 void load(VirtFILE*); 152 152 void load2(const SString &,int &); 153 154 static const char* SERIALIZATION_PREFIX; 153 155 }; 154 156 … … 221 223 @param n Param's name 222 224 */ 223 SimpleAbstractParam(void* o=0,const char*n=0):object(o),myname(n),dontcheckchanges(0) {} 225 SimpleAbstractParam(void* o=0,const char*n=0):myname(n),dontcheckchanges(0),object(o) {} 226 void setDontCheckChanges(bool x) {dontcheckchanges=x;} 224 227 225 228 void select(void *o) {object=o;} -
cpp/gdk/sstring.cpp
r92 r104 7 7 #include "nonstd_stl.h" 8 8 #include "extvalue.h" 9 10 #ifdef MULTITHREADED 11 #include <pthread.h> 12 static pthread_mutex_t sstring_ref_lock; 13 #define REF_LOCK pthread_mutex_lock(&sstring_ref_lock); 14 #define REF_UNLOCK pthread_mutex_unlock(&sstring_ref_lock) 15 #else 16 #define REF_LOCK 17 #define REF_UNLOCK 18 #endif 9 19 10 20 static int guessMemSize(int request, int memhint) … … 96 106 SString::~SString() 97 107 { 108 REF_LOCK; 98 109 detach(); 110 REF_UNLOCK; 99 111 } 100 112 … … 102 114 { 103 115 buf=new SBuf(x); 116 memhint=-1; 104 117 } 105 118 … … 113 126 SString::SString(const SString &from) 114 127 { 115 buf=from.buf; 116 if (buf->size) buf->refcount++; 128 if (from.buf==&SBuf::empty()) 129 buf=&SBuf::empty(); 130 else 131 { 132 REF_LOCK; 133 buf=from.buf; 134 if (buf->size) 135 buf->refcount++; 136 REF_UNLOCK; 137 } 117 138 memhint=-1; 118 139 } … … 163 184 { 164 185 if (ensuresize<0) ensuresize=len(); 186 REF_LOCK; 165 187 detachCopy(ensuresize); 188 REF_UNLOCK; 166 189 appending=buf->used; 167 190 return buf->txt; … … 176 199 char *SString::directAppend(int maxappend) 177 200 { 201 REF_LOCK; 178 202 detachCopy(buf->used+maxappend); 203 REF_UNLOCK; 179 204 appending=buf->used; 180 205 return buf->txt+appending; … … 208 233 { 209 234 if (!count) return; 235 REF_LOCK; 210 236 detachCopy(buf->used+count); 237 REF_UNLOCK; 211 238 buf->append(txt,count); 212 239 } … … 230 257 if (!ch) chlen=0; 231 258 else if (chlen<0) chlen=strlen(ch); 259 REF_LOCK; 232 260 detachEmpty(chlen); 261 REF_UNLOCK; 233 262 memcpy(buf->txt,ch,chlen); 234 263 buf->txt[chlen]=0; buf->used=chlen; … … 243 272 { 244 273 if (s.buf==buf) return; 274 REF_LOCK; 245 275 detach(); 246 276 buf=s.buf; 247 277 if (buf->size) buf->refcount++; 278 REF_UNLOCK; 248 279 } 249 280 /////////////////////////////////////// … … 306 337 } 307 338 308 const SString&SString::valueOf(int i)309 { 310 staticSString t;339 SString SString::valueOf(int i) 340 { 341 SString t; 311 342 sprintf(t.directWrite(20),"%d",i); t.endWrite(); 312 343 return t; 313 344 } 314 const SString&SString::valueOf(long i)315 { 316 staticSString t;345 SString SString::valueOf(long i) 346 { 347 SString t; 317 348 sprintf(t.directWrite(20),"%d",i); t.endWrite(); 318 349 return t; 319 350 } 320 const SString&SString::valueOf(double d)321 { 322 staticSString t;351 SString SString::valueOf(double d) 352 { 353 SString t; 323 354 sprintf(t.directWrite(20),"%g",d); t.endWrite(); 324 355 return t; 325 356 } 326 const SString&SString::valueOf(const SString& s)357 SString SString::valueOf(const SString& s) 327 358 { 328 359 return s; -
cpp/gdk/sstring.h
r92 r104 157 157 char charAt(int pos) const {return buf->txt[pos];} 158 158 159 static const SString&valueOf(int);160 static const SString&valueOf(long);161 static const SString&valueOf(double);162 static const SString&valueOf(const SString&); //tylko do kompletu zeby mozna uzyc tej funkcji nie martwiac sie o typ argumentu159 static SString valueOf(int); 160 static SString valueOf(long); 161 static SString valueOf(double); 162 static SString valueOf(const SString&); //tylko do kompletu zeby mozna uzyc tej funkcji nie martwiac sie o typ argumentu 163 163 static SString valueOf(const ExtValue&); //tylko do kompletu zeby mozna uzyc tej funkcji nie martwiac sie o typ argumentu 164 164 static SString valueOf(const ExtObject&); //tylko do kompletu zeby mozna uzyc tej funkcji nie martwiac sie o typ argumentu -
cpp/gdk/stdouterr.cpp
r81 r104 1 1 // This file is a part of the Framsticks GDK library. 2 // Copyright (C) 2002-201 1Szymon Ulatowski. See LICENSE.txt for details.2 // Copyright (C) 2002-2013 Szymon Ulatowski. See LICENSE.txt for details. 3 3 // Refer to http://www.framsticks.com/ for further information. 4 4 … … 12 12 void StdoutErrorHandler::handle(const char *o,const char *m,const char *bl,int w) 13 13 { 14 static char* level[]={"DEBUG","INFO","WARN","ERROR","CRITICAL"};15 14 if (w<-1) w=-1; else if (w>3) w=3; 16 15 #ifdef SHP 17 AppLog("[%s] %s::%s - %s\n", level[w+1],o,m,bl);16 AppLog("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl); 18 17 #else 19 18 if (file) 20 file->printf("[%s] %s::%s - %s\n", level[w+1],o,m,bl);19 file->printf("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl); 21 20 else 22 printf("[%s] %s::%s - %s\n", level[w+1],o,m,bl);21 printf("[%s] %s::%s - %s\n",MSG_LEVEL[w+1],o,m,bl); 23 22 #endif 24 23 }
Note: See TracChangeset
for help on using the changeset viewer.