PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 1ms

/Extras/COLLADA_DOM/src/dae/daeAtomicType.cpp

http://dynamica.googlecode.com/
C++ | 779 lines | 679 code | 48 blank | 52 comment | 108 complexity | fc93c6617bb136ca20cdeacccd039fc6 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-3.0
  1. /*
  2. * Copyright 2006 Sony Computer Entertainment Inc.
  3. *
  4. * Licensed under the SCEA Shared Source License, Version 1.0 (the "License"); you may not use this
  5. * file except in compliance with the License. You may obtain a copy of the License at:
  6. * http://research.scea.com/scea_shared_source_license.html
  7. *
  8. * Unless required by applicable law or agreed to in writing, software distributed under the License
  9. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied. See the License for the specific language governing permissions and limitations under the
  11. * License.
  12. */
  13. #include <dae/daeAtomicType.h>
  14. #include <dae/daeElement.h>
  15. #include <dae/daeURI.h>
  16. #include <dae/daeIDRef.h>
  17. #include <dae/daeMetaElement.h>
  18. #include <dae/daeDatabase.h>
  19. #include <dae/daeErrorHandler.h>
  20. daeAtomicTypeArray* daeAtomicType::_Types = NULL;
  21. daeBool daeAtomicType::_TypesInitialized = false;
  22. void
  23. daeAtomicType::initializeKnownTypes()
  24. {
  25. _Types = new daeAtomicTypeArray;
  26. initializeKnownBaseTypes();
  27. //mandatory to set here, because the array types are querying the atomic types
  28. _TypesInitialized = true;
  29. }
  30. void
  31. daeAtomicType::uninitializeKnownTypes()
  32. {
  33. if ( _TypesInitialized )
  34. {
  35. _TypesInitialized = false;
  36. unsigned int i;
  37. for (i=0;i<_Types->getCount();i++)
  38. {
  39. daeAtomicType* type = _Types->get(i);
  40. delete type;
  41. }
  42. delete _Types;
  43. }
  44. }
  45. void
  46. daeAtomicType::initializeKnownBaseTypes()
  47. {
  48. _Types->append(new daeUIntType);
  49. _Types->append(new daeIntType);
  50. _Types->append(new daeLongType);
  51. _Types->append(new daeShortType);
  52. _Types->append(new daeUIntType);
  53. _Types->append(new daeULongType);
  54. _Types->append(new daeFloatType);
  55. _Types->append(new daeDoubleType);
  56. _Types->append(new daeStringRefType);
  57. _Types->append(new daeElementRefType);
  58. _Types->append(new daeEnumType);
  59. _Types->append(new daeRawRefType);
  60. _Types->append(new daeResolverType);
  61. _Types->append(new daeIDResolverType);
  62. _Types->append(new daeBoolType);
  63. _Types->append(new daeTokenType);
  64. }
  65. daeAtomicType*
  66. daeAtomicType::get(daeStringRef typeString)
  67. {
  68. if (!_TypesInitialized)
  69. daeAtomicType::initializeKnownTypes();
  70. int tCount = (int)_Types->getCount();
  71. int i;
  72. for(i=0; i<tCount; i++) {
  73. daeAtomicType* type = _Types->get(i);
  74. daeStringRefArray& nameBindings = type->getNameBindings();
  75. int count = (int)nameBindings.getCount();
  76. int j;
  77. for(j=0;j<count;j++)
  78. if (!strcmp(nameBindings[j],typeString))
  79. break;
  80. if (j!=count)
  81. return type;
  82. }
  83. return NULL;
  84. }
  85. daeAtomicType::daeAtomicType()
  86. {
  87. _size = -1;
  88. _alignment = -1;
  89. _typeEnum = -1;
  90. _typeString = "notype";
  91. _printFormat = "badtype";
  92. _scanFormat = "";
  93. _maxStringLength = -1;
  94. }
  95. daeAtomicType*
  96. daeAtomicType::get(daeEnum typeEnum)
  97. {
  98. if (!_TypesInitialized)
  99. daeAtomicType::initializeKnownTypes();
  100. int tCount = (int)_Types->getCount();
  101. int i;
  102. for(i=0; i<tCount; i++) {
  103. daeAtomicType* type = _Types->get(i);
  104. if (type->getTypeEnum() == typeEnum)
  105. return type;
  106. }
  107. return NULL;
  108. }
  109. daeBool
  110. daeAtomicType::stringToMemory(daeChar *src, daeChar* dstMemory)
  111. {
  112. sscanf(src, _scanFormat, dstMemory);
  113. return true;
  114. }
  115. daeBool
  116. daeAtomicType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  117. {
  118. // just to remove the warnings
  119. (void)src;
  120. if (dstSize > 32)
  121. sprintf(dst,"unknown type string conversion\n");
  122. return true;
  123. }
  124. daeInt
  125. daeAtomicType::append(daeAtomicType* t) {
  126. if (!_TypesInitialized)
  127. daeAtomicType::initializeKnownTypes();
  128. return (daeInt)_Types->append(t);
  129. }
  130. const daeAtomicType*
  131. daeAtomicType::getByIndex(daeInt index) {
  132. return _Types->get(index);
  133. }
  134. daeInt
  135. daeAtomicType::getCount() {
  136. return (daeInt)_Types->getCount();
  137. }
  138. daeEnumType::daeEnumType()
  139. {
  140. _size = sizeof(daeEnum);
  141. _alignment = sizeof(daeEnum);
  142. _typeEnum = EnumType;
  143. _nameBindings.append("enum");
  144. _printFormat = "%s";//"%%.%ds";
  145. _scanFormat = "%s";
  146. _strings = NULL;
  147. _values = NULL;
  148. _typeString = "enum";
  149. }
  150. daeEnumType::~daeEnumType() {
  151. if ( _strings ) {
  152. delete _strings;
  153. _strings = NULL;
  154. }
  155. if ( _values ) {
  156. delete _values;
  157. _values = NULL;
  158. }
  159. }
  160. daeBoolType::daeBoolType()
  161. {
  162. _size = sizeof(daeBool);
  163. _alignment = sizeof(daeBool);
  164. _typeEnum = BoolType;
  165. _printFormat = "%d";
  166. _scanFormat = "%d";
  167. _typeString = "bool";
  168. _maxStringLength = (daeInt)strlen("false")+1;
  169. _nameBindings.append("bool");
  170. //_nameBindings.append("xsBool");
  171. _nameBindings.append("xsBoolean");
  172. }
  173. daeIntType::daeIntType()
  174. {
  175. _size = sizeof(daeInt);
  176. _alignment = sizeof(daeInt);
  177. _typeEnum = IntType;
  178. _maxStringLength = 16;
  179. _nameBindings.append("int");
  180. _nameBindings.append("xsInteger");
  181. _nameBindings.append("xsHexBinary");
  182. _nameBindings.append("xsIntegerArray");
  183. _nameBindings.append("xsHexBinaryArray");
  184. _nameBindings.append("xsByte");
  185. _nameBindings.append("xsInt");
  186. _printFormat = "%d";
  187. _scanFormat = "%d";
  188. _typeString = "int";
  189. }
  190. daeLongType::daeLongType()
  191. {
  192. _size = sizeof(daeLong);
  193. _alignment = sizeof(daeLong);
  194. _typeEnum = LongType;
  195. _maxStringLength = 32;
  196. _nameBindings.append("xsLong");
  197. _nameBindings.append("xsLongArray");
  198. _printFormat = "%lld";
  199. _scanFormat = "%lld";
  200. _typeString = "long";
  201. }
  202. daeShortType::daeShortType()
  203. {
  204. _maxStringLength = 8;
  205. _size = sizeof(daeShort);
  206. _alignment = sizeof(daeShort);
  207. _typeEnum = ShortType;
  208. _nameBindings.append("short");
  209. _nameBindings.append("xsShort");
  210. _printFormat = "%hd";
  211. _scanFormat = "%hd";
  212. _typeString = "short";
  213. }
  214. daeUIntType::daeUIntType()
  215. {
  216. _maxStringLength = 16;
  217. _size = sizeof(daeUInt);
  218. _alignment = sizeof(daeUInt);
  219. _typeEnum = UIntType;
  220. _nameBindings.append("uint");
  221. _nameBindings.append("xsNonNegativeInteger");
  222. _nameBindings.append("xsUnsignedByte");
  223. _nameBindings.append("xsUnsignedInt");
  224. _nameBindings.append("xsPositiveInteger");
  225. _printFormat = "%u";
  226. _scanFormat = "%u";
  227. _typeString = "uint";
  228. }
  229. daeULongType::daeULongType()
  230. {
  231. _size = sizeof(daeULong);
  232. _alignment = sizeof(daeULong);
  233. _typeEnum = ULongType;
  234. _maxStringLength = 32;
  235. _nameBindings.append("ulong");
  236. _nameBindings.append("xsUnsignedLong");
  237. _printFormat = "%llu";
  238. _scanFormat = "%llu";
  239. _typeString = "ulong";
  240. }
  241. daeFloatType::daeFloatType()
  242. {
  243. _maxStringLength = 64;
  244. _size = sizeof(daeFloat);
  245. _alignment = sizeof(daeFloat);
  246. _typeEnum = FloatType;
  247. _nameBindings.append("float");
  248. _nameBindings.append("xsFloat");
  249. _printFormat = "%g";
  250. _scanFormat = "%g";
  251. _typeString = "float";
  252. }
  253. daeDoubleType::daeDoubleType()
  254. {
  255. _size = sizeof(daeDouble);
  256. _alignment = sizeof(daeDouble);
  257. _typeEnum = DoubleType;
  258. _nameBindings.append("double");
  259. _nameBindings.append("xsDouble");
  260. _nameBindings.append("xsDecimal");
  261. _printFormat = "%lg";
  262. _scanFormat = "%lg";
  263. _typeString = "double";
  264. _maxStringLength = 64;
  265. }
  266. daeStringRefType::daeStringRefType()
  267. {
  268. _size = sizeof(daeStringRef);
  269. _alignment = sizeof(daeStringRef);
  270. _typeEnum = StringRefType;
  271. _nameBindings.append("string");
  272. _nameBindings.append("xsString");
  273. _nameBindings.append("xsDateTime");
  274. _printFormat = "%s";
  275. _scanFormat = "%s";
  276. _typeString = "string";
  277. }
  278. daeTokenType::daeTokenType()
  279. {
  280. _size = sizeof(daeStringRef);
  281. _alignment = sizeof(daeStringRef);
  282. _typeEnum = TokenType;
  283. _nameBindings.append("token");
  284. _nameBindings.append("xsID");
  285. _nameBindings.append("xsNCName");
  286. _nameBindings.append("xsNMTOKEN");
  287. _nameBindings.append("xsName");
  288. _nameBindings.append("xsToken");
  289. _nameBindings.append("xsNameArray");
  290. _nameBindings.append("xsTokenArray");
  291. _nameBindings.append("xsNCNameArray");
  292. _printFormat = "%s";
  293. _scanFormat = "%s";
  294. _typeString = "token";
  295. }
  296. daeElementRefType::daeElementRefType()
  297. {
  298. _size = sizeof(daeElementRef);
  299. _alignment = sizeof(daeElementRef);
  300. _typeEnum = ElementRefType;
  301. _nameBindings.append("element");
  302. _nameBindings.append("Element");
  303. _nameBindings.append("TrackedElement");
  304. _printFormat = "%p";
  305. _scanFormat = "%p";
  306. _typeString = "element";
  307. _maxStringLength = 64;
  308. }
  309. daeRawRefType::daeRawRefType()
  310. {
  311. _size = sizeof(daeRawRef);
  312. _alignment = sizeof(daeRawRef);
  313. _typeEnum = RawRefType;
  314. _nameBindings.append("raw");
  315. _printFormat = "%p";
  316. _scanFormat = "%p";
  317. _typeString = "raw";
  318. _maxStringLength = 64;
  319. }
  320. daeResolverType::daeResolverType()
  321. {
  322. _size = sizeof(daeURI);
  323. _alignment = sizeof(daeURI);
  324. _typeEnum = ResolverType;
  325. _nameBindings.append("resolver");
  326. _nameBindings.append("xsAnyURI");
  327. _printFormat = "%s";
  328. _scanFormat = "%s";
  329. _typeString = "resolver";
  330. }
  331. daeIDResolverType::daeIDResolverType()
  332. {
  333. _size = sizeof(daeIDRef);
  334. _alignment = sizeof(daeIDRef);
  335. _typeEnum = IDResolverType;
  336. _nameBindings.append("xsIDREF");
  337. _nameBindings.append("xsIDREFS");
  338. _printFormat = "%s";
  339. _scanFormat = "%s";
  340. _typeString = "idref_resolver";
  341. }
  342. daeBool
  343. daeIntType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  344. {
  345. if (_maxStringLength > dstSize) return false;
  346. sprintf(dst,_printFormat,*((daeInt*)src));
  347. return true;
  348. }
  349. daeBool
  350. daeLongType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  351. {
  352. if (_maxStringLength > dstSize) return false;
  353. sprintf(dst,_printFormat,*((daeLong*)src));
  354. return true;
  355. }
  356. daeBool
  357. daeShortType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  358. {
  359. if (_maxStringLength > dstSize) return false;
  360. sprintf(dst,_printFormat,*((daeShort*)src));
  361. return true;
  362. }
  363. daeBool
  364. daeUIntType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  365. {
  366. if (_maxStringLength > dstSize) return false;
  367. sprintf(dst,_printFormat,*((daeUInt*)src));
  368. return true;
  369. }
  370. daeBool
  371. daeULongType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  372. {
  373. if (_maxStringLength > dstSize) return false;
  374. sprintf(dst,_printFormat,*((daeULong*)src));
  375. return true;
  376. }
  377. daeBool
  378. daeFloatType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  379. {
  380. if (_maxStringLength > dstSize) return false;
  381. if ( *(daeFloat*)src != *(daeFloat*)src ) //NAN
  382. {
  383. strcpy( dst, "NaN" );
  384. }
  385. else if ( *(daeUInt*)src == 0x7f800000 ) //+INF
  386. {
  387. strcpy( dst, "INF" );
  388. }
  389. else if ( *(daeUInt*)src == 0xff800000 ) //-INF
  390. {
  391. strcpy( dst, "-INF" );
  392. }
  393. else
  394. {
  395. sprintf(dst,_printFormat,*((daeFloat*)src));
  396. }
  397. return true;
  398. }
  399. daeBool
  400. daeFloatType::stringToMemory(daeChar *src, daeChar* dstMemory)
  401. {
  402. if ( strcmp(src, "NaN") == 0 ) {
  403. daeErrorHandler::get()->handleWarning("NaN encountered while setting an attribute or value\n");
  404. *(daeInt*)(dstMemory) = 0x7f800002;
  405. }
  406. else if ( strcmp(src, "INF") == 0 ) {
  407. daeErrorHandler::get()->handleWarning( "INF encountered while setting an attribute or value\n" );
  408. *(daeInt*)(dstMemory) = 0x7f800000;
  409. }
  410. else if ( strcmp(src, "-INF") == 0 ) {
  411. daeErrorHandler::get()->handleWarning( "-INF encountered while setting an attribute or value\n" );
  412. *(daeInt*)(dstMemory) = 0xff800000;
  413. }
  414. else
  415. {
  416. sscanf(src, _scanFormat, dstMemory);
  417. }
  418. return true;
  419. }
  420. daeBool
  421. daeDoubleType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  422. {
  423. if (_maxStringLength > dstSize) return false;
  424. if ( *(daeDouble*)src != *(daeDouble*)src ) //NAN
  425. {
  426. strcpy( dst, "NaN" );
  427. }
  428. #if !(defined (_MSC_VER) && _MSC_VER < 1300)
  429. //this breaks visual studio 2006, so ignore NaN/INF rather then break the build
  430. else if ( *(daeULong*)src == 0x7ff0000000000000LL ) //+INF
  431. {
  432. strcpy( dst, "INF" );
  433. }
  434. else if ( *(daeULong*)src == 0xfff0000000000000LL ) //-INF
  435. {
  436. strcpy( dst, "-INF" );
  437. }
  438. #endif
  439. else
  440. {
  441. sprintf(dst,_printFormat,*((daeDouble*)src));
  442. }
  443. return true;
  444. }
  445. daeBool
  446. daeDoubleType::stringToMemory(daeChar *src, daeChar* dstMemory)
  447. {
  448. #if !(defined (_MSC_VER) && _MSC_VER < 1300)
  449. //this breaks visual studio 2006, so ignore NaN/INF rather then break the build
  450. if ( strcmp(src, "NaN") == 0 ) {
  451. daeErrorHandler::get()->handleWarning( "NaN encountered while setting an attribute or value\n" );
  452. *(daeLong*)(dstMemory) = 0x7ff0000000000002LL;
  453. }
  454. else if ( strcmp(src, "INF") == 0 ) {
  455. daeErrorHandler::get()->handleWarning( "INF encountered while setting an attribute or value\n" );
  456. *(daeLong*)(dstMemory) = 0x7ff0000000000000LL;
  457. }
  458. else if ( strcmp(src, "-INF") == 0 ) {
  459. daeErrorHandler::get()->handleWarning( "-INF encountered while setting an attribute or value\n" );
  460. *(daeLong*)(dstMemory) = 0xfff0000000000000LL;
  461. }
  462. else
  463. #endif
  464. {
  465. sscanf(src, _scanFormat, dstMemory);
  466. }
  467. return true;
  468. }
  469. daeBool
  470. daeRawRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  471. {
  472. if (_maxStringLength > dstSize) return false;
  473. sprintf(dst,"%p",(void *)(*((daeRawRef*)src)));
  474. return true;
  475. }
  476. daeBool
  477. daeStringRefType::getUsesStrings()
  478. {
  479. return true;
  480. }
  481. daeBool
  482. daeTokenType::getUsesStrings()
  483. {
  484. return false;
  485. }
  486. daeBool
  487. daeStringRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  488. {
  489. daeString s = *((daeStringRef *)src);
  490. if (!s || strlen(s) == 0)
  491. dst[0] = '\0';
  492. else {
  493. char tmp[64];
  494. sprintf(tmp,"%%.%ds",dstSize-1);
  495. sprintf(dst,tmp,(const char*)s);
  496. if ((daeInt)(strlen(s)+1) > dstSize)
  497. return false;
  498. }
  499. return true;
  500. }
  501. daeBool
  502. daeResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  503. {
  504. #if 1
  505. // Get the URI we are trying to write
  506. daeURI *thisURI = ((daeURI *)src);
  507. daeString s;
  508. // !!!GAC We may want to re-resolve the URI before writing, if so call thisURI->resolveURI() here
  509. // !!!GAC if you're willing to trust that everything is properly resolved, this isn't needed
  510. // Was this URI successfully resolved ? (if element or collection is null, we can't write the URI correctly)
  511. if(thisURI->getState() != daeURI::uri_success || !(thisURI->getElement()) || !(thisURI->getContainer()))
  512. {
  513. // This URI was never successfully resolved, so write out it's original value
  514. s = thisURI->getOriginalURI();
  515. if ( s == NULL ) s = "";
  516. }
  517. else
  518. {
  519. // This URI was successfully resolved, we need to determine if it is referencing this document (the one being written)
  520. // or some other document so we know what URI to write out.
  521. // !!!GAC this approach should be safe, if the collection pointer of our document matches the collection pointer
  522. // !!!GAC of the element our URI is pointing at, we are pointing at our own doc.
  523. if(thisURI->getElement()->getDocument() == thisURI->getContainer()->getDocument())
  524. {
  525. // we will send back the original URI if we're pointing at ourselves
  526. s = thisURI->getOriginalURI();
  527. if ( s == NULL ) s = "";
  528. }
  529. else
  530. {
  531. // !!!GAC change this to test outputting of relative URIs, NOT FULLY TESTED!!!
  532. #if 1
  533. // we will send back the full resolved URI
  534. s = thisURI->getURI();
  535. if ( s == NULL ) s = "";
  536. #else
  537. // Makes the URI relative to the document being written, EXPERIMENTAL, not fully tested!!!
  538. thisURI->makeRelativeTo(thisURI->getDocument()->getCollection()->getDocumentURI());
  539. s = thisURI->getOriginalURI();
  540. if ( s == NULL ) s = "";
  541. #endif
  542. }
  543. }
  544. // Copy at most dstSize-1 characters, null terminate and return error if the string was too long
  545. daeChar *d;
  546. int i;
  547. for(d = dst, i = 1; *s != 0 && i<dstSize; s++, d++, i++)
  548. {
  549. // If the URI contains spaces, substitute %20
  550. if(*s == ' ')
  551. {
  552. if( (i+2)<dstSize)
  553. {
  554. *(d++)='%';
  555. *(d++)='2';
  556. *d = '0';
  557. }
  558. else
  559. {
  560. // not enough space to escape the string so null terminate and return error
  561. *d = 0;
  562. return(false);
  563. }
  564. }
  565. else
  566. {
  567. *d = *s;
  568. }
  569. }
  570. *d = 0;
  571. if( *s == 0)
  572. return(true);
  573. else
  574. return(false);
  575. #else
  576. // !!!GAC This is the old code which doesn't work for cross document references
  577. // ((daeURI*)src)->resolveURI();
  578. // Get the URI String as set, not the composited one from the base
  579. // as per SCEA request
  580. daeString s = ((daeURI *)src)->getOriginalURI();
  581. char tmp[64];
  582. sprintf(tmp,"%%.%ds",dstSize-1);
  583. sprintf(dst,tmp,s);
  584. if ((daeInt)(strlen(s)+1) > dstSize)
  585. return false;
  586. return true;
  587. #endif
  588. }
  589. daeBool
  590. daeIDResolverType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  591. {
  592. ((daeIDRef*)src)->resolveID();
  593. daeString s = ((daeIDRef *)src)->getID();
  594. char tmp[64];
  595. sprintf(tmp,"%%.%ds",dstSize-1);
  596. sprintf(dst,tmp,s);
  597. if ((daeInt)(strlen(s)+1) > dstSize)
  598. return false;
  599. return true;
  600. }
  601. void
  602. daeAtomicType::resolve(daeElementRef element, daeChar* src)
  603. {
  604. // just to remove the warnings
  605. (void)element;
  606. (void)src;
  607. }
  608. void
  609. daeResolverType::resolve(daeElementRef element, daeChar* src)
  610. {
  611. daeURI* resolver = (daeURI*)src;
  612. resolver->setContainer(element);
  613. resolver->resolveElement();
  614. }
  615. daeBool
  616. daeResolverType::stringToMemory(daeChar* src, daeChar* dstMemory)
  617. {
  618. #define MAX_PATH 1024
  619. daeChar tempstr[MAX_PATH];
  620. memset(tempstr,0,MAX_PATH);
  621. daeChar* s;
  622. daeChar* t;
  623. for(s=src, t=tempstr; *s!=0; s++,t++)
  624. {
  625. if (*s == '%') {
  626. if ((*(s+1) == '2') && (*(s+2) == '0'))
  627. {
  628. (*t)=' ';
  629. s+=2;
  630. continue;
  631. }
  632. } else if (*s == ' ') {
  633. char err[512];
  634. memset( err, 0, 512 );
  635. sprintf(err,"uri contains white space, dom will convert them to %%20 in output files!\n uri=%s", src);
  636. daeErrorHandler::get()->handleWarning( err );
  637. }
  638. *t=*s;
  639. }
  640. ((daeURI*)dstMemory)->setURI(tempstr);
  641. return true;
  642. }
  643. void
  644. daeIDResolverType::resolve(daeElementRef element, daeChar* src)
  645. {
  646. daeIDRef* resolver = (daeIDRef*)src;
  647. resolver->setContainer( element );
  648. resolver->resolveElement();
  649. }
  650. daeBool
  651. daeIDResolverType::stringToMemory(daeChar* src, daeChar* dstMemory)
  652. {
  653. ((daeIDRef*)dstMemory)->setID(src);
  654. return true;
  655. }
  656. daeBool
  657. daeStringRefType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
  658. {
  659. *((daeStringRef*)dstMemory) = srcChars;
  660. return true;
  661. }
  662. daeBool
  663. daeEnumType::stringToMemory(daeChar* src, daeChar* dst )
  664. {
  665. size_t index(0);
  666. if ( _strings->find(src,index) == DAE_ERR_QUERY_NO_MATCH ) return false;
  667. daeEnum val = _values->get( index );
  668. *((daeEnum*)dst) = val;
  669. return true;
  670. }
  671. daeBool
  672. daeEnumType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  673. {
  674. daeStringRef s = "unknown";
  675. if (_strings != NULL) {
  676. size_t index;
  677. if (_values->find(*((daeEnum*)src), index) == DAE_OK)
  678. s = _strings->get(index);
  679. }
  680. sprintf(dst,_printFormat,(const char*)s);
  681. (void)dstSize;
  682. return true;
  683. }
  684. daeBool
  685. daeBoolType::stringToMemory(daeChar* srcChars, daeChar* dstMemory)
  686. {
  687. if (strncmp(srcChars,"true",4)==0 || strncmp(srcChars,"1",1)==0)
  688. *((daeBool*)dstMemory) = true;
  689. else
  690. *((daeBool*)dstMemory) = false;
  691. return true;
  692. }
  693. daeBool
  694. daeBoolType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  695. {
  696. if (*((daeBool*)src)) {
  697. if (dstSize < 5)
  698. return false;
  699. else
  700. sprintf(dst,"true");
  701. }
  702. else {
  703. if (dstSize < 6)
  704. return false;
  705. else
  706. sprintf(dst,"false");
  707. }
  708. return true;
  709. }
  710. //!!!ACL added for 1.4 complex types and groups
  711. //unImplemented
  712. daeBool
  713. daeElementRefType::memoryToString(daeChar* src, daeChar* dst, daeInt dstSize)
  714. {
  715. /*if (*((daeBool*)src)) {
  716. if (dstSize < 5)
  717. return false;
  718. else
  719. sprintf(dst,"true");
  720. }
  721. else {
  722. if (dstSize < 6)
  723. return false;
  724. else
  725. sprintf(dst,"false");
  726. }*/
  727. (void)src;
  728. (void)dst;
  729. (void)dstSize;
  730. return false;
  731. }