ReAntTweakBar.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #include "ReAntTweakBar.h"
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <sstream>
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <map>
  8. #define MAX_CB_VAR_SIZE 10
  9. // Max line size for reading files
  10. #define MAX_LINE 1000
  11. #define MAX_WORD 100
  12. // GLOBAL WRAPPERS
  13. namespace igl
  14. {
  15. std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > > ReTw_custom_types;
  16. }
  17. TwType igl::ReTwDefineEnum(
  18. const char *name,
  19. const TwEnumVal *enumValues,
  20. unsigned int nbValues)
  21. {
  22. // copy enum valus into vector
  23. std::vector<TwEnumVal> enum_vals;
  24. enum_vals.resize(nbValues);
  25. for(unsigned int j = 0; j<nbValues;j++)
  26. {
  27. enum_vals[j] = enumValues[j];
  28. }
  29. TwType type = TwDefineEnum(name,enumValues,nbValues);
  30. ReTw_custom_types[type] =
  31. std::pair<const char *,std::vector<TwEnumVal> >(name,enum_vals);
  32. return type;
  33. }
  34. namespace igl
  35. {
  36. struct ReTwTypeString
  37. {
  38. TwType type;
  39. const char * type_str;
  40. };
  41. #define RETW_NUM_DEFAULT_TYPE_STRINGS 23
  42. ReTwTypeString ReTwDefaultTypeStrings[RETW_NUM_DEFAULT_TYPE_STRINGS] =
  43. {
  44. {TW_TYPE_UNDEF,"TW_TYPE_UNDEF"},
  45. {TW_TYPE_BOOLCPP,"TW_TYPE_BOOLCPP"},
  46. {TW_TYPE_BOOL8,"TW_TYPE_BOOL8"},
  47. {TW_TYPE_BOOL16,"TW_TYPE_BOOL16"},
  48. {TW_TYPE_BOOL32,"TW_TYPE_BOOL32"},
  49. {TW_TYPE_CHAR,"TW_TYPE_CHAR"},
  50. {TW_TYPE_INT8,"TW_TYPE_INT8"},
  51. {TW_TYPE_UINT8,"TW_TYPE_UINT8"},
  52. {TW_TYPE_INT16,"TW_TYPE_INT16"},
  53. {TW_TYPE_UINT16,"TW_TYPE_UINT16"},
  54. {TW_TYPE_INT32,"TW_TYPE_INT32"},
  55. {TW_TYPE_UINT32,"TW_TYPE_UINT32"},
  56. {TW_TYPE_FLOAT,"TW_TYPE_FLOAT"},
  57. {TW_TYPE_DOUBLE,"TW_TYPE_DOUBLE"},
  58. {TW_TYPE_COLOR32,"TW_TYPE_COLOR32"},
  59. {TW_TYPE_COLOR3F,"TW_TYPE_COLOR3F"},
  60. {TW_TYPE_COLOR4F,"TW_TYPE_COLOR4F"},
  61. {TW_TYPE_CDSTRING,"TW_TYPE_CDSTRING"},
  62. {TW_TYPE_STDSTRING,"TW_TYPE_STDSTRING"},
  63. {TW_TYPE_QUAT4F,"TW_TYPE_QUAT4F"},
  64. {TW_TYPE_QUAT4D,"TW_TYPE_QUAT4D"},
  65. {TW_TYPE_DIR3F,"TW_TYPE_DIR3F"},
  66. {TW_TYPE_DIR3D,"TW_TYPE_DIR3D"}
  67. };
  68. }
  69. igl::ReTwBar::ReTwBar():
  70. bar(NULL),rw_items(),cb_items()
  71. {
  72. }
  73. igl::ReTwBar::ReTwBar(const igl::ReTwBar & that):
  74. bar(that.bar),
  75. rw_items(that.rw_items),
  76. cb_items(that.cb_items)
  77. {
  78. }
  79. igl::ReTwBar & igl::ReTwBar::operator=(const igl::ReTwBar & that)
  80. {
  81. // check for self assignment
  82. if(this != &that)
  83. {
  84. bar = that.bar;
  85. rw_items = that.rw_items;
  86. cb_items = that.cb_items;
  87. }
  88. return *this;
  89. }
  90. // BAR WRAPPERS
  91. void igl::ReTwBar::TwNewBar(const char *barName)
  92. {
  93. // double colon without anything in front of it means look for this in the
  94. // global namespace... I hope...
  95. this->bar = ::TwNewBar(barName);
  96. }
  97. int igl::ReTwBar::TwAddVarRW(
  98. const char *name,
  99. TwType type,
  100. void *var,
  101. const char *def,
  102. const bool record)
  103. {
  104. int ret = ::TwAddVarRW(this->bar,name,type,var,def);
  105. if(ret && record)
  106. {
  107. rw_items.push_back(ReTwRWItem(name,type,var));
  108. }
  109. return ret;
  110. }
  111. int igl::ReTwBar::TwAddVarCB(
  112. const char *name,
  113. TwType type,
  114. TwSetVarCallback setCallback,
  115. TwGetVarCallback getCallback,
  116. void *clientData,
  117. const char *def,
  118. const bool record)
  119. {
  120. int ret =
  121. ::TwAddVarCB(this->bar,name,type,setCallback,getCallback,clientData,def);
  122. if(ret && record)
  123. {
  124. cb_items.push_back(ReTwCBItem(name,type,setCallback,getCallback,clientData));
  125. }
  126. return ret;
  127. }
  128. int igl::ReTwBar::TwAddVarRO(
  129. const char *name,
  130. TwType type,
  131. void *var,
  132. const char *def)
  133. {
  134. int ret = ::TwAddVarRO(this->bar,name,type,var,def);
  135. // Read only variables are not recorded
  136. //if(ret)
  137. //{
  138. // rw_items.push_back(ReTwRWItem(name,type,var));
  139. //}
  140. return ret;
  141. }
  142. int igl::ReTwBar::TwAddButton(
  143. const char *name,
  144. TwButtonCallback buttonCallback,
  145. void *clientData,
  146. const char *def)
  147. {
  148. int ret =
  149. ::TwAddButton(this->bar,name,buttonCallback,clientData,def);
  150. // buttons are not recorded
  151. //if(ret)
  152. //{
  153. // cb_items.push_back(ReTwCBItem(name,type,setCallback,getCallback,clientData));
  154. //}
  155. return ret;
  156. }
  157. int igl::ReTwBar::TwSetParam(
  158. const char *varName,
  159. const char *paramName,
  160. TwParamValueType paramValueType,
  161. unsigned int inValueCount,
  162. const void *inValues)
  163. {
  164. // For now just pass these along
  165. return
  166. ::TwSetParam(
  167. this->bar,
  168. varName,
  169. paramName,
  170. paramValueType,
  171. inValueCount,
  172. inValues);
  173. }
  174. int igl::ReTwBar::TwGetParam(
  175. const char *varName,
  176. const char *paramName,
  177. TwParamValueType paramValueType,
  178. unsigned int outValueMaxCount,
  179. void *outValues)
  180. {
  181. return
  182. ::TwGetParam(
  183. this->bar,
  184. varName,
  185. paramName,
  186. paramValueType,
  187. outValueMaxCount,
  188. outValues);
  189. }
  190. int igl::ReTwBar::TwRefreshBar()
  191. {
  192. return ::TwRefreshBar(this->bar);
  193. }
  194. int igl::ReTwBar::TwTerminate()
  195. {
  196. std::cout<<"TwTerminate"<<std::endl;
  197. int r = ::TwTerminate();
  198. std::cout<<" "<<r<<std::endl;
  199. return r;
  200. }
  201. bool igl::ReTwBar::save(const char *file_name)
  202. {
  203. FILE * fp;
  204. if(file_name == NULL)
  205. {
  206. fp = stdout;
  207. }else
  208. {
  209. fp = fopen(file_name,"w");
  210. }
  211. if(fp == NULL)
  212. {
  213. printf("ERROR: not able to open %s for writing...\n",file_name);
  214. return false;
  215. }
  216. // Print all RW variables
  217. for(
  218. std::vector<ReTwRWItem>::iterator it = rw_items.begin();
  219. it != rw_items.end();
  220. it++)
  221. {
  222. std::string s = (*it).name;
  223. const char * name = s.c_str();
  224. TwType type = (*it).type;
  225. void * var = (*it).var;
  226. fprintf(fp,"%s: %s\n",
  227. name,
  228. get_value_as_string(var,type).c_str());
  229. }
  230. char var[MAX_CB_VAR_SIZE];
  231. // Print all CB variables
  232. for(
  233. std::vector<ReTwCBItem>::iterator it = cb_items.begin();
  234. it != cb_items.end();
  235. it++)
  236. {
  237. const char * name = it->name.c_str();
  238. TwType type = it->type;
  239. //TwSetVarCallback setCallback = it->setCallback;
  240. TwGetVarCallback getCallback = it->getCallback;
  241. void * clientData = it->clientData;
  242. // I'm not sure how to do what I want to do. getCallback needs to be sure
  243. // that it can write to var. So var needs to point to a valid and big
  244. // enough chunk of memory
  245. getCallback(var,clientData);
  246. fprintf(fp,"%s: %s\n",
  247. name,
  248. get_value_as_string(var,type).c_str());
  249. }
  250. fprintf(fp,"\n");
  251. if(file_name != NULL)
  252. {
  253. fclose(fp);
  254. }
  255. // everything succeeded
  256. return true;
  257. }
  258. std::string igl::ReTwBar::get_value_as_string(
  259. void * var,
  260. TwType type)
  261. {
  262. std::stringstream sstr;
  263. switch(type)
  264. {
  265. case TW_TYPE_BOOLCPP:
  266. {
  267. sstr << "TW_TYPE_BOOLCPP" << " ";
  268. sstr << *(static_cast<bool*>(var));
  269. break;
  270. }
  271. case TW_TYPE_QUAT4D:
  272. {
  273. sstr << "TW_TYPE_QUAT4D" << " ";
  274. // Q: Why does casting to double* work? shouldn't I have to cast to
  275. // double**?
  276. double * q = static_cast<double*>(var);
  277. sstr << q[0] << " " << q[1] << " " << q[2] << " " << q[3];
  278. break;
  279. }
  280. case TW_TYPE_QUAT4F:
  281. {
  282. sstr << "TW_TYPE_QUAT4F" << " ";
  283. // Q: Why does casting to float* work? shouldn't I have to cast to
  284. // float**?
  285. float * q = static_cast<float*>(var);
  286. sstr << q[0] << " " << q[1] << " " << q[2] << " " << q[3];
  287. break;
  288. }
  289. case TW_TYPE_COLOR4F:
  290. {
  291. sstr << "TW_TYPE_COLOR4F" << " ";
  292. float * c = static_cast<float*>(var);
  293. sstr << c[0] << " " << c[1] << " " << c[2] << " " << c[3];
  294. break;
  295. }
  296. case TW_TYPE_COLOR3F:
  297. {
  298. sstr << "TW_TYPE_COLOR3F" << " ";
  299. float * c = static_cast<float*>(var);
  300. sstr << c[0] << " " << c[1] << " " << c[2];
  301. break;
  302. }
  303. case TW_TYPE_DIR3D:
  304. {
  305. sstr << "TW_TYPE_DIR3D" << " ";
  306. double * d = static_cast<double*>(var);
  307. sstr << d[0] << " " << d[1] << " " << d[2];
  308. break;
  309. }
  310. case TW_TYPE_DIR3F:
  311. {
  312. sstr << "TW_TYPE_DIR3F" << " ";
  313. float * d = static_cast<float*>(var);
  314. sstr << d[0] << " " << d[1] << " " << d[2];
  315. break;
  316. }
  317. case TW_TYPE_BOOL32:
  318. {
  319. sstr << "TW_TYPE_BOOL32" << " ";
  320. sstr << *(static_cast<int*>(var));
  321. break;
  322. }
  323. case TW_TYPE_INT32:
  324. {
  325. sstr << "TW_TYPE_INT32" << " ";
  326. sstr << *(static_cast<int*>(var));
  327. break;
  328. }
  329. case TW_TYPE_FLOAT:
  330. {
  331. sstr << "TW_TYPE_FLOAT" << " ";
  332. sstr << *(static_cast<float*>(var));
  333. break;
  334. }
  335. case TW_TYPE_DOUBLE:
  336. {
  337. sstr << "TW_TYPE_DOUBLE" << " ";
  338. sstr << std::setprecision(15) << *(static_cast<double*>(var));
  339. break;
  340. }
  341. default:
  342. {
  343. std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter =
  344. ReTw_custom_types.find(type);
  345. if(iter != ReTw_custom_types.end())
  346. {
  347. sstr << (*iter).second.first << " ";
  348. int enum_val = *(static_cast<int*>(var));
  349. // try find display name for enum value
  350. std::vector<TwEnumVal>::iterator eit = (*iter).second.second.begin();
  351. bool found = false;
  352. for(;eit<(*iter).second.second.end();eit++)
  353. {
  354. if(enum_val == eit->Value)
  355. {
  356. sstr << eit->Label;
  357. found = true;
  358. break;
  359. }
  360. }
  361. if(!found)
  362. {
  363. sstr << "ERROR_ENUM_VALUE_NOT_DEFINED";
  364. }
  365. }else
  366. {
  367. sstr << "ERROR_TYPE_NOT_SUPPORTED";
  368. }
  369. break;
  370. }
  371. }
  372. return sstr.str();
  373. }
  374. bool igl::ReTwBar::load(const char *file_name)
  375. {
  376. FILE * fp;
  377. fp = fopen(file_name,"r");
  378. if(fp == NULL)
  379. {
  380. printf("ERROR: not able to open %s for reading...\n",file_name);
  381. return false;
  382. }
  383. // go through file line by line
  384. char line[MAX_LINE];
  385. bool still_comments;
  386. char name[MAX_WORD];
  387. char type_str[MAX_WORD];
  388. char value_str[MAX_WORD];
  389. // line number
  390. int j = 0;
  391. bool finished = false;
  392. while(true)
  393. {
  394. // Eat comments
  395. still_comments = true;
  396. while(still_comments)
  397. {
  398. if(fgets(line,MAX_LINE,fp) == NULL)
  399. {
  400. finished = true;
  401. break;
  402. }
  403. // Blank lines and lines that begin with # are comments
  404. still_comments = (line[0] == '#' || line[0] == '\n');
  405. j++;
  406. }
  407. if(finished)
  408. {
  409. break;
  410. }
  411. sscanf(line,"%[^:]: %s %[^\n]",name,type_str,value_str);
  412. //printf("%s: %s %s\n",name, type_str,value_str);
  413. TwType type;
  414. if(!type_from_string(type_str,type))
  415. {
  416. printf("ERROR: %s type not found... Skipping...\n",type_str);
  417. continue;
  418. }
  419. set_value_from_string(name,type,value_str);
  420. }
  421. fclose(fp);
  422. // everything succeeded
  423. return true;
  424. }
  425. bool igl::ReTwBar::type_from_string(const char *type_str, TwType & type)
  426. {
  427. // first check default types
  428. for(int j = 0; j < RETW_NUM_DEFAULT_TYPE_STRINGS; j++)
  429. {
  430. if(strcmp(type_str,ReTwDefaultTypeStrings[j].type_str) == 0)
  431. {
  432. type = ReTwDefaultTypeStrings[j].type;
  433. return true;
  434. break;
  435. }
  436. }
  437. // then check custom types
  438. std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter =
  439. ReTw_custom_types.begin();
  440. for(;iter != ReTw_custom_types.end(); iter++)
  441. {
  442. if(strcmp((*iter).second.first,type_str)==0)
  443. {
  444. type = (*iter).first;
  445. return true;
  446. }
  447. }
  448. return false;
  449. }
  450. bool igl::ReTwBar::set_value_from_string(
  451. const char * name,
  452. TwType type,
  453. const char * value_str)
  454. {
  455. void * value = NULL;
  456. // possible value slots
  457. int i;
  458. float v;
  459. double dv;
  460. float f[4];
  461. double d[4];
  462. bool b;
  463. // First try to get value from default types
  464. switch(type)
  465. {
  466. case TW_TYPE_BOOLCPP:
  467. {
  468. int ib;
  469. if(sscanf(value_str," %d",&ib) == 1)
  470. {
  471. b = ib!=0;
  472. value = &b;
  473. }else
  474. {
  475. printf("ERROR: Bad value format...\n");
  476. return false;
  477. }
  478. break;
  479. }
  480. case TW_TYPE_QUAT4D:
  481. //case TW_TYPE_COLOR4D:
  482. {
  483. if(sscanf(value_str," %lf %lf %lf %lf",&d[0],&d[1],&d[2],&d[3]) == 4)
  484. {
  485. value = &d;
  486. }else
  487. {
  488. printf("ERROR: Bad value format...\n");
  489. return false;
  490. }
  491. break;
  492. }
  493. case TW_TYPE_QUAT4F:
  494. case TW_TYPE_COLOR4F:
  495. {
  496. if(sscanf(value_str," %f %f %f %f",&f[0],&f[1],&f[2],&f[3]) == 4)
  497. {
  498. value = &f;
  499. }else
  500. {
  501. printf("ERROR: Bad value format...\n");
  502. return false;
  503. }
  504. break;
  505. }
  506. //case TW_TYPE_COLOR3D:
  507. case TW_TYPE_DIR3D:
  508. {
  509. if(sscanf(value_str," %lf %lf %lf",&d[0],&d[1],&d[2]) == 3)
  510. {
  511. value = &d;
  512. }else
  513. {
  514. printf("ERROR: Bad value format...\n");
  515. return false;
  516. }
  517. break;
  518. }
  519. case TW_TYPE_COLOR3F:
  520. case TW_TYPE_DIR3F:
  521. {
  522. if(sscanf(value_str," %f %f %f",&f[0],&f[1],&f[2]) == 3)
  523. {
  524. value = &f;
  525. }else
  526. {
  527. printf("ERROR: Bad value format...\n");
  528. return false;
  529. }
  530. break;
  531. }
  532. case TW_TYPE_BOOL32:
  533. case TW_TYPE_INT32:
  534. {
  535. if(sscanf(value_str," %d",&i) == 1)
  536. {
  537. value = &i;
  538. }else
  539. {
  540. printf("ERROR: Bad value format...\n");
  541. return false;
  542. }
  543. break;
  544. }
  545. case TW_TYPE_FLOAT:
  546. {
  547. if(sscanf(value_str," %f",&v) == 1)
  548. {
  549. value = &v;
  550. }else
  551. {
  552. printf("ERROR: Bad value format...\n");
  553. return false;
  554. }
  555. break;
  556. }
  557. case TW_TYPE_DOUBLE:
  558. {
  559. if(sscanf(value_str," %lf",&dv) == 1)
  560. {
  561. value = &dv;
  562. }else
  563. {
  564. printf("ERROR: Bad value format...\n");
  565. return false;
  566. }
  567. break;
  568. }
  569. default:
  570. // Try to find type in custom enum types
  571. std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter =
  572. ReTw_custom_types.find(type);
  573. if(iter != ReTw_custom_types.end())
  574. {
  575. std::vector<TwEnumVal>::iterator eit = (*iter).second.second.begin();
  576. bool found = false;
  577. for(;eit<(*iter).second.second.end();eit++)
  578. {
  579. if(strcmp(value_str,eit->Label) == 0)
  580. {
  581. i = eit->Value;
  582. value = &i;
  583. found = true;
  584. break;
  585. }
  586. }
  587. if(!found)
  588. {
  589. printf("ERROR_ENUM_VALUE_NOT_DEFINED");
  590. }
  591. }else
  592. {
  593. printf("ERROR_TYPE_NOT_SUPPORTED\n");
  594. }
  595. break;
  596. }
  597. // Find variable based on name
  598. // First look in RW items
  599. bool item_found = false;
  600. for(
  601. std::vector<ReTwRWItem>::iterator it = rw_items.begin();
  602. it != rw_items.end();
  603. it++)
  604. {
  605. if(it->name == name)
  606. {
  607. void * var = it->var;
  608. switch(type)
  609. {
  610. case TW_TYPE_BOOLCPP:
  611. {
  612. bool * bvar = static_cast<bool*>(var);
  613. bool * bvalue = static_cast<bool*>(value);
  614. *bvar = *bvalue;
  615. break;
  616. }
  617. case TW_TYPE_QUAT4D:
  618. //case TW_TYPE_COLOR4D:
  619. {
  620. double * dvar = static_cast<double*>(var);
  621. double * dvalue = static_cast<double*>(value);
  622. dvar[0] = dvalue[0];
  623. dvar[1] = dvalue[1];
  624. dvar[2] = dvalue[2];
  625. dvar[3] = dvalue[3];
  626. break;
  627. }
  628. case TW_TYPE_QUAT4F:
  629. case TW_TYPE_COLOR4F:
  630. {
  631. float * fvar = static_cast<float*>(var);
  632. float * fvalue = static_cast<float*>(value);
  633. fvar[0] = fvalue[0];
  634. fvar[1] = fvalue[1];
  635. fvar[2] = fvalue[2];
  636. fvar[3] = fvalue[3];
  637. break;
  638. }
  639. //case TW_TYPE_COLOR3D:
  640. case TW_TYPE_DIR3D:
  641. {
  642. double * dvar = static_cast<double*>(var);
  643. double * dvalue = static_cast<double*>(value);
  644. dvar[0] = dvalue[0];
  645. dvar[1] = dvalue[1];
  646. dvar[2] = dvalue[2];
  647. break;
  648. }
  649. case TW_TYPE_COLOR3F:
  650. case TW_TYPE_DIR3F:
  651. {
  652. float * fvar = static_cast<float*>(var);
  653. float * fvalue = static_cast<float*>(value);
  654. fvar[0] = fvalue[0];
  655. fvar[1] = fvalue[1];
  656. fvar[2] = fvalue[2];
  657. break;
  658. }
  659. case TW_TYPE_BOOL32:
  660. case TW_TYPE_INT32:
  661. {
  662. int * ivar = static_cast<int*>(var);
  663. int * ivalue = static_cast<int*>(value);
  664. *ivar = *ivalue;
  665. break;
  666. }
  667. case TW_TYPE_FLOAT:
  668. {
  669. float * fvar = static_cast<float*>(var);
  670. float * fvalue = static_cast<float*>(value);
  671. *fvar = *fvalue;
  672. break;
  673. }
  674. case TW_TYPE_DOUBLE:
  675. {
  676. double * dvar = static_cast<double*>(var);
  677. double * fvalue = static_cast<double*>(value);
  678. *dvar = *fvalue;
  679. break;
  680. }
  681. default:
  682. // Try to find type in custom enum types
  683. std::map<TwType,std::pair<const char *,std::vector<TwEnumVal> > >::iterator iter =
  684. ReTw_custom_types.find(type);
  685. if(iter != ReTw_custom_types.end())
  686. {
  687. int * ivar = static_cast<int*>(var);
  688. std::vector<TwEnumVal>::iterator eit = (*iter).second.second.begin();
  689. bool found = false;
  690. for(;eit<(*iter).second.second.end();eit++)
  691. {
  692. if(strcmp(value_str,eit->Label) == 0)
  693. {
  694. *ivar = eit->Value;
  695. found = true;
  696. break;
  697. }
  698. }
  699. if(!found)
  700. {
  701. printf("ERROR_ENUM_VALUE_NOT_DEFINED");
  702. }
  703. }else
  704. {
  705. printf("ERROR_TYPE_NOT_SUPPORTED\n");
  706. }
  707. break;
  708. }
  709. item_found = true;
  710. break;
  711. }
  712. }
  713. // Try looking in CB items
  714. if(!item_found)
  715. {
  716. for(
  717. std::vector<ReTwCBItem>::iterator it = cb_items.begin();
  718. it != cb_items.end();
  719. it++)
  720. {
  721. if(it->name==name)
  722. {
  723. it->setCallback(value,it->clientData);
  724. item_found = true;
  725. break;
  726. }
  727. }
  728. }
  729. if(!item_found)
  730. {
  731. printf("ERROR: item not found\n");
  732. }
  733. return true;
  734. }