libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmRpt.h"
  5. #include "cmErr.h"
  6. #include "cmCtx.h"
  7. #include "cmMem.h"
  8. #include "cmMallocDebug.h"
  9. #include "cmLinkedHeap.h"
  10. #include "cmJson.h"
  11. #include "cmDspValue.h"
  12. cmDspValue_t cmDspNullValue = { 0 };
  13. const cmDspValue_t* _vcptr( const cmDspValue_t* vp )
  14. {
  15. while( cmIsFlag(vp->flags, kProxyDsvFl ) )
  16. vp = vp->u.vp;
  17. return vp;
  18. }
  19. cmDspValue_t* _vptr( cmDspValue_t* vp )
  20. {
  21. while( cmIsFlag(vp->flags,kProxyDsvFl) )
  22. vp = vp->u.vp;
  23. return vp;
  24. }
  25. void** _cmDsvGetDataPtrPtr( cmDspValue_t* vp )
  26. {
  27. if( cmDsvIsMtx(vp) )
  28. return &vp->u.m.u.vp;
  29. if( cmIsFlag(vp->flags,kStrzDsvFl) )
  30. return (void**)&vp->u.z;
  31. return NULL;
  32. }
  33. unsigned _cmDsvBasicType( unsigned flags )
  34. { return flags & (kTypeDsvMask & (~kMtxDsvFl) ); }
  35. unsigned _cmDsvEleByteCount( unsigned flags )
  36. {
  37. switch( _cmDsvBasicType(flags) )
  38. {
  39. case kBoolDsvFl: return sizeof(bool);
  40. case kCharDsvFl: return sizeof(char);
  41. case kUCharDsvFl: return sizeof(unsigned char);
  42. case kShortDsvFl: return sizeof(short);
  43. case kUShortDsvFl:return sizeof(unsigned short);
  44. case kLongDsvFl: return sizeof(long);
  45. case kULongDsvFl: return sizeof(unsigned long);
  46. case kIntDsvFl: return sizeof(int);
  47. case kUIntDsvFl: return sizeof(unsigned int);
  48. case kFloatDsvFl: return sizeof(float);
  49. case kDoubleDsvFl:return sizeof(double);
  50. case kSampleDsvFl:return sizeof(cmSample_t);
  51. case kRealDsvFl: return sizeof(cmReal_t);
  52. case kStrzDsvFl: return sizeof(cmChar_t*);
  53. case kJsonDsvFl: return sizeof(cmJsonNode_t*);
  54. default:
  55. { assert(0); }
  56. }
  57. return 0;
  58. }
  59. bool cmDsvIsNull( const cmDspValue_t* vp ){ vp=_vcptr(vp); return vp->flags == kNullDsvFl; }
  60. bool cmDsvIsBool( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kBoolDsvFl); }
  61. bool cmDsvIsChar( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kCharDsvFl); }
  62. bool cmDsvIsUChar( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUCharDsvFl); }
  63. bool cmDsvIsShort( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kShortDsvFl); }
  64. bool cmDsvIsUShort( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUShortDsvFl); }
  65. bool cmDsvIsLong( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kLongDsvFl); }
  66. bool cmDsvIsULong( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kULongDsvFl); }
  67. bool cmDsvIsInt( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kIntDsvFl); }
  68. bool cmDsvIsUInt( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUIntDsvFl); }
  69. bool cmDsvIsFloat( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kFloatDsvFl); }
  70. bool cmDsvIsDouble( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kDoubleDsvFl); }
  71. bool cmDsvIsSample( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kSampleDsvFl); }
  72. bool cmDsvIsReal( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kRealDsvFl); }
  73. bool cmDsvIsPtr( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kPtrDsvFl); }
  74. bool cmDsvIsStrz( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kStrzDsvFl); }
  75. bool cmDsvIsStrcz( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kStrzDsvFl | kConstDsvFl); }
  76. bool cmDsvIsSymbol( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kSymDsvFl); }
  77. bool cmDsvIsJson( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kJsonDsvFl); }
  78. bool cmDsvIsBoolMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kBoolDsvFl | kMtxDsvFl); }
  79. bool cmDsvIsCharMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kCharDsvFl | kMtxDsvFl); }
  80. bool cmDsvIsUCharMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUCharDsvFl | kMtxDsvFl); }
  81. bool cmDsvIsShortMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kShortDsvFl | kMtxDsvFl); }
  82. bool cmDsvIsUShortMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUShortDsvFl | kMtxDsvFl); }
  83. bool cmDsvIsLongMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kLongDsvFl | kMtxDsvFl); }
  84. bool cmDsvIsULongMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kULongDsvFl | kMtxDsvFl); }
  85. bool cmDsvIsIntMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kIntDsvFl | kMtxDsvFl); }
  86. bool cmDsvIsUIntMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kUIntDsvFl | kMtxDsvFl); }
  87. bool cmDsvIsFloatMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kFloatDsvFl | kMtxDsvFl); }
  88. bool cmDsvIsDoubleMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kDoubleDsvFl | kMtxDsvFl); }
  89. bool cmDsvIsSampleMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kSampleDsvFl | kMtxDsvFl); }
  90. bool cmDsvIsRealMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kRealDsvFl | kMtxDsvFl); }
  91. bool cmDsvIsJsonMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kJsonDsvFl | kMtxDsvFl); }
  92. bool cmDsvIsStrzMtx( const cmDspValue_t* vp ){ vp=_vcptr(vp); return cmAllFlags(vp->flags,kStrzDsvFl | kMtxDsvFl); }
  93. bool cmDsvSetFromValist( cmDspValue_t* vp, unsigned flags, va_list vl )
  94. {
  95. vp = _vptr(vp);
  96. switch(flags)
  97. {
  98. case kBoolDsvFl: cmDsvSetBool( vp, va_arg(vl,int )); break;
  99. case kCharDsvFl: cmDsvSetChar( vp, va_arg(vl,int )); break;
  100. case kUCharDsvFl: cmDsvSetUChar( vp, va_arg(vl,int )); break;
  101. case kShortDsvFl: cmDsvSetShort( vp, va_arg(vl,int )); break;
  102. case kUShortDsvFl: cmDsvSetUShort( vp, va_arg(vl,int )); break;
  103. case kLongDsvFl: cmDsvSetLong( vp, va_arg(vl,long )); break;
  104. case kULongDsvFl: cmDsvSetULong( vp, va_arg(vl,unsigned long )); break;
  105. case kIntDsvFl: cmDsvSetInt( vp, va_arg(vl,int )); break;
  106. case kUIntDsvFl: cmDsvSetUInt( vp, va_arg(vl,unsigned )); break;
  107. case kFloatDsvFl: cmDsvSetFloat( vp, va_arg(vl,double )); break;
  108. case kDoubleDsvFl: cmDsvSetDouble( vp, va_arg(vl,double )); break;
  109. case kSampleDsvFl: cmDsvSetSample( vp, va_arg(vl,double )); break;
  110. case kRealDsvFl: cmDsvSetReal( vp, va_arg(vl,double )); break;
  111. case kPtrDsvFl: cmDsvSetPtr( vp, va_arg(vl,void* )); break;
  112. case kStrzDsvFl: cmDsvSetStrz( vp, va_arg(vl,cmChar_t* )); break;
  113. default:
  114. return false;
  115. }
  116. return true;
  117. }
  118. void cmDsvSetNull( cmDspValue_t* vp ) { vp->flags = kNullDsvFl; }
  119. void cmDsvSetBool( cmDspValue_t* vp, bool v ) { vp->flags = kBoolDsvFl; vp->u.b = v; }
  120. void cmDsvSetChar( cmDspValue_t* vp, char v ) { vp->flags = kCharDsvFl; vp->u.c = v; }
  121. void cmDsvSetUChar( cmDspValue_t* vp, unsigned char v ) { vp->flags = kUCharDsvFl; vp->u.uc = v; }
  122. void cmDsvSetShort( cmDspValue_t* vp, short v ) { vp->flags = kShortDsvFl; vp->u.s = v; }
  123. void cmDsvSetUShort( cmDspValue_t* vp, unsigned short v ) { vp->flags = kUShortDsvFl; vp->u.us = v; }
  124. void cmDsvSetLong( cmDspValue_t* vp, long v ) { vp->flags = kLongDsvFl; vp->u.l = v; }
  125. void cmDsvSetULong( cmDspValue_t* vp, unsigned long v ) { vp->flags = kULongDsvFl; vp->u.ul = v; }
  126. void cmDsvSetInt( cmDspValue_t* vp, int v ) { vp->flags = kIntDsvFl; vp->u.i = v; }
  127. void cmDsvSetUInt( cmDspValue_t* vp, unsigned int v ) { vp->flags = kUIntDsvFl; vp->u.u = v; }
  128. void cmDsvSetFloat( cmDspValue_t* vp, float v ) { vp->flags = kFloatDsvFl; vp->u.f = v; }
  129. void cmDsvSetDouble( cmDspValue_t* vp, double v ) { vp->flags = kDoubleDsvFl; vp->u.d = v; }
  130. void cmDsvSetSample( cmDspValue_t* vp, cmSample_t v ) { vp->flags = kSampleDsvFl; vp->u.a = v; }
  131. void cmDsvSetReal( cmDspValue_t* vp, cmReal_t v ) { vp->flags = kRealDsvFl; vp->u.r = v; }
  132. void cmDsvSetPtr( cmDspValue_t* vp, void* v ) { vp->flags = kPtrDsvFl; vp->u.vp = v; }
  133. void cmDsvSetSymbol( cmDspValue_t* vp, unsigned v ) { vp->flags = kSymDsvFl; vp->u.u = v; }
  134. void cmDsvSetStrz( cmDspValue_t* vp, cmChar_t* v ) { vp->flags = kStrzDsvFl; vp->u.z = v; }
  135. void cmDsvSetStrcz( cmDspValue_t* vp, const cmChar_t* v ){ vp->flags = kStrzDsvFl | kConstDsvFl; vp->u.cz = v; }
  136. void cmDsvSetJson( cmDspValue_t* vp, cmJsonNode_t* v) { vp->flags = kJsonDsvFl; vp->u.j = v; }
  137. void cmDsvSetBoolMtx( cmDspValue_t* vp, bool* v, unsigned rn, unsigned cn ) { vp->flags = kBoolDsvFl | kMtxDsvFl; vp->u.m.u.bp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  138. void cmDsvSetCharMtx( cmDspValue_t* vp, char* v, unsigned rn, unsigned cn ) { vp->flags = kCharDsvFl | kMtxDsvFl; vp->u.m.u.cp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  139. void cmDsvSetUCharMtx( cmDspValue_t* vp, unsigned char* v, unsigned rn, unsigned cn ) { vp->flags = kUCharDsvFl | kMtxDsvFl; vp->u.m.u.ucp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  140. void cmDsvSetShortMtx( cmDspValue_t* vp, short* v, unsigned rn, unsigned cn ) { vp->flags = kShortDsvFl | kMtxDsvFl; vp->u.m.u.sp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  141. void cmDsvSetUShortMtx( cmDspValue_t* vp, unsigned short* v, unsigned rn, unsigned cn ) { vp->flags = kUShortDsvFl | kMtxDsvFl; vp->u.m.u.usp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  142. void cmDsvSetLongMtx( cmDspValue_t* vp, long* v, unsigned rn, unsigned cn ) { vp->flags = kLongDsvFl | kMtxDsvFl; vp->u.m.u.lp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  143. void cmDsvSetULongMtx( cmDspValue_t* vp, unsigned long* v, unsigned rn, unsigned cn ) { vp->flags = kULongDsvFl | kMtxDsvFl; vp->u.m.u.ulp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  144. void cmDsvSetIntMtx( cmDspValue_t* vp, int* v, unsigned rn, unsigned cn ) { vp->flags = kIntDsvFl | kMtxDsvFl; vp->u.m.u.ip=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  145. void cmDsvSetUIntMtx( cmDspValue_t* vp, unsigned int* v, unsigned rn, unsigned cn ) { vp->flags = kUIntDsvFl | kMtxDsvFl; vp->u.m.u.up=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  146. void cmDsvSetFloatMtx( cmDspValue_t* vp, float* v, unsigned rn, unsigned cn ) { vp->flags = kFloatDsvFl | kMtxDsvFl; vp->u.m.u.fp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  147. void cmDsvSetDoubleMtx( cmDspValue_t* vp, double* v, unsigned rn, unsigned cn ) { vp->flags = kDoubleDsvFl | kMtxDsvFl; vp->u.m.u.dp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  148. void cmDsvSetSampleMtx( cmDspValue_t* vp, cmSample_t* v, unsigned rn, unsigned cn ) { vp->flags = kSampleDsvFl | kMtxDsvFl; vp->u.m.u.ap=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  149. void cmDsvSetRealMtx( cmDspValue_t* vp, cmReal_t* v, unsigned rn, unsigned cn ) { vp->flags = kRealDsvFl | kMtxDsvFl; vp->u.m.u.rp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  150. void cmDsvSetJsonMtx( cmDspValue_t* vp, cmJsonNode_t** v, unsigned rn, unsigned cn ) { vp->flags = kJsonDsvFl | kMtxDsvFl; vp->u.m.u.jp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  151. void cmDsvSetStrzMtx( cmDspValue_t* vp, cmChar_t** v, unsigned rn, unsigned cn ) { vp->flags = kStrzDsvFl | kMtxDsvFl; vp->u.m.u.zp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  152. void cmDsvSetStrczMtx( cmDspValue_t* vp, const cmChar_t** v,unsigned rn, unsigned cn ) { vp->flags = kStrzDsvFl | kMtxDsvFl | kConstDsvFl; vp->u.m.u.czp=v; vp->u.m.rn=rn; vp->u.m.cn=cn; }
  153. void cmDsvSetMtx( cmDspValue_t* vp, unsigned flags, void* v, unsigned rn, unsigned cn )
  154. {
  155. vp->flags=flags;
  156. vp->u.m.u.vp=v;
  157. vp->u.m.rn=rn;
  158. vp->u.m.cn=cn;
  159. }
  160. void cmDsvSetProxy( cmDspValue_t* vp, cmDspValue_t* pp )
  161. { vp->flags = kProxyDsvFl; vp->u.vp = pp; }
  162. bool cmDsvCanConvertFlags( unsigned destFlags, unsigned srcFlags )
  163. {
  164. unsigned sFl = cmClrFlag(srcFlags & kTypeDsvMask, kProxyDsvFl);
  165. unsigned dFl = cmClrFlag(destFlags & kTypeDsvMask, kProxyDsvFl );
  166. // if the flags are equal then no conversion is necessary
  167. if( sFl == dFl )
  168. return true;
  169. // if either the src or dst has no assigned type then conversion is always possible
  170. if( sFl == 0 || dFl == 0 )
  171. return true;
  172. // conversion is not possible between a mtx and a scalar or v.v.
  173. if( cmIsFlag(sFl,kMtxDsvFl) != cmIsFlag(dFl,kMtxDsvFl) )
  174. return false;
  175. // conversion between JSON nodes and anything else is not possible
  176. if( cmIsFlag(sFl,kJsonDsvFl) != cmIsFlag(dFl,kJsonDsvFl) )
  177. return false;
  178. // conversion between string and anything else is not possible.
  179. if( cmIsFlag(sFl,kStrzDsvFl) != cmIsFlag(dFl,kStrzDsvFl) )
  180. return false;
  181. // conversion betweens symbols and anything else is not possible
  182. if( cmIsFlag(sFl,kSymDsvFl) != cmIsFlag(dFl,kSymDsvFl) )
  183. return false;
  184. return true;
  185. }
  186. bool cmDsvCanConvert( const cmDspValue_t* dvp, const cmDspValue_t* svp )
  187. {
  188. dvp = _vcptr(dvp);
  189. svp = _vcptr(svp);
  190. return cmDsvCanConvertFlags( _vcptr(dvp)->flags, _vcptr(svp)->flags );
  191. }
  192. bool cmDsvBool( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kBoolDsvFl)) return vp->u.b; assert(0); return 0; }
  193. char cmDsvChar( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kCharDsvFl)) return vp->u.c; assert(0); return 0; }
  194. unsigned char cmDsvUChar( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kUCharDsvFl)) return vp->u.uc; assert(0); return 0; }
  195. short cmDsvShort( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kShortDsvFl)) return vp->u.s; assert(0); return 0; }
  196. unsigned short cmDsvUShort( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kUShortDsvFl)) return vp->u.us; assert(0); return 0; }
  197. long cmDsvLong( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kLongDsvFl)) return vp->u.l; assert(0); return 0; }
  198. unsigned long cmDsvULong( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kULongDsvFl)) return vp->u.ul; assert(0); return 0; }
  199. int cmDsvInt( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kIntDsvFl)) return vp->u.i; assert(0); return 0; }
  200. unsigned int cmDsvUInt( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kUIntDsvFl)) return vp->u.u; assert(0); return 0; }
  201. float cmDsvFloat( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kFloatDsvFl)) return vp->u.f; assert(0); return 0; }
  202. double cmDsvDouble( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kDoubleDsvFl)) return vp->u.d; assert(0); return 0; }
  203. cmSample_t cmDsvSample( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kSampleDsvFl)) return vp->u.a; assert(0); return 0; }
  204. cmReal_t cmDsvReal( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kRealDsvFl)) return vp->u.r; assert(0); return 0; }
  205. void* cmDsvPtr( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kPtrDsvFl)) return vp->u.vp; assert(0); return 0; }
  206. unsigned int cmDsvSymbol( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kSymDsvFl)) return vp->u.u; assert(0); return cmInvalidId; }
  207. cmJsonNode_t* cmDsvJson( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmIsFlag((vp->flags & kTypeDsvMask),kJsonDsvFl)) return vp->u.j; assert(0); return NULL; }
  208. const cmDspValue_t* cmDsvValueCPtr( const cmDspValue_t* vp )
  209. { return _vcptr(vp); }
  210. cmDspValue_t* cmDsvValuePtr( cmDspValue_t* vp )
  211. { return _vptr(vp); }
  212. cmChar_t* cmDsvStrz( const cmDspValue_t* vp )
  213. {
  214. vp=_vcptr(vp);
  215. if(cmIsFlag((vp->flags & kTypeDsvMask),kStrzDsvFl) && cmIsFlag(vp->flags,kConstDsvFl)==false )
  216. return vp->u.z;
  217. assert(0);
  218. return NULL;
  219. }
  220. const cmChar_t*cmDsvStrcz( const cmDspValue_t* vp )
  221. {
  222. vp = _vcptr(vp);
  223. if(cmIsFlag((vp->flags & kTypeDsvMask),kStrzDsvFl))
  224. return vp->u.z;
  225. assert(0);
  226. return NULL;
  227. }
  228. const bool* cmDsvBoolCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kBoolDsvFl)) return vp->u.m.u.bp; assert(0); return NULL; }
  229. const char* cmDsvCharCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kCharDsvFl)) return vp->u.m.u.cp; assert(0); return NULL; }
  230. const unsigned char* cmDsvUCharCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUCharDsvFl)) return vp->u.m.u.ucp; assert(0); return NULL; }
  231. const short* cmDsvShortCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kShortDsvFl)) return vp->u.m.u.sp; assert(0); return NULL; }
  232. const unsigned short* cmDsvUShortCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUShortDsvFl)) return vp->u.m.u.usp; assert(0); return NULL; }
  233. const long* cmDsvLongCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kLongDsvFl)) return vp->u.m.u.lp; assert(0); return NULL; }
  234. const unsigned long* cmDsvULongCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kULongDsvFl)) return vp->u.m.u.ulp; assert(0); return NULL; }
  235. const int* cmDsvIntCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kIntDsvFl)) return vp->u.m.u.ip; assert(0); return NULL; }
  236. const unsigned int* cmDsvUIntCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUIntDsvFl)) return vp->u.m.u.up; assert(0); return NULL; }
  237. const float* cmDsvFloatCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kFloatDsvFl)) return vp->u.m.u.fp; assert(0); return NULL; }
  238. const double* cmDsvDoubleCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kDoubleDsvFl)) return vp->u.m.u.dp; assert(0); return NULL; }
  239. const cmSample_t* cmDsvSampleCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kSampleDsvFl)) return vp->u.m.u.ap; assert(0); return NULL; }
  240. const cmReal_t* cmDsvRealCMtx( const cmDspValue_t* vp ) { vp=_vcptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kRealDsvFl)) return vp->u.m.u.rp; assert(0); return NULL; }
  241. const cmChar_t** cmDsvStrzCMtx( const cmDspValue_t* vp )
  242. {
  243. vp = _vcptr(vp);
  244. if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kStrzDsvFl) )
  245. return vp->u.m.u.czp;
  246. assert(0);
  247. return NULL;
  248. }
  249. const cmChar_t** cmDsvStrczCMtx( const cmDspValue_t* vp )
  250. {
  251. vp = _vcptr(vp);
  252. if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kStrzDsvFl))
  253. return vp->u.m.u.czp;
  254. assert(0);
  255. return NULL;
  256. }
  257. bool* cmDsvBoolMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kBoolDsvFl)) return vp->u.m.u.bp; assert(0); return NULL; }
  258. char* cmDsvCharMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kCharDsvFl)) return vp->u.m.u.cp; assert(0); return NULL; }
  259. unsigned char* cmDsvUCharMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUCharDsvFl)) return vp->u.m.u.ucp; assert(0); return NULL; }
  260. short* cmDsvShortMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kShortDsvFl)) return vp->u.m.u.sp; assert(0); return NULL; }
  261. unsigned short* cmDsvUShortMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUShortDsvFl)) return vp->u.m.u.usp; assert(0); return NULL; }
  262. long* cmDsvLongMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kLongDsvFl)) return vp->u.m.u.lp; assert(0); return NULL; }
  263. unsigned long* cmDsvULongMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kULongDsvFl)) return vp->u.m.u.ulp; assert(0); return NULL; }
  264. int* cmDsvIntMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kIntDsvFl)) return vp->u.m.u.ip; assert(0); return NULL; }
  265. unsigned int* cmDsvUIntMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kUIntDsvFl)) return vp->u.m.u.up; assert(0); return NULL; }
  266. float* cmDsvFloatMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kFloatDsvFl)) return vp->u.m.u.fp; assert(0); return NULL; }
  267. double* cmDsvDoubleMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kDoubleDsvFl)) return vp->u.m.u.dp; assert(0); return NULL; }
  268. cmSample_t* cmDsvSampleMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kSampleDsvFl)) return vp->u.m.u.ap; assert(0); return NULL; }
  269. cmReal_t* cmDsvRealMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kRealDsvFl)) return vp->u.m.u.rp; assert(0); return NULL; }
  270. cmJsonNode_t** cmDsvJsonMtx( cmDspValue_t* vp ) { vp=_vptr(vp); if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kJsonDsvFl)) return vp->u.m.u.jp; assert(0); return NULL; }
  271. cmChar_t** cmDsvStrzMtx( cmDspValue_t* vp )
  272. {
  273. vp = _vptr(vp);
  274. if(cmAllFlags((vp->flags & kTypeDsvMask), kMtxDsvFl | kStrzDsvFl) && cmIsFlag(vp->flags,kConstDsvFl))
  275. return vp->u.m.u.zp;
  276. assert(0);
  277. return NULL;
  278. }
  279. const cmChar_t** cmDsvStrczMtx( cmDspValue_t* vp )
  280. { return cmDsvStrczCMtx(vp); }
  281. // Get the value of a cmDspValue_t as a <type>.
  282. // Conversion is performed if the return type does not exactly match the cmDspValue_t type.
  283. bool cmDsvGetBool( const cmDspValue_t* vp )
  284. {
  285. vp = _vcptr(vp);
  286. switch((vp->flags & kTypeDsvMask))
  287. {
  288. case kNullDsvFl: break;
  289. case kBoolDsvFl: return vp->u.b;
  290. case kCharDsvFl: return (bool)vp->u.c;
  291. case kUCharDsvFl: return (bool)vp->u.uc;
  292. case kShortDsvFl: return (bool)vp->u.s;
  293. case kUShortDsvFl: return (bool)vp->u.us;
  294. case kLongDsvFl: return (bool)vp->u.l;
  295. case kULongDsvFl: return (bool)vp->u.ul;
  296. case kIntDsvFl: return (bool)vp->u.i;
  297. case kUIntDsvFl: return (bool)vp->u.u;
  298. case kFloatDsvFl: return (bool)vp->u.f;
  299. case kDoubleDsvFl: return (bool)vp->u.d;
  300. case kSampleDsvFl: return (bool)vp->u.a;
  301. case kRealDsvFl: return (bool)vp->u.r;
  302. default:
  303. assert(0);
  304. }
  305. return 0;
  306. }
  307. char cmDsvGetChar( const cmDspValue_t* vp )
  308. {
  309. vp = _vcptr(vp);
  310. switch((vp->flags & kTypeDsvMask))
  311. {
  312. case kNullDsvFl: break;
  313. case kBoolDsvFl: return (char)vp->u.b;
  314. case kCharDsvFl: return vp->u.c;
  315. case kUCharDsvFl: return (char)vp->u.uc;
  316. case kShortDsvFl: return (char)vp->u.s;
  317. case kUShortDsvFl: return (char)vp->u.us;
  318. case kLongDsvFl: return (char)vp->u.l;
  319. case kULongDsvFl: return (char)vp->u.ul;
  320. case kIntDsvFl: return (char)vp->u.i;
  321. case kUIntDsvFl: return (char)vp->u.u;
  322. case kFloatDsvFl: return (char)vp->u.f;
  323. case kDoubleDsvFl: return (char)vp->u.d;
  324. case kSampleDsvFl: return (char)vp->u.a;
  325. case kRealDsvFl: return (char)vp->u.r;
  326. default:
  327. assert(0);
  328. }
  329. return 0;
  330. }
  331. unsigned char cmDsvGetUChar( const cmDspValue_t* vp )
  332. {
  333. vp = _vcptr(vp);
  334. switch((vp->flags & kTypeDsvMask))
  335. {
  336. case kNullDsvFl: break;
  337. case kBoolDsvFl: return (char)vp->u.b;
  338. case kCharDsvFl: return (unsigned char)vp->u.c;
  339. case kUCharDsvFl: return vp->u.uc;
  340. case kShortDsvFl: return (unsigned char)vp->u.s;
  341. case kUShortDsvFl: return (unsigned char)vp->u.us;
  342. case kLongDsvFl: return (unsigned char)vp->u.l;
  343. case kULongDsvFl: return (unsigned char)vp->u.ul;
  344. case kIntDsvFl: return (unsigned char)vp->u.i;
  345. case kUIntDsvFl: return (unsigned char)vp->u.u;
  346. case kFloatDsvFl: return (unsigned char)vp->u.f;
  347. case kDoubleDsvFl: return (unsigned char)vp->u.d;
  348. case kSampleDsvFl: return (unsigned char)vp->u.a;
  349. case kRealDsvFl: return (unsigned char)vp->u.r;
  350. default:
  351. assert(0);
  352. }
  353. return 0;
  354. }
  355. short cmDsvGetShort( const cmDspValue_t* vp )
  356. {
  357. vp = _vcptr(vp);
  358. switch((vp->flags & kTypeDsvMask))
  359. {
  360. case kNullDsvFl: break;
  361. case kBoolDsvFl: return (char)vp->u.b;
  362. case kCharDsvFl: return (short)vp->u.c;
  363. case kUCharDsvFl: return (short)vp->u.uc;
  364. case kShortDsvFl: return vp->u.s;
  365. case kUShortDsvFl: return (short)vp->u.us;
  366. case kLongDsvFl: return (short)vp->u.l;
  367. case kULongDsvFl: return (short)vp->u.ul;
  368. case kIntDsvFl: return (short)vp->u.i;
  369. case kUIntDsvFl: return (short)vp->u.u;
  370. case kFloatDsvFl: return (short)vp->u.f;
  371. case kDoubleDsvFl: return (short)vp->u.d;
  372. case kSampleDsvFl: return (short)vp->u.a;
  373. case kRealDsvFl: return (short)vp->u.r;
  374. default:
  375. assert(0);
  376. }
  377. return 0;
  378. }
  379. unsigned short cmDsvGetUShort( const cmDspValue_t* vp )
  380. {
  381. vp = _vcptr(vp);
  382. switch((vp->flags & kTypeDsvMask))
  383. {
  384. case kNullDsvFl: break;
  385. case kBoolDsvFl: return (char)vp->u.b;
  386. case kCharDsvFl: return (unsigned short)vp->u.c;
  387. case kUCharDsvFl: return (unsigned short)vp->u.uc;
  388. case kShortDsvFl: return (unsigned short)vp->u.s;
  389. case kUShortDsvFl: return vp->u.us;
  390. case kLongDsvFl: return (unsigned short)vp->u.l;
  391. case kULongDsvFl: return (unsigned short)vp->u.ul;
  392. case kIntDsvFl: return (unsigned short)vp->u.i;
  393. case kUIntDsvFl: return (unsigned short)vp->u.u;
  394. case kFloatDsvFl: return (unsigned short)vp->u.f;
  395. case kDoubleDsvFl: return (unsigned short)vp->u.d;
  396. case kSampleDsvFl: return (unsigned short)vp->u.a;
  397. case kRealDsvFl: return (unsigned short)vp->u.r;
  398. default:
  399. assert(0);
  400. }
  401. return 0;
  402. }
  403. long cmDsvGetLong( const cmDspValue_t* vp )
  404. {
  405. vp = _vcptr(vp);
  406. switch((vp->flags & kTypeDsvMask))
  407. {
  408. case kNullDsvFl: break;
  409. case kBoolDsvFl: return (char)vp->u.b;
  410. case kCharDsvFl: return (long)vp->u.c;
  411. case kUCharDsvFl: return (long)vp->u.uc;
  412. case kShortDsvFl: return (long)vp->u.s;
  413. case kUShortDsvFl: return (long)vp->u.us;
  414. case kLongDsvFl: return vp->u.l;
  415. case kULongDsvFl: return (long)vp->u.ul;
  416. case kIntDsvFl: return (long)vp->u.i;
  417. case kUIntDsvFl: return (long)vp->u.u;
  418. case kFloatDsvFl: return (long)vp->u.f;
  419. case kDoubleDsvFl: return (long)vp->u.d;
  420. case kSampleDsvFl: return (long)vp->u.a;
  421. case kRealDsvFl: return (long)vp->u.r;
  422. default:
  423. assert(0);
  424. }
  425. return 0;
  426. }
  427. unsigned long cmDsvGetULong( const cmDspValue_t* vp )
  428. {
  429. vp = _vcptr(vp);
  430. switch((vp->flags & kTypeDsvMask))
  431. {
  432. case kNullDsvFl: break;
  433. case kBoolDsvFl: return (char)vp->u.b;
  434. case kCharDsvFl: return (unsigned long)vp->u.c;
  435. case kUCharDsvFl: return (unsigned long)vp->u.uc;
  436. case kShortDsvFl: return (unsigned long)vp->u.s;
  437. case kUShortDsvFl: return (unsigned long)vp->u.us;
  438. case kLongDsvFl: return (unsigned long)vp->u.l;
  439. case kULongDsvFl: return vp->u.ul;
  440. case kIntDsvFl: return (unsigned long)vp->u.i;
  441. case kUIntDsvFl: return (unsigned long)vp->u.u;
  442. case kFloatDsvFl: return (unsigned long)vp->u.f;
  443. case kDoubleDsvFl: return (unsigned long)vp->u.d;
  444. case kSampleDsvFl: return (unsigned long)vp->u.a;
  445. case kRealDsvFl: return (unsigned long)vp->u.r;
  446. default:
  447. assert(0);
  448. }
  449. return 0;
  450. }
  451. int cmDsvGetInt( const cmDspValue_t* vp )
  452. {
  453. vp = _vcptr(vp);
  454. switch((vp->flags & kTypeDsvMask))
  455. {
  456. case kNullDsvFl: break;
  457. case kBoolDsvFl: return (char)vp->u.b;
  458. case kCharDsvFl: return (int)vp->u.c;
  459. case kUCharDsvFl: return (int)vp->u.uc;
  460. case kShortDsvFl: return (int)vp->u.s;
  461. case kUShortDsvFl: return (int)vp->u.us;
  462. case kLongDsvFl: return (int)vp->u.l;
  463. case kULongDsvFl: return (int)vp->u.ul;
  464. case kIntDsvFl: return vp->u.i;
  465. case kUIntDsvFl: return (int)vp->u.u;
  466. case kFloatDsvFl: return (int)vp->u.f;
  467. case kDoubleDsvFl: return (int)vp->u.d;
  468. case kSampleDsvFl: return (int)vp->u.a;
  469. case kRealDsvFl: return (int)vp->u.r;
  470. default:
  471. assert(0);
  472. }
  473. return 0;
  474. }
  475. unsigned int cmDsvGetUInt( const cmDspValue_t* vp )
  476. {
  477. vp = _vcptr(vp);
  478. switch((vp->flags & kTypeDsvMask))
  479. {
  480. case kNullDsvFl: break;
  481. case kBoolDsvFl: return (char)vp->u.b;
  482. case kCharDsvFl: return (unsigned int)vp->u.c;
  483. case kUCharDsvFl: return (unsigned int)vp->u.uc;
  484. case kShortDsvFl: return (unsigned int)vp->u.s;
  485. case kUShortDsvFl: return (unsigned int)vp->u.us;
  486. case kLongDsvFl: return (unsigned int)vp->u.l;
  487. case kULongDsvFl: return (unsigned int)vp->u.ul;
  488. case kIntDsvFl: return (unsigned int)vp->u.i;
  489. case kUIntDsvFl: return vp->u.u;
  490. case kFloatDsvFl: return (unsigned int)vp->u.f;
  491. case kDoubleDsvFl: return (unsigned int)vp->u.d;
  492. case kSampleDsvFl: return (unsigned int)vp->u.a;
  493. case kRealDsvFl: return (unsigned int)vp->u.r;
  494. default:
  495. assert(0);
  496. }
  497. return 0;
  498. }
  499. float cmDsvGetFloat( const cmDspValue_t* vp )
  500. {
  501. vp = _vcptr(vp);
  502. switch((vp->flags & kTypeDsvMask))
  503. {
  504. case kNullDsvFl: break;
  505. case kBoolDsvFl: return (char)vp->u.b;
  506. case kCharDsvFl: return (float)vp->u.c;
  507. case kUCharDsvFl: return (float)vp->u.uc;
  508. case kShortDsvFl: return (float)vp->u.s;
  509. case kUShortDsvFl: return (float)vp->u.us;
  510. case kLongDsvFl: return (float)vp->u.l;
  511. case kULongDsvFl: return (float)vp->u.ul;
  512. case kIntDsvFl: return (float)vp->u.i;
  513. case kUIntDsvFl: return (float)vp->u.u;
  514. case kFloatDsvFl: return vp->u.f;
  515. case kDoubleDsvFl: return (float)vp->u.d;
  516. case kSampleDsvFl: return (float)vp->u.a;
  517. case kRealDsvFl: return (float)vp->u.r;
  518. default:
  519. assert(0);
  520. }
  521. return 0;
  522. }
  523. double cmDsvGetDouble( const cmDspValue_t* vp )
  524. {
  525. vp = _vcptr(vp);
  526. switch((vp->flags & kTypeDsvMask))
  527. {
  528. case kNullDsvFl: break;
  529. case kBoolDsvFl: return (char)vp->u.b;
  530. case kCharDsvFl: return (double)vp->u.c;
  531. case kUCharDsvFl: return (double)vp->u.uc;
  532. case kShortDsvFl: return (double)vp->u.s;
  533. case kUShortDsvFl: return (double)vp->u.us;
  534. case kLongDsvFl: return (double)vp->u.l;
  535. case kULongDsvFl: return (double)vp->u.ul;
  536. case kIntDsvFl: return (double)vp->u.i;
  537. case kUIntDsvFl: return (double)vp->u.u;
  538. case kFloatDsvFl: return (double)vp->u.f;
  539. case kDoubleDsvFl: return vp->u.d;
  540. case kSampleDsvFl: return (double)vp->u.a;
  541. case kRealDsvFl: return (double)vp->u.r;
  542. default:
  543. assert(0);
  544. }
  545. return 0;
  546. }
  547. cmSample_t cmDsvGetSample( const cmDspValue_t* vp )
  548. {
  549. vp = _vcptr(vp);
  550. switch((vp->flags & kTypeDsvMask))
  551. {
  552. case kNullDsvFl: break;
  553. case kBoolDsvFl: return (char)vp->u.b;
  554. case kCharDsvFl: return (cmSample_t)vp->u.c;
  555. case kUCharDsvFl: return (cmSample_t)vp->u.uc;
  556. case kShortDsvFl: return (cmSample_t)vp->u.s;
  557. case kUShortDsvFl: return (cmSample_t)vp->u.us;
  558. case kLongDsvFl: return (cmSample_t)vp->u.l;
  559. case kULongDsvFl: return (cmSample_t)vp->u.ul;
  560. case kIntDsvFl: return (cmSample_t)vp->u.i;
  561. case kUIntDsvFl: return (cmSample_t)vp->u.u;
  562. case kFloatDsvFl: return (cmSample_t)vp->u.f;
  563. case kDoubleDsvFl: return (cmSample_t)vp->u.d;
  564. case kSampleDsvFl: return vp->u.a;
  565. case kRealDsvFl: return (cmSample_t)vp->u.r;
  566. default:
  567. assert(0);
  568. }
  569. return 0;
  570. }
  571. cmReal_t cmDsvGetReal( const cmDspValue_t* vp )
  572. {
  573. vp = _vcptr(vp);
  574. switch((vp->flags & kTypeDsvMask))
  575. {
  576. case kNullDsvFl: break;
  577. case kBoolDsvFl: return (char)vp->u.b;
  578. case kCharDsvFl: return (cmReal_t)vp->u.c;
  579. case kUCharDsvFl: return (cmReal_t)vp->u.uc;
  580. case kShortDsvFl: return (cmReal_t)vp->u.s;
  581. case kUShortDsvFl: return (cmReal_t)vp->u.us;
  582. case kLongDsvFl: return (cmReal_t)vp->u.l;
  583. case kULongDsvFl: return (cmReal_t)vp->u.ul;
  584. case kIntDsvFl: return (cmReal_t)vp->u.i;
  585. case kUIntDsvFl: return (cmReal_t)vp->u.u;
  586. case kFloatDsvFl: return (cmReal_t)vp->u.f;
  587. case kDoubleDsvFl: return (cmReal_t)vp->u.d;
  588. case kSampleDsvFl: return (cmReal_t)vp->u.a;
  589. case kRealDsvFl: return vp->u.r;
  590. default:
  591. assert(0);
  592. }
  593. return 0;
  594. }
  595. void* cmDsvGetPtr( const cmDspValue_t* vp )
  596. {
  597. vp = _vcptr(vp);
  598. if( (vp->flags & kTypeDsvMask) == kPtrDsvFl )
  599. return vp->u.vp;
  600. return NULL;
  601. }
  602. unsigned int cmDsvGetSymbol( const cmDspValue_t* vp )
  603. {
  604. vp = _vcptr(vp);
  605. if( (vp->flags & kTypeDsvMask) == kSymDsvFl )
  606. return vp->u.u;
  607. return cmInvalidId;
  608. }
  609. cmChar_t* cmDsvGetStrz( const cmDspValue_t* vp )
  610. {
  611. vp = _vcptr(vp);
  612. if( (vp->flags & kTypeDsvMask) == kStrzDsvFl && cmIsFlag(vp->flags,kConstDsvFl)==false )
  613. return vp->u.z;
  614. return NULL;
  615. }
  616. const cmChar_t* cmDsvGetStrcz( const cmDspValue_t* vp )
  617. {
  618. vp = _vcptr(vp);
  619. if( (vp->flags & kTypeDsvMask) == kStrzDsvFl )
  620. return vp->u.z;
  621. return NULL;
  622. }
  623. cmJsonNode_t* cmDsvGetJson( const cmDspValue_t* vp )
  624. {
  625. vp = _vcptr(vp);
  626. if( (vp->flags & kTypeDsvMask) == kJsonDsvFl )
  627. return vp->u.j;
  628. return NULL;
  629. }
  630. #define cvt_b( dt,vp,op,sn) do{bool* sp=vp->u.m.u.bp; bool* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  631. #define cvt_c( dt,vp,op,sn) do{char* sp=vp->u.m.u.cp; char* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  632. #define cvt_uc( dt,vp,op,sn) do{unsigned char* sp=vp->u.m.u.ucp; unsigned char* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  633. #define cvt_s( dt,vp,op,sn) do{short* sp=vp->u.m.u.sp; short* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  634. #define cvt_us( dt,vp,op,sn) do{unsigned short* sp=vp->u.m.u.usp; unsigned short* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  635. #define cvt_l( dt,vp,op,sn) do{long* sp=vp->u.m.u.lp; long* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  636. #define cvt_ul( dt,vp,op,sn) do{unsigned long* sp=vp->u.m.u.ulp; unsigned long* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  637. #define cvt_i( dt,vp,op,sn) do{int* sp=vp->u.m.u.ip; int* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  638. #define cvt_u( dt,vp,op,sn) do{unsigned int* sp=vp->u.m.u.up; unsigned int* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  639. #define cvt_f( dt,vp,op,sn) do{float* sp=vp->u.m.u.fp; float* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  640. #define cvt_d( dt,vp,op,sn) do{double* sp=vp->u.m.u.dp; double* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  641. #define cvt_a( dt,vp,op,sn) do{cmSample_t* sp=vp->u.m.u.ap; cmSample_t* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  642. #define cvt_r( dt,vp,op,sn) do{cmReal_t* sp=vp->u.m.u.rp; cmReal_t* ep=sp+sn; while(sp<ep) *op++=(dt)*sp++; }while(0)
  643. cmDsvRC_t _cmDsvValidateMtx( const cmDspValue_t* vp, unsigned vn, unsigned* snp )
  644. {
  645. if( cmIsFlag(vp->flags,kMtxDsvFl)==false)
  646. {
  647. assert(0);
  648. return kNotMtxDsvRC;
  649. }
  650. *snp = vp->u.m.rn * vp->u.m.cn;
  651. if( *snp > vn )
  652. {
  653. assert(0);
  654. return kRetTooSmallDsvRC;
  655. }
  656. return kOkDsvRC;
  657. }
  658. cmDsvRC_t cmDsvGetBoolMtx( cmDspValue_t* vp, bool* v, unsigned vn )
  659. {
  660. cmDsvRC_t rc;
  661. unsigned sn;
  662. vp = _vptr(vp);
  663. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  664. return rc;
  665. switch(cmDsvBasicType(vp))
  666. {
  667. case kBoolDsvFl: cvt_b( bool,vp,v,sn); break;
  668. case kCharDsvFl: cvt_c( bool,vp,v,sn); break;
  669. case kUCharDsvFl: cvt_uc( bool,vp,v,sn); break;
  670. case kShortDsvFl: cvt_s( bool,vp,v,sn); break;
  671. case kUShortDsvFl: cvt_us( bool,vp,v,sn); break;
  672. case kLongDsvFl: cvt_l( bool,vp,v,sn); break;
  673. case kULongDsvFl: cvt_ul( bool,vp,v,sn); break;
  674. case kIntDsvFl: cvt_i( bool,vp,v,sn); break;
  675. case kUIntDsvFl: cvt_u( bool,vp,v,sn); break;
  676. case kFloatDsvFl: cvt_f( bool,vp,v,sn); break;
  677. case kDoubleDsvFl: cvt_d( bool,vp,v,sn); break;
  678. case kSampleDsvFl: cvt_s( bool,vp,v,sn); break;
  679. case kRealDsvFl: cvt_r( bool,vp,v,sn); break;
  680. default:
  681. assert(0);
  682. return kUnknownTypeDsvRC;
  683. }
  684. return kOkDsvRC;
  685. }
  686. cmDsvRC_t cmDsvGetCharMtx( cmDspValue_t* vp, char* v, unsigned vn )
  687. {
  688. vp = _vptr(vp);
  689. cmDsvRC_t rc;
  690. unsigned sn;
  691. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  692. return rc;
  693. switch(cmDsvBasicType(vp))
  694. {
  695. case kBoolDsvFl: cvt_b( char,vp,v,sn); break;
  696. case kCharDsvFl: cvt_c( char,vp,v,sn); break;
  697. case kUCharDsvFl: cvt_uc( char,vp,v,sn); break;
  698. case kShortDsvFl: cvt_s( char,vp,v,sn); break;
  699. case kUShortDsvFl: cvt_us( char,vp,v,sn); break;
  700. case kLongDsvFl: cvt_l( char,vp,v,sn); break;
  701. case kULongDsvFl: cvt_ul( char,vp,v,sn); break;
  702. case kIntDsvFl: cvt_i( char,vp,v,sn); break;
  703. case kUIntDsvFl: cvt_u( char,vp,v,sn); break;
  704. case kFloatDsvFl: cvt_f( char,vp,v,sn); break;
  705. case kDoubleDsvFl: cvt_d( char,vp,v,sn); break;
  706. case kSampleDsvFl: cvt_s( char,vp,v,sn); break;
  707. case kRealDsvFl: cvt_r( char,vp,v,sn); break;
  708. default:
  709. assert(0);
  710. return kUnknownTypeDsvRC;
  711. }
  712. return kOkDsvRC;
  713. }
  714. cmDsvRC_t cmDsvGetUCharMtx( cmDspValue_t* vp, unsigned char* v, unsigned vn )
  715. {
  716. vp = _vptr(vp);
  717. cmDsvRC_t rc;
  718. unsigned sn;
  719. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  720. return rc;
  721. switch(cmDsvBasicType(vp))
  722. {
  723. case kBoolDsvFl: cvt_b( unsigned char,vp,v,sn); break;
  724. case kCharDsvFl: cvt_c( unsigned char,vp,v,sn); break;
  725. case kUCharDsvFl: cvt_uc( unsigned char,vp,v,sn); break;
  726. case kShortDsvFl: cvt_s( unsigned char,vp,v,sn); break;
  727. case kUShortDsvFl: cvt_us( unsigned char,vp,v,sn); break;
  728. case kLongDsvFl: cvt_l( unsigned char,vp,v,sn); break;
  729. case kULongDsvFl: cvt_ul( unsigned char,vp,v,sn); break;
  730. case kIntDsvFl: cvt_i( unsigned char,vp,v,sn); break;
  731. case kUIntDsvFl: cvt_u( unsigned char,vp,v,sn); break;
  732. case kFloatDsvFl: cvt_f( unsigned char,vp,v,sn); break;
  733. case kDoubleDsvFl: cvt_d( unsigned char,vp,v,sn); break;
  734. case kSampleDsvFl: cvt_s( unsigned char,vp,v,sn); break;
  735. case kRealDsvFl: cvt_r( unsigned char,vp,v,sn); break;
  736. default:
  737. assert(0);
  738. return kUnknownTypeDsvRC;
  739. }
  740. return kOkDsvRC;
  741. }
  742. cmDsvRC_t cmDsvGetShortMtx( cmDspValue_t* vp, short* v, unsigned vn )
  743. {
  744. vp = _vptr(vp);
  745. cmDsvRC_t rc;
  746. unsigned sn;
  747. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  748. return rc;
  749. switch(cmDsvBasicType(vp))
  750. {
  751. case kBoolDsvFl: cvt_b( short,vp,v,sn); break;
  752. case kCharDsvFl: cvt_c( short,vp,v,sn); break;
  753. case kUCharDsvFl: cvt_uc( short,vp,v,sn); break;
  754. case kShortDsvFl: cvt_s( short,vp,v,sn); break;
  755. case kUShortDsvFl: cvt_us( short,vp,v,sn); break;
  756. case kLongDsvFl: cvt_l( short,vp,v,sn); break;
  757. case kULongDsvFl: cvt_ul( short,vp,v,sn); break;
  758. case kIntDsvFl: cvt_i( short,vp,v,sn); break;
  759. case kUIntDsvFl: cvt_u( short,vp,v,sn); break;
  760. case kFloatDsvFl: cvt_f( short,vp,v,sn); break;
  761. case kDoubleDsvFl: cvt_d( short,vp,v,sn); break;
  762. case kSampleDsvFl: cvt_s( short,vp,v,sn); break;
  763. case kRealDsvFl: cvt_r( short,vp,v,sn); break;
  764. default:
  765. assert(0);
  766. return kUnknownTypeDsvRC;
  767. }
  768. return kOkDsvRC;
  769. }
  770. cmDsvRC_t cmDsvGetUShortMtx( cmDspValue_t* vp, unsigned short* v, unsigned vn )
  771. {
  772. vp = _vptr(vp);
  773. cmDsvRC_t rc;
  774. unsigned sn;
  775. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  776. return rc;
  777. switch(cmDsvBasicType(vp))
  778. {
  779. case kBoolDsvFl: cvt_b( unsigned short,vp,v,sn); break;
  780. case kCharDsvFl: cvt_c( unsigned short,vp,v,sn); break;
  781. case kUCharDsvFl: cvt_uc( unsigned short,vp,v,sn); break;
  782. case kShortDsvFl: cvt_s( unsigned short,vp,v,sn); break;
  783. case kUShortDsvFl: cvt_us( unsigned short,vp,v,sn); break;
  784. case kLongDsvFl: cvt_l( unsigned short,vp,v,sn); break;
  785. case kULongDsvFl: cvt_ul( unsigned short,vp,v,sn); break;
  786. case kIntDsvFl: cvt_i( unsigned short,vp,v,sn); break;
  787. case kUIntDsvFl: cvt_u( unsigned short,vp,v,sn); break;
  788. case kFloatDsvFl: cvt_f( unsigned short,vp,v,sn); break;
  789. case kDoubleDsvFl: cvt_d( unsigned short,vp,v,sn); break;
  790. case kSampleDsvFl: cvt_s( unsigned short,vp,v,sn); break;
  791. case kRealDsvFl: cvt_r( unsigned short,vp,v,sn); break;
  792. default:
  793. assert(0);
  794. return kUnknownTypeDsvRC;
  795. }
  796. return kOkDsvRC;
  797. }
  798. cmDsvRC_t cmDsvGetLongMtx( cmDspValue_t* vp, long* v, unsigned vn )
  799. {
  800. vp = _vptr(vp);
  801. cmDsvRC_t rc;
  802. unsigned sn;
  803. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  804. return rc;
  805. switch(cmDsvBasicType(vp))
  806. {
  807. case kBoolDsvFl: cvt_b( long,vp,v,sn); break;
  808. case kCharDsvFl: cvt_c( long,vp,v,sn); break;
  809. case kUCharDsvFl: cvt_uc( long,vp,v,sn); break;
  810. case kShortDsvFl: cvt_s( long,vp,v,sn); break;
  811. case kUShortDsvFl: cvt_us( long,vp,v,sn); break;
  812. case kLongDsvFl: cvt_l( long,vp,v,sn); break;
  813. case kULongDsvFl: cvt_ul( long,vp,v,sn); break;
  814. case kIntDsvFl: cvt_i( long,vp,v,sn); break;
  815. case kUIntDsvFl: cvt_u( long,vp,v,sn); break;
  816. case kFloatDsvFl: cvt_f( long,vp,v,sn); break;
  817. case kDoubleDsvFl: cvt_d( long,vp,v,sn); break;
  818. case kSampleDsvFl: cvt_s( long,vp,v,sn); break;
  819. case kRealDsvFl: cvt_r( long,vp,v,sn); break;
  820. default:
  821. assert(0);
  822. return kUnknownTypeDsvRC;
  823. }
  824. return kOkDsvRC;
  825. }
  826. cmDsvRC_t cmDsvGetULongMtx( cmDspValue_t* vp, unsigned long* v, unsigned vn )
  827. {
  828. vp = _vptr(vp);
  829. cmDsvRC_t rc;
  830. unsigned sn;
  831. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  832. return rc;
  833. switch(cmDsvBasicType(vp))
  834. {
  835. case kBoolDsvFl: cvt_b( unsigned long,vp,v,sn); break;
  836. case kCharDsvFl: cvt_c( unsigned long,vp,v,sn); break;
  837. case kUCharDsvFl: cvt_uc( unsigned long,vp,v,sn); break;
  838. case kShortDsvFl: cvt_s( unsigned long,vp,v,sn); break;
  839. case kUShortDsvFl: cvt_us( unsigned long,vp,v,sn); break;
  840. case kLongDsvFl: cvt_l( unsigned long,vp,v,sn); break;
  841. case kULongDsvFl: cvt_ul( unsigned long,vp,v,sn); break;
  842. case kIntDsvFl: cvt_i( unsigned long,vp,v,sn); break;
  843. case kUIntDsvFl: cvt_u( unsigned long,vp,v,sn); break;
  844. case kFloatDsvFl: cvt_f( unsigned long,vp,v,sn); break;
  845. case kDoubleDsvFl: cvt_d( unsigned long,vp,v,sn); break;
  846. case kSampleDsvFl: cvt_s( unsigned long,vp,v,sn); break;
  847. case kRealDsvFl: cvt_r( unsigned long,vp,v,sn); break;
  848. default:
  849. assert(0);
  850. return kUnknownTypeDsvRC;
  851. }
  852. return kOkDsvRC;
  853. }
  854. cmDsvRC_t cmDsvGetIntMtx( cmDspValue_t* vp, int* v, unsigned vn )
  855. {
  856. vp = _vptr(vp);
  857. cmDsvRC_t rc;
  858. unsigned sn;
  859. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  860. return rc;
  861. switch(cmDsvBasicType(vp))
  862. {
  863. case kBoolDsvFl: cvt_b( int,vp,v,sn); break;
  864. case kCharDsvFl: cvt_c( int,vp,v,sn); break;
  865. case kUCharDsvFl: cvt_uc( int,vp,v,sn); break;
  866. case kShortDsvFl: cvt_s( int,vp,v,sn); break;
  867. case kUShortDsvFl: cvt_us( int,vp,v,sn); break;
  868. case kLongDsvFl: cvt_l( int,vp,v,sn); break;
  869. case kULongDsvFl: cvt_ul( int,vp,v,sn); break;
  870. case kIntDsvFl: cvt_i( int,vp,v,sn); break;
  871. case kUIntDsvFl: cvt_u( int,vp,v,sn); break;
  872. case kFloatDsvFl: cvt_f( int,vp,v,sn); break;
  873. case kDoubleDsvFl: cvt_d( int,vp,v,sn); break;
  874. case kSampleDsvFl: cvt_s( int,vp,v,sn); break;
  875. case kRealDsvFl: cvt_r( int,vp,v,sn); break;
  876. default:
  877. assert(0);
  878. return kUnknownTypeDsvRC;
  879. }
  880. return kOkDsvRC;
  881. }
  882. cmDsvRC_t cmDsvGetUIntMtx( cmDspValue_t* vp, unsigned int* v, unsigned vn )
  883. {
  884. vp = _vptr(vp);
  885. cmDsvRC_t rc;
  886. unsigned sn;
  887. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  888. return rc;
  889. switch(cmDsvBasicType(vp))
  890. {
  891. case kBoolDsvFl: cvt_b( unsigned int,vp,v,sn); break;
  892. case kCharDsvFl: cvt_c( unsigned int,vp,v,sn); break;
  893. case kUCharDsvFl: cvt_uc( unsigned int,vp,v,sn); break;
  894. case kShortDsvFl: cvt_s( unsigned int,vp,v,sn); break;
  895. case kUShortDsvFl: cvt_us( unsigned int,vp,v,sn); break;
  896. case kLongDsvFl: cvt_l( unsigned int,vp,v,sn); break;
  897. case kULongDsvFl: cvt_ul( unsigned int,vp,v,sn); break;
  898. case kIntDsvFl: cvt_i( unsigned int,vp,v,sn); break;
  899. case kUIntDsvFl: cvt_u( unsigned int,vp,v,sn); break;
  900. case kFloatDsvFl: cvt_f( unsigned int,vp,v,sn); break;
  901. case kDoubleDsvFl: cvt_d( unsigned int,vp,v,sn); break;
  902. case kSampleDsvFl: cvt_s( unsigned int,vp,v,sn); break;
  903. case kRealDsvFl: cvt_r( unsigned int,vp,v,sn); break;
  904. default:
  905. assert(0);
  906. return kUnknownTypeDsvRC;
  907. }
  908. return kOkDsvRC;
  909. }
  910. cmDsvRC_t cmDsvGetFloatMtx( cmDspValue_t* vp, float* v, unsigned vn )
  911. {
  912. vp = _vptr(vp);
  913. cmDsvRC_t rc;
  914. unsigned sn;
  915. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  916. return rc;
  917. switch(cmDsvBasicType(vp))
  918. {
  919. case kBoolDsvFl: cvt_b( float,vp,v,sn); break;
  920. case kCharDsvFl: cvt_c( float,vp,v,sn); break;
  921. case kUCharDsvFl: cvt_uc( float,vp,v,sn); break;
  922. case kShortDsvFl: cvt_s( float,vp,v,sn); break;
  923. case kUShortDsvFl: cvt_us( float,vp,v,sn); break;
  924. case kLongDsvFl: cvt_l( float,vp,v,sn); break;
  925. case kULongDsvFl: cvt_ul( float,vp,v,sn); break;
  926. case kIntDsvFl: cvt_i( float,vp,v,sn); break;
  927. case kUIntDsvFl: cvt_u( float,vp,v,sn); break;
  928. case kFloatDsvFl: cvt_f( float,vp,v,sn); break;
  929. case kDoubleDsvFl: cvt_d( float,vp,v,sn); break;
  930. case kSampleDsvFl: cvt_s( float,vp,v,sn); break;
  931. case kRealDsvFl: cvt_r( float,vp,v,sn); break;
  932. default:
  933. assert(0);
  934. return kUnknownTypeDsvRC;
  935. }
  936. return kOkDsvRC;
  937. }
  938. cmDsvRC_t cmDsvGetDoubleMtx( cmDspValue_t* vp, double* v, unsigned vn )
  939. {
  940. vp = _vptr(vp);
  941. cmDsvRC_t rc;
  942. unsigned sn;
  943. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  944. return rc;
  945. switch(cmDsvBasicType(vp))
  946. {
  947. case kBoolDsvFl: cvt_b( double,vp,v,sn); break;
  948. case kCharDsvFl: cvt_c( double,vp,v,sn); break;
  949. case kUCharDsvFl: cvt_uc( double,vp,v,sn); break;
  950. case kShortDsvFl: cvt_s( double,vp,v,sn); break;
  951. case kUShortDsvFl: cvt_us( double,vp,v,sn); break;
  952. case kLongDsvFl: cvt_l( double,vp,v,sn); break;
  953. case kULongDsvFl: cvt_ul( double,vp,v,sn); break;
  954. case kIntDsvFl: cvt_i( double,vp,v,sn); break;
  955. case kUIntDsvFl: cvt_u( double,vp,v,sn); break;
  956. case kFloatDsvFl: cvt_f( double,vp,v,sn); break;
  957. case kDoubleDsvFl: cvt_d( double,vp,v,sn); break;
  958. case kSampleDsvFl: cvt_s( double,vp,v,sn); break;
  959. case kRealDsvFl: cvt_r( double,vp,v,sn); break;
  960. default:
  961. assert(0);
  962. return kUnknownTypeDsvRC;
  963. }
  964. return kOkDsvRC;
  965. }
  966. cmDsvRC_t cmDsvGetSampleMtx( cmDspValue_t* vp, cmSample_t* v, unsigned vn )
  967. {
  968. vp = _vptr(vp);
  969. cmDsvRC_t rc;
  970. unsigned sn;
  971. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  972. return rc;
  973. switch(cmDsvBasicType(vp))
  974. {
  975. case kBoolDsvFl: cvt_b( cmSample_t,vp,v,sn); break;
  976. case kCharDsvFl: cvt_c( cmSample_t,vp,v,sn); break;
  977. case kUCharDsvFl: cvt_uc( cmSample_t,vp,v,sn); break;
  978. case kShortDsvFl: cvt_s( cmSample_t,vp,v,sn); break;
  979. case kUShortDsvFl: cvt_us( cmSample_t,vp,v,sn); break;
  980. case kLongDsvFl: cvt_l( cmSample_t,vp,v,sn); break;
  981. case kULongDsvFl: cvt_ul( cmSample_t,vp,v,sn); break;
  982. case kIntDsvFl: cvt_i( cmSample_t,vp,v,sn); break;
  983. case kUIntDsvFl: cvt_u( cmSample_t,vp,v,sn); break;
  984. case kFloatDsvFl: cvt_f( cmSample_t,vp,v,sn); break;
  985. case kDoubleDsvFl: cvt_d( cmSample_t,vp,v,sn); break;
  986. case kSampleDsvFl: cvt_s( cmSample_t,vp,v,sn); break;
  987. case kRealDsvFl: cvt_r( cmSample_t,vp,v,sn); break;
  988. default:
  989. assert(0);
  990. return kUnknownTypeDsvRC;
  991. }
  992. return kOkDsvRC;
  993. }
  994. cmDsvRC_t cmDsvGetRealMtx( cmDspValue_t* vp, cmReal_t* v, unsigned vn )
  995. {
  996. vp = _vptr(vp);
  997. cmDsvRC_t rc;
  998. unsigned sn;
  999. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  1000. return rc;
  1001. switch(cmDsvBasicType(vp))
  1002. {
  1003. case kBoolDsvFl: cvt_b( cmReal_t,vp,v,sn); break;
  1004. case kCharDsvFl: cvt_c( cmReal_t,vp,v,sn); break;
  1005. case kUCharDsvFl: cvt_uc( cmReal_t,vp,v,sn); break;
  1006. case kShortDsvFl: cvt_s( cmReal_t,vp,v,sn); break;
  1007. case kUShortDsvFl: cvt_us( cmReal_t,vp,v,sn); break;
  1008. case kLongDsvFl: cvt_l( cmReal_t,vp,v,sn); break;
  1009. case kULongDsvFl: cvt_ul( cmReal_t,vp,v,sn); break;
  1010. case kIntDsvFl: cvt_i( cmReal_t,vp,v,sn); break;
  1011. case kUIntDsvFl: cvt_u( cmReal_t,vp,v,sn); break;
  1012. case kFloatDsvFl: cvt_f( cmReal_t,vp,v,sn); break;
  1013. case kDoubleDsvFl: cvt_d( cmReal_t,vp,v,sn); break;
  1014. case kSampleDsvFl: cvt_s( cmReal_t,vp,v,sn); break;
  1015. case kRealDsvFl: cvt_r( cmReal_t,vp,v,sn); break;
  1016. default:
  1017. assert(0);
  1018. return kUnknownTypeDsvRC;
  1019. }
  1020. return kOkDsvRC;
  1021. }
  1022. cmDsvRC_t cmDsvGetStrzMtx( cmDspValue_t* vp, cmChar_t* v, unsigned vn )
  1023. {
  1024. vp = _vptr(vp);
  1025. cmDsvRC_t rc;
  1026. unsigned sn;
  1027. if((rc = _cmDsvValidateMtx(vp,vn,&sn)) != kOkDsvRC )
  1028. return rc;
  1029. if( cmIsFlag(vp->flags,kConstDsvFl) )
  1030. return kConstViolationDsvRC;
  1031. switch(cmDsvBasicType(vp))
  1032. {
  1033. case kBoolDsvFl: cvt_b( cmChar_t,vp,v,sn); break;
  1034. case kCharDsvFl: cvt_c( cmChar_t,vp,v,sn); break;
  1035. case kUCharDsvFl: cvt_uc( cmChar_t,vp,v,sn); break;
  1036. case kShortDsvFl: cvt_s( cmChar_t,vp,v,sn); break;
  1037. case kUShortDsvFl: cvt_us( cmChar_t,vp,v,sn); break;
  1038. case kLongDsvFl: cvt_l( cmChar_t,vp,v,sn); break;
  1039. case kULongDsvFl: cvt_ul( cmChar_t,vp,v,sn); break;
  1040. case kIntDsvFl: cvt_i( cmChar_t,vp,v,sn); break;
  1041. case kUIntDsvFl: cvt_u( cmChar_t,vp,v,sn); break;
  1042. case kFloatDsvFl: cvt_f( cmChar_t,vp,v,sn); break;
  1043. case kDoubleDsvFl: cvt_d( cmChar_t,vp,v,sn); break;
  1044. case kSampleDsvFl: cvt_s( cmChar_t,vp,v,sn); break;
  1045. case kRealDsvFl: cvt_r( cmChar_t,vp,v,sn); break;
  1046. default:
  1047. assert(0);
  1048. return kUnknownTypeDsvRC;
  1049. }
  1050. return kOkDsvRC;
  1051. }
  1052. bool cmDsvIsType( const cmDspValue_t* vp, unsigned flags )
  1053. { vp = _vcptr(vp); return cmAllFlags(vp->flags,flags); }
  1054. bool cmDsvIsMtx( const cmDspValue_t* vp )
  1055. { return cmIsFlag(vp->flags,kMtxDsvFl); }
  1056. unsigned cmDsvEleCount( const cmDspValue_t* vp )
  1057. {
  1058. vp = _vcptr(vp);
  1059. if( cmIsFlag(vp->flags,kMtxDsvFl)==false)
  1060. return 0;
  1061. return vp->u.m.rn * vp->u.m.cn;
  1062. }
  1063. unsigned cmDsvRows( const cmDspValue_t* vp )
  1064. {
  1065. vp = _vcptr(vp);
  1066. if( cmIsFlag(vp->flags,kMtxDsvFl)==false)
  1067. return 0;
  1068. return vp->u.m.rn;
  1069. }
  1070. unsigned cmDsvCols( const cmDspValue_t* vp )
  1071. {
  1072. vp = _vcptr(vp);
  1073. if( cmIsFlag(vp->flags,kMtxDsvFl)==false)
  1074. return 0;
  1075. return vp->u.m.cn;
  1076. }
  1077. unsigned cmDsvBasicType( const cmDspValue_t* vp )
  1078. { vp = _vcptr(vp); return _cmDsvBasicType(vp->flags); }
  1079. unsigned cmDsvEleByteCount( const cmDspValue_t* vp )
  1080. { vp = _vcptr(vp); return _cmDsvEleByteCount(vp->flags); }
  1081. unsigned cmDsvByteCount( unsigned flags, unsigned rn, unsigned cn )
  1082. {
  1083. flags = flags & kTypeDsvMask;
  1084. return (cmIsFlag(flags,kMtxDsvFl) ? rn*cn : 1) * _cmDsvEleByteCount(flags);
  1085. }
  1086. unsigned cmDsvSerialByteCount( const cmDspValue_t* vp )
  1087. {
  1088. vp = _vcptr(vp);
  1089. unsigned byteCnt = sizeof(cmDspValue_t);
  1090. unsigned basicType = cmDsvBasicType(vp);
  1091. if( cmDsvIsMtx(vp) )
  1092. {
  1093. switch(basicType)
  1094. {
  1095. case kBoolDsvFl:
  1096. case kCharDsvFl:
  1097. case kUCharDsvFl:
  1098. case kShortDsvFl:
  1099. case kUShortDsvFl:
  1100. case kLongDsvFl:
  1101. case kULongDsvFl:
  1102. case kIntDsvFl:
  1103. case kUIntDsvFl:
  1104. case kFloatDsvFl:
  1105. case kDoubleDsvFl:
  1106. case kSampleDsvFl:
  1107. case kRealDsvFl:
  1108. case kSymDsvFl:
  1109. byteCnt += cmDsvRows(vp) * cmDsvCols(vp) * cmDsvEleByteCount(vp);
  1110. break;
  1111. case kStrzDsvFl:
  1112. case kJsonDsvFl:
  1113. // not implemented - these serializers still need to be implemented
  1114. byteCnt = 0;
  1115. assert(0);
  1116. break;
  1117. default:
  1118. { assert(0); }
  1119. }
  1120. }
  1121. else // scalars
  1122. {
  1123. switch(basicType)
  1124. {
  1125. case kBoolDsvFl:
  1126. case kCharDsvFl:
  1127. case kUCharDsvFl:
  1128. case kShortDsvFl:
  1129. case kUShortDsvFl:
  1130. case kLongDsvFl:
  1131. case kULongDsvFl:
  1132. case kIntDsvFl:
  1133. case kUIntDsvFl:
  1134. case kFloatDsvFl:
  1135. case kDoubleDsvFl:
  1136. case kSampleDsvFl:
  1137. case kRealDsvFl:
  1138. case kPtrDsvFl:
  1139. case kSymDsvFl:
  1140. // these types are stored as part of the type record
  1141. // and therefore don't need any extra storage
  1142. break;
  1143. case kStrzDsvFl:
  1144. byteCnt += vp->u.z==NULL ? 0 : strlen(vp->u.z) + 1;
  1145. break;
  1146. case kJsonDsvFl:
  1147. if( vp->u.j != NULL )
  1148. {
  1149. assert( cmJsonValidate(vp->u.j) == kOkJsRC );
  1150. byteCnt += cmJsonSerialByteCount( vp->u.j );
  1151. }
  1152. break;
  1153. default:
  1154. { assert(0); }
  1155. }
  1156. }
  1157. return byteCnt;
  1158. }
  1159. unsigned cmDsvSerialDataByteCount( const cmDspValue_t* vp )
  1160. { vp = _vcptr(vp); return cmDsvSerialByteCount(vp) - sizeof(cmDspValue_t); }
  1161. cmDsvRC_t cmDsvSerialize( const cmDspValue_t* vp, void* buf, unsigned bufByteCnt )
  1162. {
  1163. vp = _vcptr(vp);
  1164. // the buffer must be at least large enough to
  1165. // hold the cmDspValue_t header record
  1166. if( bufByteCnt < sizeof(cmDspValue_t) )
  1167. return kRetTooSmallDsvRC;
  1168. cmDspValue_t* hp = (cmDspValue_t*)buf;
  1169. char* dp = (char*)(hp + 1);
  1170. char* ep = ((char*)buf) + bufByteCnt;
  1171. unsigned basicType = cmDsvBasicType(vp);
  1172. *hp = *vp; // copy the type header record
  1173. if( cmDsvIsMtx(vp) )
  1174. {
  1175. switch(basicType)
  1176. {
  1177. case kBoolDsvFl:
  1178. case kCharDsvFl:
  1179. case kUCharDsvFl:
  1180. case kShortDsvFl:
  1181. case kUShortDsvFl:
  1182. case kLongDsvFl:
  1183. case kULongDsvFl:
  1184. case kIntDsvFl:
  1185. case kUIntDsvFl:
  1186. case kFloatDsvFl:
  1187. case kDoubleDsvFl:
  1188. case kSampleDsvFl:
  1189. case kRealDsvFl:
  1190. {
  1191. // if the mtx data ptr is NULL then set it to NULL in the serialized data
  1192. if( vp->u.m.u.vp == NULL )
  1193. hp->u.m.u.vp = NULL;
  1194. else
  1195. {
  1196. unsigned bn = cmDsvRows(vp) * cmDsvCols(vp) * cmDsvEleByteCount(vp);
  1197. if( dp + bn > ep )
  1198. return kRetTooSmallDsvRC;
  1199. memcpy(dp, vp->u.m.u.vp, bn);
  1200. hp->u.m.u.vp = dp;
  1201. }
  1202. }
  1203. break;
  1204. case kStrzDsvFl:
  1205. case kJsonDsvFl:
  1206. // not implemented - fall through and assert
  1207. default:
  1208. { assert(0); }
  1209. }
  1210. }
  1211. else // scalars
  1212. {
  1213. switch(basicType)
  1214. {
  1215. case kBoolDsvFl:
  1216. case kCharDsvFl:
  1217. case kUCharDsvFl:
  1218. case kShortDsvFl:
  1219. case kUShortDsvFl:
  1220. case kLongDsvFl:
  1221. case kULongDsvFl:
  1222. case kIntDsvFl:
  1223. case kUIntDsvFl:
  1224. case kFloatDsvFl:
  1225. case kDoubleDsvFl:
  1226. case kSampleDsvFl:
  1227. case kRealDsvFl:
  1228. case kPtrDsvFl:
  1229. case kSymDsvFl:
  1230. // these types are stored as part of the type record
  1231. // and therefore don't need any extra storage
  1232. break;
  1233. case kStrzDsvFl:
  1234. if( vp->u.z==NULL )
  1235. hp->u.z = NULL;
  1236. else
  1237. {
  1238. unsigned bn = strlen(vp->u.z) + 1;
  1239. if( dp + bn > ep )
  1240. return kRetTooSmallDsvRC;
  1241. strncpy(dp,vp->u.z,bn);
  1242. hp->u.z = dp;
  1243. }
  1244. break;
  1245. case kJsonDsvFl:
  1246. if( vp->u.j == NULL )
  1247. hp->u.j = NULL;
  1248. else
  1249. {
  1250. unsigned bn = cmJsonSerialByteCount( vp->u.j );
  1251. if( dp + bn > ep )
  1252. return kRetTooSmallDsvRC;
  1253. if( cmJsonSerialize(vp->u.j,dp,bufByteCnt-sizeof(cmDspValue_t)) != kOkJsRC )
  1254. return kRetTooSmallDsvRC;
  1255. }
  1256. break;
  1257. default:
  1258. { assert(0); }
  1259. }
  1260. }
  1261. return kOkDsvRC;
  1262. }
  1263. cmDsvRC_t cmDsvDeserializeInPlace( cmDspValue_t* vp, unsigned dataBufByteCnt )
  1264. {
  1265. vp = _vptr(vp);
  1266. assert( cmIsFlag(vp->flags,kJsonDsvFl)==false );
  1267. void** vpp = _cmDsvGetDataPtrPtr(vp);
  1268. if( vpp != NULL )
  1269. {
  1270. *vpp = vp + 1;
  1271. }
  1272. return kOkDsvRC;
  1273. }
  1274. cmDsvRC_t cmDsvDeserializeJson( cmDspValue_t* vp, cmJsonH_t jsH )
  1275. {
  1276. vp = _vptr(vp);
  1277. if( cmJsonClearTree(jsH) )
  1278. return kJsonDeserialFailDsvRC;
  1279. if( cmJsonDeserialize(jsH, vp + 1, NULL ) != kOkJsRC )
  1280. return kJsonDeserialFailDsvRC;
  1281. vp->u.j = cmJsonRoot(jsH);
  1282. return kOkDsvRC;
  1283. }
  1284. void cmDsvPrint( const cmDspValue_t* vp, const cmChar_t* label, cmRpt_t* rpt )
  1285. {
  1286. vp = _vcptr(vp);
  1287. const char* noLbl="";
  1288. const char* lbl = label==NULL? noLbl : label;
  1289. if( cmDsvIsMtx(vp) )
  1290. {
  1291. unsigned i,j;
  1292. unsigned rn = cmDsvCols(vp);
  1293. unsigned cn = cmDsvRows(vp);
  1294. for(i=0; i<rn; ++i)
  1295. {
  1296. for(j=0; j<cn; ++j)
  1297. {
  1298. switch( cmDsvBasicType(vp) )
  1299. {
  1300. case kCharDsvFl: cmRptPrintf (rpt,"%s%c ",lbl,vp->u.m.u.cp[ (j*rn) + i ]); break;
  1301. case kUCharDsvFl: cmRptPrintf (rpt,"%s%c ",lbl,vp->u.m.u.ucp[ (j*rn) + i ]); break;
  1302. case kShortDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.sp[ (j*rn) + i ]); break;
  1303. case kUShortDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.usp[ (j*rn) + i ]); break;
  1304. case kLongDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.lp[ (j*rn) + i ]); break;
  1305. case kULongDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.ulp[ (j*rn) + i ]); break;
  1306. case kIntDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.ip[ (j*rn) + i ]); break;
  1307. case kUIntDsvFl: cmRptPrintf (rpt,"%s%i ",lbl,vp->u.m.u.up[ (j*rn) + i ]); break;
  1308. case kFloatDsvFl: cmRptPrintf (rpt,"%s%f ",lbl,vp->u.m.u.fp[ (j*rn) + i ]); break;
  1309. case kDoubleDsvFl: cmRptPrintf (rpt,"%s%f ",lbl,vp->u.m.u.dp[ (j*rn) + i ]); break;
  1310. case kSampleDsvFl: cmRptPrintf (rpt,"%s%f ",lbl,vp->u.m.u.ap[ (j*rn) + i ]); break;
  1311. case kRealDsvFl: cmRptPrintf (rpt,"%s%f ",lbl,vp->u.m.u.rp[ (j*rn) + i ]); break;
  1312. case kStrzDsvFl: cmRptPrintf (rpt,"%s%s ",lbl,vp->u.m.u.zp[ (j*rn) + i ]); break;
  1313. case kJsonDsvFl: cmJsonPrintTree(vp->u.m.u.jp[ (j*rn) + i ],rpt); break;
  1314. default:
  1315. { assert(0); }
  1316. }
  1317. }
  1318. cmRptPrint(rpt,"\n");
  1319. }
  1320. }
  1321. else
  1322. {
  1323. switch( cmDsvBasicType(vp) )
  1324. {
  1325. case kBoolDsvFl: cmRptPrintf(rpt,"%s%s ",lbl,vp->u.b ? "true" : "false"); break;
  1326. case kCharDsvFl: cmRptPrintf(rpt,"%s%c ",lbl,vp->u.c); break;
  1327. case kUCharDsvFl: cmRptPrintf(rpt,"%s%c ",lbl,vp->u.uc); break;
  1328. case kShortDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.s); break;
  1329. case kUShortDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.us); break;
  1330. case kLongDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.l); break;
  1331. case kULongDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.ul); break;
  1332. case kIntDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.i); break;
  1333. case kUIntDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.u); break;
  1334. case kFloatDsvFl: cmRptPrintf(rpt,"%s%f ",lbl,vp->u.f); break;
  1335. case kDoubleDsvFl: cmRptPrintf(rpt,"%s%f ",lbl,vp->u.d); break;
  1336. case kSampleDsvFl: cmRptPrintf(rpt,"%s%f ",lbl,vp->u.a); break;
  1337. case kRealDsvFl: cmRptPrintf(rpt,"%s%f ",lbl,vp->u.r); break;
  1338. case kPtrDsvFl: cmRptPrintf(rpt,"%s%p ",lbl,vp->u.vp); break;
  1339. case kStrzDsvFl: cmRptPrintf(rpt,"%s%s ",lbl,vp->u.z); break;
  1340. case kSymDsvFl: cmRptPrintf(rpt,"%s%i ",lbl,vp->u.u); break;
  1341. case kJsonDsvFl: cmJsonPrintTree(vp->u.j,rpt); break;
  1342. default:
  1343. { assert(0); }
  1344. }
  1345. }
  1346. }