libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmDspValue.c 59KB

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