- Timestamp:
- 10/17/22 12:28:47 (2 years ago)
- Location:
- cpp/frams/param
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/param.cpp
r1155 r1184 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-202 0Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2022 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 49 49 return (const char*)memchr((const void*)t, ch, limit - t); 50 50 } 51 52 53 Param2ParamCopy::Param2ParamCopy(ParamInterface& schema, const std::initializer_list<const char*> names) 54 { 55 for (const char* n : names) 56 { 57 int i = schema.findId(n); 58 if (i >= 0) 59 fields.push_back(i); 60 else 61 logPrintf("Param2ParamCopy", "findId", LOG_CRITICAL, "Can't find '%s.%s'", schema.getName(), n); 62 } 63 } 64 65 void Param2ParamCopy::operator()(const ParamInterface& from, ParamInterface& to) 66 { 67 ExtValue tmp; 68 for (int i : fields) 69 { 70 ((ParamInterface&)from).get(i, tmp); 71 to.set(i, tmp); 72 } 73 } 74 51 75 52 76 void ParamInterface::copyFrom(ParamInterface *src) -
cpp/frams/param/param.h
r1155 r1184 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 17Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2022 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 8 8 #include <stdio.h> 9 9 #include <stdint.h> 10 #include <vector> 10 11 #include <frams/util/sstring.h> 11 12 #include <frams/util/sstringutils.h> … … 199 200 }; 200 201 202 203 204 /** Copy fields between two compatible params. A Param2ParamCopy object can be static so the field names are only looked up once. */ 205 class Param2ParamCopy 206 { 207 std::vector<int> fields; 208 public: 209 Param2ParamCopy(ParamInterface& schema, const std::initializer_list<const char*> names); 210 void operator()(const ParamInterface& from, ParamInterface& to); 211 }; 212 213 214 215 201 216 // implementations: 202 217 … … 317 332 }; 318 333 334 #ifdef _DEBUG 335 #define CHECK_PARAMENTRY_COUNT // This could be the only version, because it is not significantly more costly than the other one. Now we have a _DEBUG (checking, slightly slower) version and a non-_DEBUG (i.e. release, non-checking, slightly faster) version. Since both versions are completely different, the non-_DEBUG (release) version is not verified at all during thorough _DEBUG testing. 336 #endif 337 319 338 class Param : public SimpleAbstractParam 320 339 { … … 329 348 */ 330 349 350 #ifdef CHECK_PARAMENTRY_COUNT 351 352 template <int COUNT> 353 Param(ParamEntry (&t)[COUNT],void* o = 0, const char*n = 0) :SimpleAbstractParam(o, n), tab(t) 354 { 355 if (!n&&tab) myname = tab[0].name; 356 //printf("Param(ParamEntry t[%d]) %s\n",COUNT,myname?myname:"unknown name"); 357 if (tab) 358 { 359 int in_array = COUNT-1-tab[0].group; 360 if (tab[0].flags != in_array) 361 printf("\nCHECK_PARAMENTRY_COUNT: %d items in ParamEntry[] array, declared %d (%s)\n\n",in_array, tab[0].flags, myname?myname:"unknown name"); 362 if (in_array>0 && tab[COUNT-1].id != NULL) //in_array>0 -> completely empty paramtab can't end with the usual zero row because that's also its first row 363 printf("\nCHECK_PARAMENTRY_COUNT: last entry is not null (%s)\n\n",myname?myname:"unknown name"); 364 } 365 } 366 367 template<typename T, typename std::enable_if_t<std::is_same<ParamEntry*,T>::value>* = nullptr > //SFINAE-fu because the normal ParamEntry* overload would be also called for ParamEntry[COUNT] argument 368 Param(T t, void* o = 0, const char*n = 0) :SimpleAbstractParam(o, n), tab(t) 369 { 370 //printf("Param(ParamEntry* t) %s\n",tab?tab[0].name:""); 371 if (!n&&tab) myname = tab[0].name; 372 } 373 374 Param() :SimpleAbstractParam(NULL, NULL), tab(NULL) 375 { 376 //printf("Param(NULL)\n"); 377 } 378 379 #else // CHECK_PARAMENTRY_COUNT 380 331 381 Param(ParamEntry *t = 0, void* o = 0, const char*n = 0) :SimpleAbstractParam(o, n), tab(t) 332 382 { 333 383 if (!n&&tab) myname = tab[0].name; 334 384 } 335 385 386 #endif // CHECK_PARAMENTRY_COUNT 387 336 388 Param(const Param& p) :SimpleAbstractParam(p.object, p.myname), tab(p.tab) {} 337 389 void operator=(const Param&p) { object = p.object; myname = p.myname; tab = p.tab; }
Note: See TracChangeset
for help on using the changeset viewer.