Variant.h 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  1. //
  2. // Notice Regarding Standards. AMD does not provide a license or sublicense to
  3. // any Intellectual Property Rights relating to any standards, including but not
  4. // limited to any audio and/or video codec technologies such as MPEG-2, MPEG-4;
  5. // AVC/H.264; HEVC/H.265; AAC decode/FFMPEG; AAC encode/FFMPEG; VC-1; and MP3
  6. // (collectively, the "Media Technologies"). For clarity, you will pay any
  7. // royalties due for such third party technologies, which may include the Media
  8. // Technologies that are owed as a result of AMD providing the Software to you.
  9. //
  10. // MIT license
  11. //
  12. // Copyright (c) 2018 Advanced Micro Devices, Inc. All rights reserved.
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining a copy
  15. // of this software and associated documentation files (the "Software"), to deal
  16. // in the Software without restriction, including without limitation the rights
  17. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  18. // copies of the Software, and to permit persons to whom the Software is
  19. // furnished to do so, subject to the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included in
  22. // all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  25. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  26. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  27. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  28. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  29. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  30. // THE SOFTWARE.
  31. //
  32. #ifndef AMF_Variant_h
  33. #define AMF_Variant_h
  34. #pragma once
  35. #if defined(_MSC_VER)
  36. #pragma warning(disable: 4996)
  37. #endif
  38. #include "Interface.h"
  39. #include <locale.h>
  40. #include <wchar.h>
  41. #include <string.h>
  42. #if defined(__cplusplus)
  43. namespace amf
  44. {
  45. #endif
  46. //----------------------------------------------------------------------------------------------
  47. // variant types
  48. //----------------------------------------------------------------------------------------------
  49. typedef enum AMF_VARIANT_TYPE
  50. {
  51. AMF_VARIANT_EMPTY = 0,
  52. AMF_VARIANT_BOOL = 1,
  53. AMF_VARIANT_INT64 = 2,
  54. AMF_VARIANT_DOUBLE = 3,
  55. AMF_VARIANT_RECT = 4,
  56. AMF_VARIANT_SIZE = 5,
  57. AMF_VARIANT_POINT = 6,
  58. AMF_VARIANT_RATE = 7,
  59. AMF_VARIANT_RATIO = 8,
  60. AMF_VARIANT_COLOR = 9,
  61. AMF_VARIANT_STRING = 10, // value is char*
  62. AMF_VARIANT_WSTRING = 11, // value is wchar_t*
  63. AMF_VARIANT_INTERFACE = 12, // value is AMFInterface*
  64. AMF_VARIANT_FLOAT = 13,
  65. AMF_VARIANT_FLOAT_SIZE = 14,
  66. AMF_VARIANT_FLOAT_POINT2D = 15,
  67. AMF_VARIANT_FLOAT_POINT3D = 16,
  68. AMF_VARIANT_FLOAT_VECTOR4D = 17
  69. } AMF_VARIANT_TYPE;
  70. //----------------------------------------------------------------------------------------------
  71. // variant struct
  72. //----------------------------------------------------------------------------------------------
  73. typedef struct AMFVariantStruct
  74. {
  75. AMF_VARIANT_TYPE type;
  76. union
  77. {
  78. amf_bool boolValue;
  79. amf_int64 int64Value;
  80. amf_double doubleValue;
  81. char* stringValue;
  82. wchar_t* wstringValue;
  83. AMFInterface* pInterface;
  84. struct AMFRect rectValue;
  85. struct AMFSize sizeValue;
  86. struct AMFPoint pointValue;
  87. struct AMFRate rateValue;
  88. struct AMFRatio ratioValue;
  89. struct AMFColor colorValue;
  90. amf_float floatValue;
  91. struct AMFFloatSize floatSizeValue;
  92. struct AMFFloatPoint2D floatPoint2DValue;
  93. struct AMFFloatPoint3D floatPoint3DValue;
  94. struct AMFFloatVector4D floatVector4DValue;
  95. };
  96. } AMFVariantStruct;
  97. //----------------------------------------------------------------------------------------------
  98. // variant accessors
  99. //----------------------------------------------------------------------------------------------
  100. static AMF_INLINE AMF_VARIANT_TYPE AMF_STD_CALL AMFVariantGetType(const AMFVariantStruct* _variant) { return (_variant)->type; }
  101. #if defined(__cplusplus)
  102. static AMF_INLINE AMF_VARIANT_TYPE& AMF_STD_CALL AMFVariantGetType(AMFVariantStruct* _variant) { return (_variant)->type; }
  103. #endif
  104. static AMF_INLINE amf_bool AMF_STD_CALL AMFVariantGetBool(const AMFVariantStruct* _variant) { return (_variant)->boolValue; }
  105. static AMF_INLINE amf_int64 AMF_STD_CALL AMFVariantGetInt64(const AMFVariantStruct* _variant) { return (_variant)->int64Value; }
  106. static AMF_INLINE amf_double AMF_STD_CALL AMFVariantGetDouble(const AMFVariantStruct* _variant) { return (_variant)->doubleValue; }
  107. static AMF_INLINE amf_float AMF_STD_CALL AMFVariantGetFloat(const AMFVariantStruct* _variant) { return (_variant)->floatValue; }
  108. static AMF_INLINE const char* AMF_STD_CALL AMFVariantGetString(const AMFVariantStruct* _variant) { return (_variant)->stringValue; }
  109. static AMF_INLINE const wchar_t* AMF_STD_CALL AMFVariantGetWString(const AMFVariantStruct* _variant) { return (_variant)->wstringValue; }
  110. #if defined(__cplusplus)
  111. static AMF_INLINE const AMFInterface* AMF_STD_CALL AMFVariantGetInterface(const AMFVariantStruct* _variant) { return (_variant)->pInterface; }
  112. #endif
  113. static AMF_INLINE AMFInterface* AMF_STD_CALL AMFVariantGetInterface(AMFVariantStruct* _variant) { return (_variant)->pInterface; }
  114. #if defined(__cplusplus)
  115. static AMF_INLINE const AMFRect & AMF_STD_CALL AMFVariantGetRect (const AMFVariantStruct* _variant) { return (_variant)->rectValue; }
  116. static AMF_INLINE const AMFSize & AMF_STD_CALL AMFVariantGetSize (const AMFVariantStruct* _variant) { return (_variant)->sizeValue; }
  117. static AMF_INLINE const AMFPoint& AMF_STD_CALL AMFVariantGetPoint(const AMFVariantStruct* _variant) { return (_variant)->pointValue; }
  118. static AMF_INLINE const AMFFloatSize& AMF_STD_CALL AMFVariantGetFloatSize(const AMFVariantStruct* _variant) { return (_variant)->floatSizeValue; }
  119. static AMF_INLINE const AMFFloatPoint2D& AMF_STD_CALL AMFVariantGetFloatPoint2D(const AMFVariantStruct* _variant) { return (_variant)->floatPoint2DValue; }
  120. static AMF_INLINE const AMFFloatPoint3D& AMF_STD_CALL AMFVariantGetFloatPoint3D(const AMFVariantStruct* _variant) { return (_variant)->floatPoint3DValue; }
  121. static AMF_INLINE const AMFFloatVector4D& AMF_STD_CALL AMFVariantGetFloatVector4D(const AMFVariantStruct* _variant) { return (_variant)->floatVector4DValue; }
  122. static AMF_INLINE const AMFRate & AMF_STD_CALL AMFVariantGetRate (const AMFVariantStruct* _variant) { return (_variant)->rateValue; }
  123. static AMF_INLINE const AMFRatio& AMF_STD_CALL AMFVariantGetRatio(const AMFVariantStruct* _variant) { return (_variant)->ratioValue; }
  124. static AMF_INLINE const AMFColor& AMF_STD_CALL AMFVariantGetColor(const AMFVariantStruct* _variant) { return (_variant)->colorValue; }
  125. #else // #if defined(__cplusplus)
  126. static AMF_INLINE const AMFRect AMF_STD_CALL AMFVariantGetRect (const AMFVariantStruct* _variant) { return (_variant)->rectValue; }
  127. static AMF_INLINE const AMFSize AMF_STD_CALL AMFVariantGetSize (const AMFVariantStruct* _variant) { return (_variant)->sizeValue; }
  128. static AMF_INLINE const AMFPoint AMF_STD_CALL AMFVariantGetPoint(const AMFVariantStruct* _variant) { return (_variant)->pointValue; }
  129. static AMF_INLINE const AMFFloatSize AMF_STD_CALL AMFVariantGetFloatSize(const AMFVariantStruct* _variant) { return (_variant)->floatSizeValue; }
  130. static AMF_INLINE const AMFFloatPoint2D AMF_STD_CALL AMFVariantGetFloatPoint2D(const AMFVariantStruct* _variant) { return (_variant)->floatPoint2DValue; }
  131. static AMF_INLINE const AMFFloatPoint3D AMF_STD_CALL AMFVariantGetFloatPoint3D(const AMFVariantStruct* _variant) { return (_variant)->floatPoint3DValue; }
  132. static AMF_INLINE const AMFFloatVector4D AMF_STD_CALL AMFVariantGetFloatVector4D(const AMFVariantStruct* _variant) { return (_variant)->floatVector4DValue; }
  133. static AMF_INLINE const AMFRate AMF_STD_CALL AMFVariantGetRate (const AMFVariantStruct* _variant) { return (_variant)->rateValue; }
  134. static AMF_INLINE const AMFRatio AMF_STD_CALL AMFVariantGetRatio(const AMFVariantStruct* _variant) { return (_variant)->ratioValue; }
  135. static AMF_INLINE const AMFColor AMF_STD_CALL AMFVariantGetColor(const AMFVariantStruct* _variant) { return (_variant)->colorValue; }
  136. #endif // #if defined(__cplusplus)
  137. #define AMFVariantEmpty(_variant) 0
  138. #define AMFVariantBool(_variant) (_variant)->boolValue
  139. #define AMFVariantInt64(_variant) (_variant)->int64Value
  140. #define AMFVariantDouble(_variant) (_variant)->doubleValue
  141. #define AMFVariantFloat(_variant) (_variant)->floatValue
  142. #define AMFVariantRect(_variant) (_variant)->rectValue
  143. #define AMFVariantSize(_variant) (_variant)->sizeValue
  144. #define AMFVariantPoint(_variant) (_variant)->pointValue
  145. #define AMFVariantFloatSize(_variant) (_variant)->floatSizeValue
  146. #define AMFVariantFloatPoint2D(_variant) (_variant)->floatPoint2DValue
  147. #define AMFVariantFloatPoint3D(_variant) (_variant)->floatPoint3DValue
  148. #define AMFVariantFloatVector4D(_variant) (_variant)->floatVector4DValue
  149. #define AMFVariantRate(_variant) (_variant)->rateValue
  150. #define AMFVariantRatio(_variant) (_variant)->ratioValue
  151. #define AMFVariantColor(_variant) (_variant)->colorValue
  152. #define AMFVariantString(_variant) (_variant)->stringValue
  153. #define AMFVariantWString(_variant) (_variant)->wstringValue
  154. #define AMFVariantInterface(_variant) (_variant)->pInterface
  155. //----------------------------------------------------------------------------------------------
  156. // variant hleper functions
  157. //----------------------------------------------------------------------------------------------
  158. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantInit(AMFVariantStruct* pVariant);
  159. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantClear(AMFVariantStruct* pVariant);
  160. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantCompare(const AMFVariantStruct* pFirst, const AMFVariantStruct* pSecond, amf_bool* equal);
  161. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantCopy(AMFVariantStruct* pDest, const AMFVariantStruct* pSrc);
  162. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignBool(AMFVariantStruct* pDest, amf_bool value);
  163. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignInt64(AMFVariantStruct* pDest, amf_int64 value);
  164. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignDouble(AMFVariantStruct* pDest, amf_double value);
  165. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloat(AMFVariantStruct* pDest, amf_float value);
  166. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignString(AMFVariantStruct* pDest, const char* value);
  167. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignWString(AMFVariantStruct* pDest, const wchar_t* value);
  168. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignInterface(AMFVariantStruct* pDest, AMFInterface* value);
  169. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRect(AMFVariantStruct* pDest, const AMFRect* value);
  170. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignSize(AMFVariantStruct* pDest, const AMFSize* value);
  171. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignPoint(AMFVariantStruct* pDest, const AMFPoint* value);
  172. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatSize(AMFVariantStruct* pDest, const AMFFloatSize* value);
  173. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint2D(AMFVariantStruct* pDest, const AMFFloatPoint2D* value);
  174. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint3D(AMFVariantStruct* pDest, const AMFFloatPoint3D* value);
  175. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatVector4D(AMFVariantStruct* pDest, const AMFFloatVector4D* value);
  176. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRate(AMFVariantStruct* pDest, const AMFRate* value);
  177. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRatio(AMFVariantStruct* pDest, const AMFRatio* value);
  178. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignColor(AMFVariantStruct* pDest, const AMFColor* value);
  179. #if defined(__cplusplus)
  180. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRect(AMFVariantStruct* pDest, const AMFRect& value);
  181. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignSize(AMFVariantStruct* pDest, const AMFSize& value);
  182. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignPoint(AMFVariantStruct* pDest, const AMFPoint& value);
  183. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatSize(AMFVariantStruct* pDest, const AMFFloatSize& value);
  184. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint2D(AMFVariantStruct* pDest, const AMFFloatPoint2D& value);
  185. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint3D(AMFVariantStruct* pDest, const AMFFloatPoint3D& value);
  186. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatVector4D(AMFVariantStruct* pDest, const AMFFloatVector4D& value);
  187. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRate(AMFVariantStruct* pDest, const AMFRate& value);
  188. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRatio(AMFVariantStruct* pDest, const AMFRatio& value);
  189. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignColor(AMFVariantStruct* pDest, const AMFColor& value);
  190. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantChangeType(AMFVariantStruct* pDest, const AMFVariantStruct* pSrc, AMF_VARIANT_TYPE newType);
  191. #endif
  192. static AMF_INLINE char* AMF_CDECL_CALL AMFVariantDuplicateString(const char* from);
  193. static AMF_INLINE void AMF_CDECL_CALL AMFVariantFreeString(char* from);
  194. static AMF_INLINE wchar_t* AMF_CDECL_CALL AMFVariantDuplicateWString(const wchar_t* from);
  195. static AMF_INLINE void AMF_CDECL_CALL AMFVariantFreeWString(wchar_t* from);
  196. #if defined(__cplusplus)
  197. //----------------------------------------------------------------------------------------------
  198. // AMF_INLINE Variant helper class
  199. //----------------------------------------------------------------------------------------------
  200. class AMFVariant : public AMFVariantStruct
  201. {
  202. public:
  203. class String;
  204. class WString;
  205. public:
  206. AMFVariant() { AMFVariantInit(this); }
  207. explicit AMFVariant(const AMFVariantStruct& other) { AMFVariantInit(this); AMFVariantCopy(this, const_cast<AMFVariantStruct*>(&other)); }
  208. explicit AMFVariant(const AMFVariantStruct* pOther);
  209. template<typename T>
  210. explicit AMFVariant(const AMFInterfacePtr_T<T>& pValue);
  211. AMFVariant(const AMFVariant& other) { AMFVariantInit(this); AMFVariantCopy(this, const_cast<AMFVariantStruct*>(static_cast<const AMFVariantStruct*>(&other))); }
  212. explicit AMF_INLINE AMFVariant(amf_bool value) { AMFVariantInit(this); AMFVariantAssignBool(this, value); }
  213. explicit AMF_INLINE AMFVariant(amf_int64 value) { AMFVariantInit(this); AMFVariantAssignInt64(this, value); }
  214. explicit AMF_INLINE AMFVariant(amf_uint64 value) { AMFVariantInit(this); AMFVariantAssignInt64(this, (amf_int64)value); }
  215. explicit AMF_INLINE AMFVariant(amf_int32 value) { AMFVariantInit(this); AMFVariantAssignInt64(this, value); }
  216. explicit AMF_INLINE AMFVariant(amf_uint32 value) { AMFVariantInit(this); AMFVariantAssignInt64(this, value); }
  217. explicit AMF_INLINE AMFVariant(amf_double value) { AMFVariantInit(this); AMFVariantAssignDouble(this, value); }
  218. explicit AMF_INLINE AMFVariant(amf_float value) { AMFVariantInit(this); AMFVariantAssignFloat(this, value); }
  219. explicit AMF_INLINE AMFVariant(const AMFRect & value) { AMFVariantInit(this); AMFVariantAssignRect(this, &value); }
  220. explicit AMF_INLINE AMFVariant(const AMFSize & value) { AMFVariantInit(this); AMFVariantAssignSize(this, &value); }
  221. explicit AMF_INLINE AMFVariant(const AMFPoint& value) { AMFVariantInit(this); AMFVariantAssignPoint(this, &value); }
  222. explicit AMF_INLINE AMFVariant(const AMFFloatSize& value) { AMFVariantInit(this); AMFVariantAssignFloatSize(this, &value); }
  223. explicit AMF_INLINE AMFVariant(const AMFFloatPoint2D& value) { AMFVariantInit(this); AMFVariantAssignFloatPoint2D(this, &value); }
  224. explicit AMF_INLINE AMFVariant(const AMFFloatPoint3D& value) { AMFVariantInit(this); AMFVariantAssignFloatPoint3D(this, &value); }
  225. explicit AMF_INLINE AMFVariant(const AMFFloatVector4D& value) { AMFVariantInit(this); AMFVariantAssignFloatVector4D(this, &value); }
  226. explicit AMF_INLINE AMFVariant(const AMFRate & value) { AMFVariantInit(this); AMFVariantAssignRate(this, &value); }
  227. explicit AMF_INLINE AMFVariant(const AMFRatio& value) { AMFVariantInit(this); AMFVariantAssignRatio(this, &value); }
  228. explicit AMF_INLINE AMFVariant(const AMFColor& value) { AMFVariantInit(this); AMFVariantAssignColor(this, &value); }
  229. explicit AMF_INLINE AMFVariant(const char* value) { AMFVariantInit(this); AMFVariantAssignString(this, value); }
  230. explicit AMF_INLINE AMFVariant(const wchar_t* value) { AMFVariantInit(this); AMFVariantAssignWString(this, value); }
  231. explicit AMF_INLINE AMFVariant(AMFInterface* pValue) { AMFVariantInit(this); AMFVariantAssignInterface(this, pValue); }
  232. ~AMFVariant() { AMFVariantClear(this); }
  233. AMFVariant& operator=(const AMFVariantStruct& other);
  234. AMFVariant& operator=(const AMFVariantStruct* pOther);
  235. AMFVariant& operator=(const AMFVariant& other);
  236. AMFVariant& operator=(amf_bool value) { AMFVariantAssignBool(this, value); return *this;}
  237. AMFVariant& operator=(amf_int64 value) { AMFVariantAssignInt64(this, value); return *this;}
  238. AMFVariant& operator=(amf_uint64 value) { AMFVariantAssignInt64(this, (amf_int64)value); return *this;}
  239. AMFVariant& operator=(amf_int32 value) { AMFVariantAssignInt64(this, value); return *this;}
  240. AMFVariant& operator=(amf_uint32 value) { AMFVariantAssignInt64(this, value); return *this;}
  241. AMFVariant& operator=(amf_double value) { AMFVariantAssignDouble(this, value); return *this;}
  242. AMFVariant& operator=(amf_float value) { AMFVariantAssignFloat(this, value); return *this; }
  243. AMFVariant& operator=(const AMFRect & value) { AMFVariantAssignRect(this, &value); return *this;}
  244. AMFVariant& operator=(const AMFSize & value) { AMFVariantAssignSize(this, &value); return *this;}
  245. AMFVariant& operator=(const AMFPoint& value) { AMFVariantAssignPoint(this, &value); return *this;}
  246. AMFVariant& operator=(const AMFFloatSize& value) { AMFVariantAssignFloatSize(this, &value); return *this; }
  247. AMFVariant& operator=(const AMFFloatPoint2D& value) { AMFVariantAssignFloatPoint2D(this, &value); return *this; }
  248. AMFVariant& operator=(const AMFFloatPoint3D& value) { AMFVariantAssignFloatPoint3D(this, &value); return *this; }
  249. AMFVariant& operator=(const AMFFloatVector4D& value) { AMFVariantAssignFloatVector4D(this, &value); return *this; }
  250. AMFVariant& operator=(const AMFRate & value) { AMFVariantAssignRate(this, &value); return *this;}
  251. AMFVariant& operator=(const AMFRatio& value) { AMFVariantAssignRatio(this, &value); return *this;}
  252. AMFVariant& operator=(const AMFColor& value) { AMFVariantAssignColor(this, &value); return *this;}
  253. AMFVariant& operator=(const char* value) { AMFVariantAssignString(this, value); return *this;}
  254. AMFVariant& operator=(const wchar_t* value) { AMFVariantAssignWString(this, value); return *this;}
  255. AMFVariant& operator=(AMFInterface* value) { AMFVariantAssignInterface(this, value); return *this;}
  256. template<typename T> AMFVariant& operator=(const AMFInterfacePtr_T<T>& value);
  257. operator amf_bool() const { return ToBool(); }
  258. operator amf_int64() const { return ToInt64(); }
  259. operator amf_uint64() const { return ToUInt64(); }
  260. operator amf_int32() const { return ToInt32(); }
  261. operator amf_uint32() const { return ToUInt32(); }
  262. operator amf_double() const { return ToDouble(); }
  263. operator amf_float() const { return ToFloat(); }
  264. operator AMFRect () const { return ToRect (); }
  265. operator AMFSize () const { return ToSize (); }
  266. operator AMFPoint() const { return ToPoint(); }
  267. operator AMFFloatSize() const { return ToFloatSize(); }
  268. operator AMFFloatPoint2D() const { return ToFloatPoint2D(); }
  269. operator AMFFloatPoint3D() const { return ToFloatPoint3D(); }
  270. operator AMFFloatVector4D() const { return ToFloatVector4D(); }
  271. operator AMFRate () const { return ToRate (); }
  272. operator AMFRatio() const { return ToRatio(); }
  273. operator AMFColor() const { return ToColor(); }
  274. operator AMFInterface*() const { return ToInterface(); }
  275. AMF_INLINE amf_bool ToBool() const { return Empty() ? false : GetValue<amf_bool, AMF_VARIANT_BOOL>(AMFVariantGetBool); }
  276. AMF_INLINE amf_int64 ToInt64() const { return Empty() ? 0 : GetValue<amf_int64, AMF_VARIANT_INT64>(AMFVariantGetInt64); }
  277. AMF_INLINE amf_uint64 ToUInt64() const { return Empty() ? 0 : GetValue<amf_uint64, AMF_VARIANT_INT64>(AMFVariantGetInt64); }
  278. AMF_INLINE amf_int32 ToInt32() const { return Empty() ? 0 : GetValue<amf_int32, AMF_VARIANT_INT64>(AMFVariantGetInt64); }
  279. AMF_INLINE amf_uint32 ToUInt32() const { return Empty() ? 0 : GetValue<amf_uint32, AMF_VARIANT_INT64>(AMFVariantGetInt64); }
  280. AMF_INLINE amf_double ToDouble() const { return Empty() ? 0 : GetValue<amf_double, AMF_VARIANT_DOUBLE>(AMFVariantGetDouble); }
  281. AMF_INLINE amf_float ToFloat() const { return Empty() ? 0 : GetValue<amf_float, AMF_VARIANT_FLOAT>(AMFVariantGetFloat); }
  282. AMF_INLINE AMFRect ToRect () const { return Empty() ? AMFRect() : GetValue<AMFRect, AMF_VARIANT_RECT>(AMFVariantGetRect); }
  283. AMF_INLINE AMFSize ToSize () const { return Empty() ? AMFSize() : GetValue<AMFSize, AMF_VARIANT_SIZE>(AMFVariantGetSize); }
  284. AMF_INLINE AMFPoint ToPoint() const { return Empty() ? AMFPoint() : GetValue<AMFPoint, AMF_VARIANT_POINT>(AMFVariantGetPoint); }
  285. AMF_INLINE AMFFloatSize ToFloatSize() const { return Empty() ? AMFFloatSize() : GetValue<AMFFloatSize, AMF_VARIANT_FLOAT_SIZE>(AMFVariantGetFloatSize); }
  286. AMF_INLINE AMFFloatPoint2D ToFloatPoint2D() const { return Empty() ? AMFFloatPoint2D() : GetValue<AMFFloatPoint2D, AMF_VARIANT_FLOAT_POINT2D>(AMFVariantGetFloatPoint2D); }
  287. AMF_INLINE AMFFloatPoint3D ToFloatPoint3D() const { return Empty() ? AMFFloatPoint3D() : GetValue<AMFFloatPoint3D, AMF_VARIANT_FLOAT_POINT3D>(AMFVariantGetFloatPoint3D); }
  288. AMF_INLINE AMFFloatVector4D ToFloatVector4D() const { return Empty() ? AMFFloatVector4D() : GetValue<AMFFloatVector4D, AMF_VARIANT_FLOAT_VECTOR4D>(AMFVariantGetFloatVector4D); }
  289. AMF_INLINE AMFRate ToRate () const { return Empty() ? AMFRate() : GetValue<AMFRate, AMF_VARIANT_RATE>(AMFVariantGetRate); }
  290. AMF_INLINE AMFRatio ToRatio() const { return Empty() ? AMFRatio() : GetValue<AMFRatio, AMF_VARIANT_RATIO>(AMFVariantGetRatio); }
  291. AMF_INLINE AMFColor ToColor() const { return Empty() ? AMFColor() : GetValue<AMFColor, AMF_VARIANT_COLOR>(AMFVariantGetColor); }
  292. AMF_INLINE AMFInterface* ToInterface() const { return AMFVariantGetType(this) == AMF_VARIANT_INTERFACE ? this->pInterface : NULL; }
  293. AMF_INLINE String ToString() const;
  294. AMF_INLINE WString ToWString() const;
  295. bool operator==(const AMFVariantStruct& other) const;
  296. bool operator==(const AMFVariantStruct* pOther) const;
  297. bool operator!=(const AMFVariantStruct& other) const;
  298. bool operator!=(const AMFVariantStruct* pOther) const;
  299. void Clear() { AMFVariantClear(this); }
  300. void Attach(AMFVariantStruct& variant);
  301. AMFVariantStruct Detach();
  302. AMFVariantStruct& GetVariant();
  303. void ChangeType(AMF_VARIANT_TYPE type, const AMFVariant* pSrc = NULL);
  304. bool Empty() const;
  305. private:
  306. template<class ReturnType, AMF_VARIANT_TYPE variantType, typename Getter>
  307. ReturnType GetValue(Getter getter) const;
  308. };
  309. //----------------------------------------------------------------------------------------------
  310. // helper String class
  311. //----------------------------------------------------------------------------------------------
  312. class AMFVariant::String
  313. {
  314. friend class AMFVariant;
  315. private:
  316. void Free()
  317. {
  318. if (m_Str != NULL)
  319. {
  320. AMFVariantFreeString(m_Str);
  321. m_Str = NULL;
  322. }
  323. }
  324. public:
  325. String() :m_Str(NULL){}
  326. String(const char* str) : m_Str(NULL)
  327. {
  328. m_Str = AMFVariantDuplicateString(str);
  329. }
  330. String(const String& p_other) : m_Str(NULL)
  331. {
  332. operator=(p_other);
  333. }
  334. #if (__cplusplus == 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X) || (_MSC_VER >= 1600)
  335. #pragma warning (push)
  336. #pragma warning (disable : 26439) //This kind of function may not throw. Declare it 'noexcept'.
  337. String(String&& p_other) : m_Str(NULL)
  338. {
  339. operator=(p_other);
  340. }
  341. #endif
  342. ~String()
  343. {
  344. Free();
  345. }
  346. char& operator[](size_t index)
  347. {
  348. if (index >= size())
  349. {
  350. resize(index);
  351. }
  352. return m_Str[index];
  353. }
  354. String& operator=(const String& p_other)
  355. {
  356. Free();
  357. m_Str = AMFVariantDuplicateString(p_other.m_Str);
  358. return *this;
  359. }
  360. #if (__cplusplus == 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X) || (_MSC_VER >= 1600)
  361. String& operator=(String&& p_other)
  362. {
  363. Free();
  364. m_Str = p_other.m_Str;
  365. p_other.m_Str = NULL; // Transfer the ownership
  366. return *this;
  367. }
  368. #endif
  369. bool operator==(const String& p_other) const
  370. {
  371. if (m_Str == NULL && p_other.m_Str == NULL)
  372. {
  373. return true;
  374. }
  375. else if ((m_Str == NULL && p_other.m_Str != NULL) || (m_Str != NULL && p_other.m_Str == NULL))
  376. {
  377. return false;
  378. }
  379. return strcmp(c_str(), p_other.c_str()) == 0;
  380. }
  381. const char* c_str() const { return m_Str; }
  382. size_t size() const
  383. {
  384. if(m_Str == NULL)
  385. {
  386. return 0;
  387. }
  388. return (size_t)strlen(m_Str);
  389. }
  390. AMF_INLINE size_t length() const { return size(); }
  391. void resize(size_t sizeAlloc)
  392. {
  393. if(sizeAlloc == 0)
  394. {
  395. Free();
  396. return;
  397. }
  398. char* str = (char*)amf_variant_alloc(sizeof(char)*(sizeAlloc + 1));
  399. if(m_Str != NULL)
  400. {
  401. size_t copySize = sizeAlloc;
  402. if(copySize > size())
  403. {
  404. copySize = size();
  405. }
  406. memcpy(str, m_Str, copySize * sizeof(char));
  407. Free();
  408. str[sizeAlloc] = 0;
  409. }
  410. m_Str = str;
  411. }
  412. private:
  413. char* m_Str;
  414. };
  415. //----------------------------------------------------------------------------------------------
  416. // helper WString class
  417. //----------------------------------------------------------------------------------------------
  418. class AMFVariant::WString
  419. {
  420. friend class AMFVariant;
  421. private:
  422. void Free()
  423. {
  424. if (m_Str != NULL)
  425. {
  426. AMFVariantFreeWString(m_Str);
  427. m_Str = NULL;
  428. }
  429. }
  430. public:
  431. WString() :m_Str(NULL){}
  432. WString(const wchar_t* str) : m_Str(NULL)
  433. {
  434. m_Str = AMFVariantDuplicateWString(str);
  435. }
  436. WString(const WString& p_other) : m_Str(NULL)
  437. {
  438. operator=(p_other);
  439. }
  440. #if (__cplusplus == 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X) || (_MSC_VER >= 1600)
  441. WString(WString&& p_other) : m_Str(NULL)
  442. {
  443. operator=(p_other);
  444. }
  445. #endif
  446. ~WString()
  447. {
  448. Free();
  449. }
  450. WString& operator=(const WString& p_other)
  451. {
  452. Free();
  453. m_Str = AMFVariantDuplicateWString(p_other.m_Str);
  454. return *this;
  455. }
  456. #if (__cplusplus == 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X) || (_MSC_VER >= 1600)
  457. WString& operator=(WString&& p_other)
  458. {
  459. Free();
  460. m_Str = p_other.m_Str;
  461. p_other.m_Str = NULL; // Transfer the ownership
  462. return *this;
  463. }
  464. #pragma warning (pop)
  465. #endif
  466. wchar_t& operator[](size_t index)
  467. {
  468. if (index >= size())
  469. {
  470. resize(index);
  471. }
  472. return m_Str[index];
  473. }
  474. bool operator==(const WString& p_other) const
  475. {
  476. if (m_Str == NULL && p_other.m_Str == NULL)
  477. {
  478. return true;
  479. }
  480. else if ((m_Str == NULL && p_other.m_Str != NULL) || (m_Str != NULL && p_other.m_Str == NULL))
  481. {
  482. return false;
  483. }
  484. return wcscmp(c_str(), p_other.c_str()) == 0;
  485. }
  486. const wchar_t* c_str() const { return m_Str; }
  487. size_t size() const
  488. {
  489. if(m_Str == NULL)
  490. {
  491. return 0;
  492. }
  493. return (size_t)wcslen(m_Str);
  494. }
  495. AMF_INLINE size_t length() const { return size(); }
  496. void resize(size_t sizeAlloc)
  497. {
  498. if(sizeAlloc == 0)
  499. {
  500. Free();
  501. return;
  502. }
  503. wchar_t* str = (wchar_t*)amf_variant_alloc(sizeof(wchar_t)*(sizeAlloc + 1));
  504. if(m_Str != NULL)
  505. {
  506. size_t copySize = sizeAlloc;
  507. if(copySize > size())
  508. {
  509. copySize = size();
  510. }
  511. memcpy(str, m_Str, copySize * sizeof(wchar_t));
  512. Free();
  513. str[sizeAlloc] = 0;
  514. }
  515. m_Str = str;
  516. }
  517. private:
  518. wchar_t* m_Str;
  519. };
  520. //-------------------------------------------------------------------------------------------------
  521. AMFVariant::String AMFVariant::ToString() const
  522. {
  523. String temp = GetValue<String, AMF_VARIANT_STRING>(AMFVariantGetString);
  524. return String(temp.c_str());
  525. }
  526. //-------------------------------------------------------------------------------------------------
  527. AMFVariant::WString AMFVariant::ToWString() const
  528. {
  529. WString temp = GetValue<WString, AMF_VARIANT_WSTRING>(AMFVariantGetWString);
  530. return WString(temp.c_str());
  531. }
  532. #endif // defined(__cplusplus)
  533. //----------------------------------------------------------------------------------------------
  534. // AMF_INLINE implementation of helper functions
  535. //----------------------------------------------------------------------------------------------
  536. #define AMF_VARIANT_RETURN_IF_INVALID_POINTER(p) \
  537. { \
  538. if(p == NULL) \
  539. { \
  540. return AMF_INVALID_POINTER; \
  541. } \
  542. }
  543. //-------------------------------------------------------------------------------------------------
  544. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantInit(AMFVariantStruct* pVariant)
  545. {
  546. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pVariant);
  547. pVariant->type = AMF_VARIANT_EMPTY;
  548. return AMF_OK;
  549. }
  550. //-------------------------------------------------------------------------------------------------
  551. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantClear(AMFVariantStruct* pVariant)
  552. {
  553. AMF_RESULT errRet = AMF_OK;
  554. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pVariant);
  555. switch(AMFVariantGetType(pVariant))
  556. {
  557. case AMF_VARIANT_STRING:
  558. amf_variant_free(AMFVariantString(pVariant));
  559. pVariant->type = AMF_VARIANT_EMPTY;
  560. break;
  561. case AMF_VARIANT_WSTRING:
  562. amf_variant_free(AMFVariantWString(pVariant));
  563. pVariant->type = AMF_VARIANT_EMPTY;
  564. break;
  565. case AMF_VARIANT_INTERFACE:
  566. if(AMFVariantInterface(pVariant) != NULL)
  567. {
  568. #if defined(__cplusplus)
  569. AMFVariantInterface(pVariant)->Release();
  570. #else
  571. AMFVariantInterface(pVariant)->pVtbl->Release(AMFVariantInterface(pVariant));
  572. #endif
  573. AMFVariantInterface(pVariant) = NULL;
  574. }
  575. pVariant->type = AMF_VARIANT_EMPTY;
  576. break;
  577. default:
  578. pVariant->type = AMF_VARIANT_EMPTY;
  579. break;
  580. }
  581. return errRet;
  582. }
  583. //-------------------------------------------------------------------------------------------------
  584. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantCompare(const AMFVariantStruct* pFirst, const AMFVariantStruct* pSecond, amf_bool* bEqual)
  585. {
  586. AMF_RESULT errRet = AMF_OK;
  587. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pFirst);
  588. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pSecond);
  589. if(pFirst == pSecond)
  590. {
  591. *bEqual = true;
  592. }
  593. else if(AMFVariantGetType(pFirst) != AMFVariantGetType(pSecond))
  594. {
  595. *bEqual = false;
  596. }
  597. else
  598. {
  599. switch(AMFVariantGetType(pFirst))
  600. {
  601. case AMF_VARIANT_EMPTY:
  602. *bEqual = true;
  603. break;
  604. case AMF_VARIANT_BOOL:
  605. *bEqual = AMFVariantGetBool(pFirst) == AMFVariantBool(pSecond);
  606. break;
  607. case AMF_VARIANT_INT64:
  608. *bEqual = AMFVariantGetInt64(pFirst) == AMFVariantInt64(pSecond);
  609. break;
  610. case AMF_VARIANT_DOUBLE:
  611. *bEqual = AMFVariantGetDouble(pFirst) == AMFVariantDouble(pSecond);
  612. break;
  613. case AMF_VARIANT_FLOAT:
  614. *bEqual = AMFVariantGetFloat(pFirst) == AMFVariantFloat(pSecond);
  615. break;
  616. case AMF_VARIANT_RECT:
  617. #if defined(__cplusplus)
  618. *bEqual = AMFVariantGetRect(pFirst) == AMFVariantGetRect(pSecond);
  619. #else
  620. *bEqual = memcmp(&pFirst->rectValue, &pSecond->rectValue, sizeof(AMFRect)) == 0;
  621. #endif
  622. break;
  623. case AMF_VARIANT_SIZE:
  624. #if defined(__cplusplus)
  625. *bEqual = AMFVariantGetSize(pFirst) == AMFVariantGetSize(pSecond);
  626. #else
  627. *bEqual = memcmp(&pFirst->sizeValue, &pSecond->sizeValue, sizeof(AMFSize)) == 0;
  628. #endif
  629. break;
  630. case AMF_VARIANT_POINT:
  631. #if defined(__cplusplus)
  632. *bEqual = AMFVariantGetPoint(pFirst) == AMFVariantGetPoint(pSecond);
  633. #else
  634. *bEqual = memcmp(&pFirst->pointValue, &pSecond->pointValue, sizeof(AMFPoint)) == 0;
  635. #endif
  636. break;
  637. case AMF_VARIANT_FLOAT_SIZE:
  638. #if defined(__cplusplus)
  639. *bEqual = AMFVariantGetFloatSize(pFirst) == AMFVariantGetFloatSize(pSecond);
  640. #else
  641. *bEqual = memcmp(&pFirst->floatSizeValue, &pSecond->floatSizeValue, sizeof(AMFFloatPoint2D)) == 0;
  642. #endif
  643. break;
  644. case AMF_VARIANT_FLOAT_POINT2D:
  645. #if defined(__cplusplus)
  646. *bEqual = AMFVariantGetFloatPoint2D(pFirst) == AMFVariantGetFloatPoint2D(pSecond);
  647. #else
  648. *bEqual = memcmp(&pFirst->floatPoint2DValue, &pSecond->floatPoint2DValue, sizeof(AMFFloatPoint2D)) == 0;
  649. #endif
  650. break;
  651. case AMF_VARIANT_FLOAT_POINT3D:
  652. #if defined(__cplusplus)
  653. *bEqual = AMFVariantGetFloatPoint3D(pFirst) == AMFVariantGetFloatPoint3D(pSecond);
  654. #else
  655. *bEqual = memcmp(&pFirst->floatPoint3DValue, &pSecond->floatPoint3DValue, sizeof(AMFFloatPoint3D)) == 0;
  656. #endif
  657. break;
  658. case AMF_VARIANT_FLOAT_VECTOR4D:
  659. #if defined(__cplusplus)
  660. *bEqual = AMFVariantGetFloatVector4D(pFirst) == AMFVariantGetFloatVector4D(pSecond);
  661. #else
  662. *bEqual = memcmp(&pFirst->floatVector4DValue, &pSecond->floatVector4DValue, sizeof(AMFFloatPoint3D)) == 0;
  663. #endif
  664. break;
  665. case AMF_VARIANT_RATE:
  666. #if defined(__cplusplus)
  667. *bEqual = AMFVariantGetRate(pFirst) == AMFVariantGetRate(pSecond);
  668. #else
  669. *bEqual = memcmp(&pFirst->rateValue, &pSecond->rateValue, sizeof(AMFRate)) == 0;
  670. #endif
  671. break;
  672. case AMF_VARIANT_RATIO:
  673. #if defined(__cplusplus)
  674. *bEqual = AMFVariantGetRatio(pFirst) == AMFVariantGetRatio(pSecond);
  675. #else
  676. *bEqual = memcmp(&pFirst->ratioValue, &pSecond->ratioValue, sizeof(AMFRatio)) == 0;
  677. #endif
  678. break;
  679. case AMF_VARIANT_COLOR:
  680. #if defined(__cplusplus)
  681. *bEqual = AMFVariantGetColor(pFirst) == AMFVariantGetColor(pSecond);
  682. #else
  683. *bEqual = memcmp(&pFirst->colorValue, &pSecond->colorValue, sizeof(AMFColor)) == 0;
  684. #endif
  685. break;
  686. case AMF_VARIANT_STRING:
  687. *bEqual = strcmp(AMFVariantString(pFirst), AMFVariantString(pSecond)) == 0;
  688. break;
  689. case AMF_VARIANT_WSTRING:
  690. *bEqual = wcscmp(AMFVariantWString(pFirst), AMFVariantWString(pSecond)) == 0;
  691. break;
  692. case AMF_VARIANT_INTERFACE:
  693. *bEqual = AMFVariantInterface(pFirst) == AMFVariantInterface(pSecond);
  694. break;
  695. default:
  696. errRet = AMF_INVALID_ARG;
  697. break;
  698. }
  699. }
  700. return errRet;
  701. }
  702. //-------------------------------------------------------------------------------------------------
  703. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantCopy(AMFVariantStruct* pDest, const AMFVariantStruct* pSrc)
  704. {
  705. AMF_RESULT errRet = AMF_OK;
  706. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  707. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pSrc);
  708. if(pDest != pSrc)
  709. {
  710. switch(AMFVariantGetType(pSrc))
  711. {
  712. case AMF_VARIANT_EMPTY:
  713. errRet = AMFVariantInit(pDest);
  714. break;
  715. case AMF_VARIANT_BOOL:
  716. errRet = AMFVariantAssignBool(pDest, AMFVariantBool(pSrc));
  717. break;
  718. case AMF_VARIANT_INT64:
  719. errRet = AMFVariantAssignInt64(pDest, AMFVariantInt64(pSrc));
  720. break;
  721. case AMF_VARIANT_DOUBLE:
  722. errRet = AMFVariantAssignDouble(pDest, AMFVariantDouble(pSrc));
  723. break;
  724. case AMF_VARIANT_FLOAT:
  725. errRet = AMFVariantAssignFloat(pDest, AMFVariantFloat(pSrc));
  726. break;
  727. case AMF_VARIANT_RECT:
  728. errRet = AMFVariantAssignRect(pDest, &pSrc->rectValue);
  729. break;
  730. case AMF_VARIANT_SIZE:
  731. errRet = AMFVariantAssignSize(pDest, &pSrc->sizeValue);
  732. break;
  733. case AMF_VARIANT_POINT:
  734. errRet = AMFVariantAssignPoint(pDest, &pSrc->pointValue);
  735. break;
  736. case AMF_VARIANT_FLOAT_SIZE:
  737. errRet = AMFVariantAssignFloatSize(pDest, &pSrc->floatSizeValue);
  738. break;
  739. case AMF_VARIANT_FLOAT_POINT2D:
  740. errRet = AMFVariantAssignFloatPoint2D(pDest, &pSrc->floatPoint2DValue);
  741. break;
  742. case AMF_VARIANT_FLOAT_POINT3D:
  743. errRet = AMFVariantAssignFloatPoint3D(pDest, &pSrc->floatPoint3DValue);
  744. break;
  745. case AMF_VARIANT_FLOAT_VECTOR4D:
  746. errRet = AMFVariantAssignFloatVector4D(pDest, &pSrc->floatVector4DValue);
  747. break;
  748. case AMF_VARIANT_RATE:
  749. errRet = AMFVariantAssignRate(pDest, &pSrc->rateValue);
  750. break;
  751. case AMF_VARIANT_RATIO:
  752. errRet = AMFVariantAssignRatio(pDest, &pSrc->ratioValue);
  753. break;
  754. case AMF_VARIANT_COLOR:
  755. errRet = AMFVariantAssignColor(pDest, &pSrc->colorValue);
  756. break;
  757. case AMF_VARIANT_STRING:
  758. errRet = AMFVariantAssignString(pDest, AMFVariantString(pSrc));
  759. break;
  760. case AMF_VARIANT_WSTRING:
  761. errRet = AMFVariantAssignWString(pDest, AMFVariantWString(pSrc));
  762. break;
  763. case AMF_VARIANT_INTERFACE:
  764. errRet = AMFVariantAssignInterface(pDest, AMFVariantInterface(pSrc));
  765. break;
  766. default:
  767. errRet = AMF_INVALID_ARG;
  768. break;
  769. }
  770. }
  771. return errRet;
  772. }
  773. #define AMFVariantTypeEmpty AMF_VARIANT_EMPTY
  774. #define AMFVariantTypeBool AMF_VARIANT_BOOL
  775. #define AMFVariantTypeInt64 AMF_VARIANT_INT64
  776. #define AMFVariantTypeDouble AMF_VARIANT_DOUBLE
  777. #define AMFVariantTypeFloat AMF_VARIANT_FLOAT
  778. #define AMFVariantTypeRect AMF_VARIANT_RECT
  779. #define AMFVariantTypeSize AMF_VARIANT_SIZE
  780. #define AMFVariantTypePoint AMF_VARIANT_POINT
  781. #define AMFVariantTypeFloatPoint2D AMF_VARIANT_FLOAT_POINT2D
  782. #define AMFVariantTypeFloatPoint3D AMF_VARIANT_FLOAT_POINT3D
  783. #define AMFVariantTypeFloatVector4D AMF_VARIANT_FLOAT_VECTOR4D
  784. #define AMFVariantTypeRate AMF_VARIANT_RATE
  785. #define AMFVariantTypeRatio AMF_VARIANT_RATIO
  786. #define AMFVariantTypeColor AMF_VARIANT_COLOR
  787. #define AMFVariantTypeString AMF_VARIANT_STRING
  788. #define AMFVariantTypeWString AMF_VARIANT_WSTRING
  789. #define AMFVariantTypeInterface AMF_VARIANT_INTERFACE
  790. #if defined(__cplusplus)
  791. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignString(AMFVariantStruct* pDest, const AMFVariant::String& value)
  792. {
  793. return AMFVariantAssignString(pDest, value.c_str());
  794. }
  795. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignWString(AMFVariantStruct* pDest, const AMFVariant::WString& value)
  796. {
  797. return AMFVariantAssignWString(pDest, value.c_str());
  798. }
  799. static AMF_INLINE amf_bool AMFConvertEmptyToBool(void*, AMF_RESULT& res) { res = AMF_OK; return false; }
  800. static AMF_INLINE amf_int64 AMFConvertEmptyToInt64(void*, AMF_RESULT& res) {res = AMF_OK; return 0; }
  801. static AMF_INLINE amf_double AMFConvertEmptyToDouble(void*, AMF_RESULT& res) {res = AMF_OK; return 0; }
  802. static AMF_INLINE amf_float AMFConvertEmptyToFloat(void*, AMF_RESULT& res) { res = AMF_OK; return 0; }
  803. static AMF_INLINE AMFVariant::String AMFConvertEmptyToString(void*, AMF_RESULT& res) {res = AMF_OK; return ""; }
  804. static AMF_INLINE AMFVariant::WString AMFConvertEmptyToWString(void*, AMF_RESULT& res) {res = AMF_OK; return L""; }
  805. static AMF_INLINE amf_int64 AMFConvertBoolToInt64(bool value, AMF_RESULT& res){res = AMF_OK; return value ? 1 : 0;}
  806. static AMF_INLINE amf_double AMFConvertBoolToDouble(bool value, AMF_RESULT& res){res = AMF_OK; return value ? 1.0 : 0.0;}
  807. static AMF_INLINE amf_float AMFConvertBoolToFloat(bool value, AMF_RESULT& res) { res = AMF_OK; return value ? 1.0f : 0.0f; }
  808. static AMF_INLINE AMFVariant::String AMFConvertBoolToString(bool value, AMF_RESULT& res){res = AMF_OK; return value ? "true" : "false";}
  809. static AMF_INLINE AMFVariant::WString AMFConvertBoolToWString(bool value, AMF_RESULT& res){res = AMF_OK; return value ? L"true" : L"false";}
  810. static AMF_INLINE bool AMFConvertInt64ToBool(amf_int64 value, AMF_RESULT& res){res = AMF_OK;return value != 0;}
  811. static AMF_INLINE amf_double AMFConvertInt64ToDouble(amf_int64 value, AMF_RESULT& res){res = AMF_OK;return (amf_double)value;}
  812. static AMF_INLINE amf_float AMFConvertInt64ToFloat(amf_int64 value, AMF_RESULT& res) { res = AMF_OK; return (amf_float)value; }
  813. static AMF_INLINE AMFVariant::String AMFConvertInt64ToString(amf_int64 value, AMF_RESULT& res)
  814. {
  815. res = AMF_OK;
  816. char buff[0xFF];
  817. sprintf(buff, "%" AMFPRId64, (long long)value);
  818. return buff;
  819. }
  820. static AMF_INLINE AMFVariant::WString AMFConvertInt64ToWString(amf_int64 value, AMF_RESULT& res)
  821. {
  822. res = AMF_OK;
  823. wchar_t buff[0xFF];
  824. swprintf(buff, 0xFF, L"%" LPRId64, (long long)value);
  825. return buff;
  826. }
  827. static AMF_INLINE bool AMFConvertDoubleToBool(amf_double value, AMF_RESULT& res){res = AMF_OK;return value != 0;}
  828. static AMF_INLINE bool AMFConvertFloatToBool(amf_float value, AMF_RESULT& res) { res = AMF_OK; return value != 0; }
  829. static AMF_INLINE amf_int64 AMFConvertDoubleToInt64(amf_double value, AMF_RESULT& res){res = AMF_OK;return amf_int64(value);}
  830. static AMF_INLINE amf_int64 AMFConvertFloatToInt64(amf_float value, AMF_RESULT& res) { res = AMF_OK; return amf_int64(value); }
  831. static AMF_INLINE AMFVariant::String AMFConvertDoubleToString(amf_double value, AMF_RESULT& res)
  832. {
  833. res = AMF_OK;
  834. char buff[0xFF];
  835. sprintf(buff, "%lf", value);
  836. return buff;
  837. }
  838. static AMF_INLINE AMFVariant::String AMFConvertFloatToString(amf_float value, AMF_RESULT& res)
  839. {
  840. res = AMF_OK;
  841. char buff[0xFF];
  842. sprintf(buff, "%f", value);
  843. return buff;
  844. }
  845. static AMF_INLINE AMFVariant::WString AMFConvertDoubleToWString(amf_double value, AMF_RESULT& res)
  846. {
  847. res = AMF_OK;
  848. wchar_t buff[0xFF];
  849. swprintf(buff, 0xFF, L"%lf", value);
  850. return buff;
  851. }
  852. static AMF_INLINE AMFVariant::WString AMFConvertFloatToWString(amf_float value, AMF_RESULT& res)
  853. {
  854. res = AMF_OK;
  855. wchar_t buff[0xFF];
  856. swprintf(buff, 0xFF, L"%f", value);
  857. return buff;
  858. }
  859. static AMF_INLINE bool AMFConvertStringToBool(const AMFVariant::String& value, AMF_RESULT& res)
  860. {
  861. res = AMF_OK;
  862. AMFVariant::String tmp = value;
  863. if(( tmp == "true") || ( tmp == "True") || ( tmp == "TRUE") || ( tmp == "1") )
  864. {
  865. return true;
  866. }
  867. else
  868. {
  869. if(( tmp == "false") || ( tmp == "False") || ( tmp == "FALSE") || ( tmp == "0") )
  870. {
  871. return false;
  872. }
  873. }
  874. res = AMF_INVALID_ARG;
  875. return false;
  876. }
  877. static AMF_INLINE amf_int64 AMFConvertStringToInt64(const AMFVariant::String& value, AMF_RESULT& res)
  878. {
  879. res = AMF_OK;
  880. long long tmp = 0;
  881. int readElements = 0;
  882. if(value.size() > 2 && ( value.c_str()[0] == '0') && ( value.c_str()[1] == 'x') )
  883. {
  884. readElements = sscanf(value.c_str(), "0x%" AMFPRIx64, &tmp);
  885. }
  886. else if(value.size() > 0)
  887. {
  888. readElements = sscanf(value.c_str(), "%" AMFPRId64, &tmp);
  889. }
  890. if(readElements)
  891. {
  892. return tmp;
  893. }
  894. res = AMF_INVALID_ARG;
  895. return 0;
  896. }
  897. static AMF_INLINE amf_double AMFConvertStringToDouble(const AMFVariant::String& value, AMF_RESULT& res)
  898. {
  899. res = AMF_OK;
  900. amf_double tmp = 0;
  901. int readElements = 0;
  902. if(value.size() > 0)
  903. {
  904. readElements = sscanf(value.c_str(), "%lf", &tmp);
  905. }
  906. if(readElements)
  907. {
  908. return tmp;
  909. }
  910. res = AMF_INVALID_ARG;
  911. return 0;
  912. }
  913. static AMF_INLINE amf_float AMFConvertStringToFloat(const AMFVariant::String& value, AMF_RESULT& res)
  914. {
  915. res = AMF_OK;
  916. amf_float tmp = 0;
  917. int readElements = 0;
  918. if (value.size() > 0)
  919. {
  920. readElements = sscanf(value.c_str(), "%f", &tmp);
  921. }
  922. if (readElements)
  923. {
  924. return tmp;
  925. }
  926. res = AMF_INVALID_ARG;
  927. return 0;
  928. }
  929. static AMF_INLINE AMFVariant::WString AMFConvertStringToWString(const AMFVariant::String& value, AMF_RESULT& res)
  930. {
  931. res = AMF_OK;
  932. // return amf_from_utf8_to_unicode(value);
  933. AMFVariant::WString result;
  934. if(0 == value.size())
  935. {
  936. return result;
  937. }
  938. const char* pUtf8Buff = value.c_str();
  939. #if defined(_WIN32)
  940. _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
  941. int UnicodeBuffSize = ::MultiByteToWideChar(CP_UTF8, 0, pUtf8Buff, -1, NULL, 0);
  942. if(0 == UnicodeBuffSize)
  943. {
  944. return result;
  945. }
  946. UnicodeBuffSize += 8; // get some extra space
  947. result.resize(UnicodeBuffSize);
  948. UnicodeBuffSize = ::MultiByteToWideChar(CP_UTF8, 0, pUtf8Buff, -1, (LPWSTR)result.c_str(), UnicodeBuffSize);
  949. UnicodeBuffSize--;
  950. #elif defined(__ANDROID__)
  951. // on android mbstowcs cannot be used to define length
  952. char* old_locale = setlocale(LC_CTYPE, "en_US.UTF8");
  953. mbstate_t mbs;
  954. mbrlen(NULL, 0, &mbs);
  955. int len = value.size();
  956. const char* pt = pUtf8Buff;
  957. int UnicodeBuffSize = 0;
  958. while(len > 0)
  959. {
  960. size_t length = mbrlen (pt, len, &mbs); //MM TODO Android always return 1
  961. if((length == 0) || (length > len))
  962. {
  963. break;
  964. }
  965. UnicodeBuffSize++;
  966. len -= length;
  967. pt += length;
  968. }
  969. UnicodeBuffSize += 8; // get some extra space
  970. result.resize(UnicodeBuffSize);
  971. mbrlen (NULL, 0, &mbs);
  972. len = value.size();
  973. pt = pUtf8Buff;
  974. UnicodeBuffSize = 0;
  975. while(len > 0)
  976. {
  977. size_t length = mbrlen (pt, len, &mbs);
  978. if((length == 0) || (length > len))
  979. {
  980. break;
  981. }
  982. mbrtowc(&((wchar_t*)(result.c_str()))[UnicodeBuffSize], pt, length, &mbs); //MM TODO Android always return 1 char
  983. UnicodeBuffSize++;
  984. len -= length;
  985. pt += length;
  986. }
  987. setlocale(LC_CTYPE, old_locale);
  988. #else
  989. char* old_locale = setlocale(LC_CTYPE, "en_US.UTF8");
  990. size_t UnicodeBuffSize = mbstowcs(NULL, pUtf8Buff, 0);
  991. if(0 == UnicodeBuffSize)
  992. {
  993. return result;
  994. }
  995. UnicodeBuffSize += 8; // get some extra space
  996. result.resize(UnicodeBuffSize);
  997. UnicodeBuffSize = mbstowcs((wchar_t*)result.c_str(), pUtf8Buff, UnicodeBuffSize + 1);
  998. setlocale(LC_CTYPE, old_locale);
  999. #endif
  1000. result.resize(UnicodeBuffSize);
  1001. return result;
  1002. }
  1003. static AMF_INLINE AMFVariant::String AMFConvertWStringToString(const AMFVariant::WString& value, AMF_RESULT& res)
  1004. {
  1005. res = AMF_OK;
  1006. // return amf_from_unicode_to_utf8(value);
  1007. AMFVariant::String result;
  1008. if(0 == value.size())
  1009. {
  1010. return result;
  1011. }
  1012. const wchar_t* pwBuff = value.c_str();
  1013. #if defined(_WIN32)
  1014. _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
  1015. int Utf8BuffSize = ::WideCharToMultiByte(CP_UTF8, 0, pwBuff, -1, NULL, 0, NULL, NULL);
  1016. if(0 == Utf8BuffSize)
  1017. {
  1018. return result;
  1019. }
  1020. Utf8BuffSize += 8; // get some extra space
  1021. result.resize(Utf8BuffSize);
  1022. Utf8BuffSize = ::WideCharToMultiByte(CP_UTF8, 0, pwBuff, -1, (LPSTR)result.c_str(), Utf8BuffSize, NULL, NULL);
  1023. Utf8BuffSize--;
  1024. #elif defined(__ANDROID__)
  1025. char* old_locale = setlocale(LC_CTYPE, "en_US.UTF8");
  1026. int Utf8BuffSize = value.length();
  1027. if(0 == Utf8BuffSize)
  1028. {
  1029. return result;
  1030. }
  1031. Utf8BuffSize += 8; // get some extra space
  1032. result.resize(Utf8BuffSize);
  1033. mbstate_t mbs;
  1034. mbrlen(NULL, 0, &mbs);
  1035. Utf8BuffSize = 0;
  1036. for( int i = 0; i < value.length(); i++)
  1037. {
  1038. //MM TODO Android - not implemented
  1039. //int written = wcrtomb(&result[Utf8BuffSize], pwBuff[i], &mbs);
  1040. ((char*)(result.c_str()))[Utf8BuffSize] = (char)(pwBuff[i]);
  1041. int written = 1;
  1042. // temp replacement
  1043. Utf8BuffSize += written;
  1044. }
  1045. setlocale(LC_CTYPE, old_locale);
  1046. #else
  1047. char* old_locale = setlocale(LC_CTYPE, "en_US.UTF8");
  1048. size_t Utf8BuffSize = wcstombs(NULL, pwBuff, 0);
  1049. if(0 == Utf8BuffSize)
  1050. {
  1051. return result;
  1052. }
  1053. Utf8BuffSize += 8; // get some extra space
  1054. result.resize(Utf8BuffSize);
  1055. Utf8BuffSize = wcstombs((char*)result.c_str(), pwBuff, Utf8BuffSize + 1);
  1056. setlocale(LC_CTYPE, old_locale);
  1057. #endif
  1058. result.resize(Utf8BuffSize);
  1059. return result;
  1060. }
  1061. static AMF_INLINE bool AMFConvertWStringToBool(const AMFVariant::WString& value, AMF_RESULT& res)
  1062. {
  1063. return AMFConvertStringToBool(AMFConvertWStringToString(value, res), res);
  1064. }
  1065. static AMF_INLINE amf_int64 AMFConvertWStringToInt64(const AMFVariant::WString& value, AMF_RESULT& res)
  1066. {
  1067. return AMFConvertStringToInt64(AMFConvertWStringToString(value, res), res);
  1068. }
  1069. static AMF_INLINE amf_double AMFConvertWStringToDouble(const AMFVariant::WString& value, AMF_RESULT& res)
  1070. {
  1071. return AMFConvertStringToDouble(AMFConvertWStringToString(value, res), res);
  1072. }
  1073. static AMF_INLINE amf_float AMFConvertWStringToFloat(const AMFVariant::WString& value, AMF_RESULT& res)
  1074. {
  1075. return AMFConvertStringToFloat(AMFConvertWStringToString(value, res), res);
  1076. }
  1077. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertRectToString(const AMFRect& value, AMF_RESULT& res)
  1078. {
  1079. res = AMF_OK;
  1080. char buff[0xFF];
  1081. sprintf(buff, "%d,%d,%d,%d", value.left, value.top, value.right, value.bottom);
  1082. return buff;
  1083. }
  1084. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertSizeToString(const AMFSize& value, AMF_RESULT& res)
  1085. {
  1086. res = AMF_OK;
  1087. char buff[0xFF];
  1088. sprintf(buff, "%d,%d", value.width, value.height);
  1089. return buff;
  1090. }
  1091. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertPointToString(const AMFPoint& value, AMF_RESULT& res)
  1092. {
  1093. res = AMF_OK;
  1094. char buff[0xFF];
  1095. sprintf(buff, "%d,%d", value.x, value.y);
  1096. return buff;
  1097. }
  1098. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertFloatSizeToString(const AMFFloatSize& value, AMF_RESULT& res)
  1099. {
  1100. res = AMF_OK;
  1101. char buff[0xFF];
  1102. sprintf(buff, "%f,%f", value.width, value.height);
  1103. return buff;
  1104. }
  1105. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertFloatPoint2DToString(const AMFFloatPoint2D& value, AMF_RESULT& res)
  1106. {
  1107. res = AMF_OK;
  1108. char buff[0xFF];
  1109. sprintf(buff, "%f,%f", value.x, value.y);
  1110. return buff;
  1111. }
  1112. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertFloatPoint3DToString(const AMFFloatPoint3D& value, AMF_RESULT& res)
  1113. {
  1114. res = AMF_OK;
  1115. char buff[0xFF];
  1116. sprintf(buff, "%f,%f,%f", value.x, value.y, value.z);
  1117. return buff;
  1118. }
  1119. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertFloatVector4DToString(const AMFFloatVector4D& value, AMF_RESULT& res)
  1120. {
  1121. res = AMF_OK;
  1122. char buff[0xFF];
  1123. sprintf(buff, "%f,%f,%f,%f", value.x, value.y, value.z, value.w);
  1124. return buff;
  1125. }
  1126. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertRateToString(const AMFRate& value, AMF_RESULT& res)
  1127. {
  1128. res = AMF_OK;
  1129. char buff[0xFF];
  1130. sprintf(buff, "%u,%u", value.num, value.den);
  1131. return buff;
  1132. }
  1133. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertRatioToString(const AMFRatio& value, AMF_RESULT& res)
  1134. {
  1135. res = AMF_OK;
  1136. char buff[0xFF];
  1137. sprintf(buff, "%u,%u", value.num, value.den);
  1138. return buff;
  1139. }
  1140. static AMF_INLINE AMFVariant::String AMF_STD_CALL AMFConvertColorToString(const AMFColor& value, AMF_RESULT& res)
  1141. {
  1142. res = AMF_OK;
  1143. char buff[0xFF];
  1144. sprintf(buff, "%u,%u,%u,%u", value.r, value.g, value.b, value.a);
  1145. return buff;
  1146. }
  1147. static AMF_INLINE AMFRect AMF_STD_CALL AMFConvertStringToRect(const AMFVariant::String& value, AMF_RESULT& res)
  1148. {
  1149. res = AMF_OK;
  1150. AMFRect tmp = {};
  1151. int readElements = 0;
  1152. if(value.size() > 0)
  1153. {
  1154. readElements = sscanf(value.c_str(), "%d,%d,%d,%d", &tmp.left, &tmp.top, &tmp.right, &tmp.bottom);
  1155. }
  1156. if(readElements)
  1157. {
  1158. return tmp;
  1159. }
  1160. res = AMF_INVALID_ARG;
  1161. return tmp;
  1162. }
  1163. static AMF_INLINE AMFSize AMF_STD_CALL AMFConvertStringToSize(const AMFVariant::String& value, AMF_RESULT& res)
  1164. {
  1165. res = AMF_OK;
  1166. AMFSize tmp = {};
  1167. int readElements = 0;
  1168. if(value.size() > 0)
  1169. {
  1170. if(strchr(value.c_str(), ',') != nullptr)
  1171. {
  1172. readElements = sscanf(value.c_str(), "%d,%d", &tmp.width, &tmp.height);
  1173. }
  1174. else if (strchr(value.c_str(), 'x') != nullptr)
  1175. {
  1176. readElements = sscanf(value.c_str(), "%dx%d", &tmp.width, &tmp.height);
  1177. }
  1178. }
  1179. if(readElements)
  1180. {
  1181. return tmp;
  1182. }
  1183. res = AMF_INVALID_ARG;
  1184. return tmp;
  1185. }
  1186. static AMF_INLINE AMFPoint AMF_STD_CALL AMFConvertStringToPoint(const AMFVariant::String& value, AMF_RESULT& res)
  1187. {
  1188. res = AMF_OK;
  1189. AMFPoint tmp = {};
  1190. int readElements = 0;
  1191. if(value.size() > 0)
  1192. {
  1193. readElements = sscanf(value.c_str(), "%d,%d", &tmp.x, &tmp.y);
  1194. }
  1195. if(readElements)
  1196. {
  1197. return tmp;
  1198. }
  1199. res = AMF_INVALID_ARG;
  1200. return tmp;
  1201. }
  1202. static AMF_INLINE AMFFloatSize AMF_STD_CALL AMFConvertStringToFloatSize(const AMFVariant::String& value, AMF_RESULT& res)
  1203. {
  1204. res = AMF_OK;
  1205. AMFFloatSize tmp = {};
  1206. int readElements = 0;
  1207. if (value.size() > 0)
  1208. {
  1209. readElements = sscanf(value.c_str(), "%f,%f", &tmp.width, &tmp.height);
  1210. }
  1211. if (readElements)
  1212. {
  1213. return tmp;
  1214. }
  1215. res = AMF_INVALID_ARG;
  1216. return tmp;
  1217. }
  1218. static AMF_INLINE AMFFloatPoint2D AMF_STD_CALL AMFConvertStringToFloatPoint2D(const AMFVariant::String& value, AMF_RESULT& res)
  1219. {
  1220. res = AMF_OK;
  1221. AMFFloatPoint2D tmp = {};
  1222. int readElements = 0;
  1223. if (value.size() > 0)
  1224. {
  1225. readElements = sscanf(value.c_str(), "%f,%f", &tmp.x, &tmp.y);
  1226. }
  1227. if (readElements)
  1228. {
  1229. return tmp;
  1230. }
  1231. res = AMF_INVALID_ARG;
  1232. return tmp;
  1233. }
  1234. static AMF_INLINE AMFFloatPoint3D AMF_STD_CALL AMFConvertStringToFloatPoint3D(const AMFVariant::String& value, AMF_RESULT& res)
  1235. {
  1236. res = AMF_OK;
  1237. AMFFloatPoint3D tmp = {};
  1238. int readElements = 0;
  1239. if (value.size() > 0)
  1240. {
  1241. readElements = sscanf(value.c_str(), "%f,%f,%f", &tmp.x, &tmp.y, &tmp.z);
  1242. }
  1243. if (readElements)
  1244. {
  1245. return tmp;
  1246. }
  1247. res = AMF_INVALID_ARG;
  1248. return tmp;
  1249. }
  1250. static AMF_INLINE AMFFloatVector4D AMF_STD_CALL AMFConvertStringToFloatVector4D(const AMFVariant::String& value, AMF_RESULT& res)
  1251. {
  1252. res = AMF_OK;
  1253. AMFFloatVector4D tmp = {};
  1254. int readElements = 0;
  1255. if (value.size() > 0)
  1256. {
  1257. readElements = sscanf(value.c_str(), "%f,%f,%f,%f", &tmp.x, &tmp.y, &tmp.z, &tmp.w);
  1258. }
  1259. if (readElements)
  1260. {
  1261. return tmp;
  1262. }
  1263. res = AMF_INVALID_ARG;
  1264. return tmp;
  1265. }
  1266. static AMF_INLINE AMFRate AMF_STD_CALL AMFConvertStringToRate(const AMFVariant::String& value, AMF_RESULT& res)
  1267. {
  1268. res = AMF_OK;
  1269. AMFRate tmp = {};
  1270. int readElements = 0;
  1271. if(value.size() > 0)
  1272. {
  1273. readElements = sscanf(value.c_str(), "%u,%u", &tmp.num, &tmp.den);
  1274. }
  1275. if(readElements)
  1276. {
  1277. return tmp;
  1278. }
  1279. res = AMF_INVALID_ARG;
  1280. return tmp;
  1281. }
  1282. static AMF_INLINE AMFRatio AMF_STD_CALL AMFConvertStringToRatio(const AMFVariant::String& value, AMF_RESULT& res)
  1283. {
  1284. res = AMF_OK;
  1285. AMFRatio tmp = {};
  1286. int readElements = 0;
  1287. if(value.size() > 0)
  1288. {
  1289. readElements = sscanf(value.c_str(), "%u,%u", &tmp.num, &tmp.den);
  1290. }
  1291. if(readElements)
  1292. {
  1293. return tmp;
  1294. }
  1295. res = AMF_INVALID_ARG;
  1296. return tmp;
  1297. }
  1298. static AMF_INLINE AMFColor AMF_STD_CALL AMFConvertStringToColor(const AMFVariant::String& value, AMF_RESULT& res)
  1299. {
  1300. res = AMF_OK;
  1301. int readElements = 0;
  1302. amf_uint32 r = 0;
  1303. amf_uint32 g = 0;
  1304. amf_uint32 b = 0;
  1305. amf_uint32 a = 0;
  1306. if(value.size() > 0)
  1307. {
  1308. readElements = sscanf(value.c_str(), "%u,%u,%u,%u", &r, &g, &b, &a);
  1309. }
  1310. if(readElements)
  1311. {
  1312. return AMFConstructColor((amf_uint8)r, (amf_uint8)g, (amf_uint8)b, (amf_uint8)a);
  1313. }
  1314. res = AMF_INVALID_ARG;
  1315. return AMFConstructColor(0, 0, 0, 255);
  1316. }
  1317. ///////////////////////
  1318. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertRectToWString(const AMFRect& value, AMF_RESULT& res)
  1319. {
  1320. return AMFConvertStringToWString(AMFConvertRectToString(value, res), res);
  1321. }
  1322. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertSizeToWString(const AMFSize& value, AMF_RESULT& res)
  1323. {
  1324. return AMFConvertStringToWString(AMFConvertSizeToString(value, res), res);
  1325. }
  1326. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertPointToWString(const AMFPoint& value, AMF_RESULT& res)
  1327. {
  1328. return AMFConvertStringToWString(AMFConvertPointToString(value, res), res);
  1329. }
  1330. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertFloatSizeToWString(const AMFFloatSize& value, AMF_RESULT& res)
  1331. {
  1332. return AMFConvertStringToWString(AMFConvertFloatSizeToString(value, res), res);
  1333. }
  1334. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertFloatPoint2DToWString(const AMFFloatPoint2D& value, AMF_RESULT& res)
  1335. {
  1336. return AMFConvertStringToWString(AMFConvertFloatPoint2DToString(value, res), res);
  1337. }
  1338. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertFloatPoint3DToWString(const AMFFloatPoint3D& value, AMF_RESULT& res)
  1339. {
  1340. return AMFConvertStringToWString(AMFConvertFloatPoint3DToString(value, res), res);
  1341. }
  1342. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertFloatVector4DToWString(const AMFFloatVector4D& value, AMF_RESULT& res)
  1343. {
  1344. return AMFConvertStringToWString(AMFConvertFloatVector4DToString(value, res), res);
  1345. }
  1346. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertRateToWString(const AMFRate& value, AMF_RESULT& res)
  1347. {
  1348. return AMFConvertStringToWString(AMFConvertRateToString(value, res), res);
  1349. }
  1350. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertRatioToWString(const AMFRatio& value, AMF_RESULT& res)
  1351. {
  1352. return AMFConvertStringToWString(AMFConvertRatioToString(value, res), res);
  1353. }
  1354. static AMF_INLINE AMFVariant::WString AMF_STD_CALL AMFConvertColorToWString(const AMFColor& value, AMF_RESULT& res)
  1355. {
  1356. return AMFConvertStringToWString(AMFConvertColorToString(value, res), res);
  1357. }
  1358. static AMF_INLINE AMFRect AMF_STD_CALL AMFConvertWStringToRect(const AMFVariant::WString& value, AMF_RESULT& res)
  1359. {
  1360. return AMFConvertStringToRect(AMFConvertWStringToString(value, res), res);
  1361. }
  1362. static AMF_INLINE AMFSize AMF_STD_CALL AMFConvertWStringToSize(const AMFVariant::WString& value, AMF_RESULT& res)
  1363. {
  1364. return AMFConvertStringToSize(AMFConvertWStringToString(value, res), res);
  1365. }
  1366. static AMF_INLINE AMFPoint AMF_STD_CALL AMFConvertWStringToPoint(const AMFVariant::WString& value, AMF_RESULT& res)
  1367. {
  1368. return AMFConvertStringToPoint(AMFConvertWStringToString(value, res), res);
  1369. }
  1370. static AMF_INLINE AMFFloatSize AMF_STD_CALL AMFConvertWStringToFloatSize(const AMFVariant::WString& value, AMF_RESULT& res)
  1371. {
  1372. return AMFConvertStringToFloatSize(AMFConvertWStringToString(value, res), res);
  1373. }
  1374. static AMF_INLINE AMFFloatPoint2D AMF_STD_CALL AMFConvertWStringToFloatPoint2D(const AMFVariant::WString& value, AMF_RESULT& res)
  1375. {
  1376. return AMFConvertStringToFloatPoint2D(AMFConvertWStringToString(value, res), res);
  1377. }
  1378. static AMF_INLINE AMFFloatPoint3D AMF_STD_CALL AMFConvertWStringToFloatPoint3D(const AMFVariant::WString& value, AMF_RESULT& res)
  1379. {
  1380. return AMFConvertStringToFloatPoint3D(AMFConvertWStringToString(value, res), res);
  1381. }
  1382. static AMF_INLINE AMFFloatVector4D AMF_STD_CALL AMFConvertWStringToFloatVector4D(const AMFVariant::WString& value, AMF_RESULT& res)
  1383. {
  1384. return AMFConvertStringToFloatVector4D(AMFConvertWStringToString(value, res), res);
  1385. }
  1386. static AMF_INLINE AMFRate AMF_STD_CALL AMFConvertWStringToRate(const AMFVariant::WString& value, AMF_RESULT& res)
  1387. {
  1388. return AMFConvertStringToRate(AMFConvertWStringToString(value, res), res);
  1389. }
  1390. static AMF_INLINE AMFRatio AMF_STD_CALL AMFConvertWStringToRatio(const AMFVariant::WString& value, AMF_RESULT& res)
  1391. {
  1392. return AMFConvertStringToRatio(AMFConvertWStringToString(value, res), res);
  1393. }
  1394. static AMF_INLINE AMFColor AMF_STD_CALL AMFConvertWStringToColor(const AMFVariant::WString& value, AMF_RESULT& res)
  1395. {
  1396. return AMFConvertStringToColor(AMFConvertWStringToString(value, res), res);
  1397. }
  1398. //-------------------------------------------------------------------------------------------------
  1399. #define AMFConvertTool(srcType, dstType)\
  1400. if(AMFVariantGetType(pSrc) == AMFVariantType##srcType && newType == AMFVariantType##dstType)\
  1401. {\
  1402. AMF_RESULT res = AMF_OK;\
  1403. AMFVariantAssign##dstType(pDest, AMFConvert##srcType##To##dstType(AMFVariant##srcType(pSrc), res));\
  1404. return res;\
  1405. }\
  1406. //-------------------------------------------------------------------------------------------------
  1407. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantChangeType(AMFVariantStruct* pDest, const AMFVariantStruct* pSrc, AMF_VARIANT_TYPE newType)
  1408. {
  1409. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1410. if(pSrc == 0)
  1411. {
  1412. pSrc = pDest;
  1413. }
  1414. if(AMFVariantGetType(pSrc) == newType)
  1415. {
  1416. if(pDest == pSrc)
  1417. {
  1418. return AMF_OK;
  1419. }
  1420. return AMFVariantCopy(pDest, pSrc);
  1421. }
  1422. AMFVariantClear(pDest);
  1423. AMFConvertTool(Empty, Bool);
  1424. AMFConvertTool(Empty, Int64);
  1425. AMFConvertTool(Empty, Double);
  1426. AMFConvertTool(Empty, Float);
  1427. AMFConvertTool(Empty, String);
  1428. AMFConvertTool(Empty, WString);
  1429. AMFConvertTool(Bool, Int64);
  1430. AMFConvertTool(Bool, Double);
  1431. AMFConvertTool(Bool, Float);
  1432. AMFConvertTool(Bool, String);
  1433. AMFConvertTool(Bool, WString);
  1434. AMFConvertTool(Int64, Bool);
  1435. AMFConvertTool(Int64, Double);
  1436. AMFConvertTool(Int64, Float);
  1437. AMFConvertTool(Int64, String);
  1438. AMFConvertTool(Int64, WString);
  1439. AMFConvertTool(Double, Bool);
  1440. AMFConvertTool(Double, Int64);
  1441. AMFConvertTool(Double, String);
  1442. AMFConvertTool(Double, String);
  1443. AMFConvertTool(Float, Bool);
  1444. AMFConvertTool(Float, Int64);
  1445. AMFConvertTool(Float, String);
  1446. AMFConvertTool(Float, String);
  1447. AMFConvertTool(String, Bool);
  1448. AMFConvertTool(String, Int64);
  1449. AMFConvertTool(String, Double);
  1450. AMFConvertTool(String, Float);
  1451. AMFConvertTool(String, WString);
  1452. AMFConvertTool(WString, Bool);
  1453. AMFConvertTool(WString, Int64);
  1454. AMFConvertTool(WString, Double);
  1455. AMFConvertTool(WString, Float);
  1456. AMFConvertTool(WString, String);
  1457. AMFConvertTool(String, Rect);
  1458. AMFConvertTool(String, Size);
  1459. AMFConvertTool(String, Point);
  1460. AMFConvertTool(String, Rate);
  1461. AMFConvertTool(String, Ratio);
  1462. AMFConvertTool(String, Color);
  1463. AMFConvertTool(Rect , String);
  1464. AMFConvertTool(Size , String);
  1465. AMFConvertTool(Point, String);
  1466. AMFConvertTool(Rate , String);
  1467. AMFConvertTool(Ratio, String);
  1468. AMFConvertTool(Color, String);
  1469. AMFConvertTool(WString, Rect);
  1470. AMFConvertTool(WString, Size);
  1471. AMFConvertTool(WString, Point);
  1472. AMFConvertTool(WString, Rate);
  1473. AMFConvertTool(WString, Ratio);
  1474. AMFConvertTool(WString, Color);
  1475. AMFConvertTool(Rect , WString);
  1476. AMFConvertTool(Size , WString);
  1477. AMFConvertTool(Point, WString);
  1478. AMFConvertTool(Rate , WString);
  1479. AMFConvertTool(Ratio, WString);
  1480. AMFConvertTool(Color, WString);
  1481. return AMF_INVALID_ARG;
  1482. }
  1483. #endif // #if defined(__cplusplus)
  1484. //-------------------------------------------------------------------------------------------------
  1485. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignBool(AMFVariantStruct* pDest, amf_bool value)
  1486. {
  1487. AMF_RESULT errRet = AMF_OK;
  1488. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1489. errRet = AMFVariantInit(pDest);
  1490. if(errRet == AMF_OK)
  1491. {
  1492. pDest->type = AMF_VARIANT_BOOL;
  1493. AMFVariantBool(pDest) = value;
  1494. }
  1495. return errRet;
  1496. }
  1497. //-------------------------------------------------------------------------------------------------
  1498. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignInt64(AMFVariantStruct* pDest, amf_int64 value)
  1499. {
  1500. AMF_RESULT errRet = AMF_OK;
  1501. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1502. errRet = AMFVariantInit(pDest);
  1503. if(errRet == AMF_OK)
  1504. {
  1505. pDest->type = AMF_VARIANT_INT64;
  1506. AMFVariantInt64(pDest) = value;
  1507. }
  1508. return errRet;
  1509. }
  1510. //-------------------------------------------------------------------------------------------------
  1511. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignDouble(AMFVariantStruct* pDest, amf_double value)
  1512. {
  1513. AMF_RESULT errRet = AMF_OK;
  1514. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1515. errRet = AMFVariantInit(pDest);
  1516. if(errRet == AMF_OK)
  1517. {
  1518. pDest->type = AMF_VARIANT_DOUBLE;
  1519. AMFVariantDouble(pDest) = value;
  1520. }
  1521. return errRet;
  1522. }
  1523. //-------------------------------------------------------------------------------------------------
  1524. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloat(AMFVariantStruct* pDest, amf_float value)
  1525. {
  1526. AMF_RESULT errRet = AMF_OK;
  1527. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1528. errRet = AMFVariantInit(pDest);
  1529. if (errRet == AMF_OK)
  1530. {
  1531. pDest->type = AMF_VARIANT_FLOAT;
  1532. AMFVariantFloat(pDest) = value;
  1533. }
  1534. return errRet;
  1535. }
  1536. //-------------------------------------------------------------------------------------------------
  1537. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignString(AMFVariantStruct* pDest, const char* pValue)
  1538. {
  1539. AMF_RESULT errRet = AMF_OK;
  1540. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1541. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pValue);
  1542. errRet = AMFVariantInit(pDest);
  1543. if(errRet == AMF_OK)
  1544. {
  1545. const size_t size = (strlen(pValue) + 1);
  1546. pDest->type = AMF_VARIANT_STRING;
  1547. AMFVariantString(pDest) = (char*)amf_variant_alloc(size * sizeof(char));
  1548. if(AMFVariantString(pDest))
  1549. {
  1550. memcpy(AMFVariantString(pDest), pValue, size * sizeof(char));
  1551. }
  1552. else
  1553. {
  1554. errRet = AMF_OUT_OF_MEMORY;
  1555. }
  1556. }
  1557. return errRet;
  1558. }
  1559. //-------------------------------------------------------------------------------------------------
  1560. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignWString(AMFVariantStruct* pDest, const wchar_t* pValue)
  1561. {
  1562. AMF_RESULT errRet = AMF_OK;
  1563. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1564. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pValue);
  1565. errRet = AMFVariantInit(pDest);
  1566. if(errRet == AMF_OK)
  1567. {
  1568. const size_t size = (wcslen(pValue) + 1);
  1569. pDest->type = AMF_VARIANT_WSTRING;
  1570. AMFVariantWString(pDest) = (wchar_t*)amf_variant_alloc(size * sizeof(wchar_t));
  1571. if(AMFVariantWString(pDest))
  1572. {
  1573. memcpy(AMFVariantWString(pDest), pValue, size * sizeof(wchar_t));
  1574. }
  1575. else
  1576. {
  1577. errRet = AMF_OUT_OF_MEMORY;
  1578. }
  1579. }
  1580. return errRet;
  1581. }
  1582. //-------------------------------------------------------------------------------------------------
  1583. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignInterface(AMFVariantStruct* pDest, AMFInterface* pValue)
  1584. {
  1585. AMF_RESULT errRet = AMF_OK;
  1586. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1587. //AMF_VARIANT_RETURN_IF_INVALID_POINTER(pValue);//can be NULL
  1588. errRet = AMFVariantInit(pDest);
  1589. if(errRet == AMF_OK)
  1590. {
  1591. pDest->type = AMF_VARIANT_INTERFACE;
  1592. AMFVariantInterface(pDest) = pValue;
  1593. if(AMFVariantInterface(pDest))
  1594. {
  1595. #if defined(__cplusplus)
  1596. AMFVariantInterface(pDest)->Acquire();
  1597. #else
  1598. AMFVariantInterface(pDest)->pVtbl->Acquire(AMFVariantInterface(pDest));
  1599. #endif
  1600. }
  1601. }
  1602. return errRet;
  1603. }
  1604. //-------------------------------------------------------------------------------------------------
  1605. #if defined(__cplusplus)
  1606. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRect(AMFVariantStruct* pDest, const AMFRect& value)
  1607. {
  1608. return AMFVariantAssignRect(pDest, &value);
  1609. }
  1610. #endif
  1611. //-------------------------------------------------------------------------------------------------
  1612. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRect (AMFVariantStruct* pDest, const AMFRect* value)
  1613. {
  1614. AMF_RESULT errRet = AMF_OK;
  1615. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1616. errRet = AMFVariantInit(pDest);
  1617. if(errRet == AMF_OK)
  1618. {
  1619. pDest->type = AMF_VARIANT_RECT;
  1620. AMFVariantRect(pDest) = *value;
  1621. }
  1622. return errRet;
  1623. }
  1624. //-------------------------------------------------------------------------------------------------
  1625. #if defined(__cplusplus)
  1626. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignSize (AMFVariantStruct* pDest, const AMFSize& value)
  1627. {
  1628. return AMFVariantAssignSize (pDest, &value);
  1629. }
  1630. #endif
  1631. //-------------------------------------------------------------------------------------------------
  1632. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignSize (AMFVariantStruct* pDest, const AMFSize* value)
  1633. {
  1634. AMF_RESULT errRet = AMF_OK;
  1635. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1636. errRet = AMFVariantInit(pDest);
  1637. if(errRet == AMF_OK)
  1638. {
  1639. pDest->type = AMF_VARIANT_SIZE;
  1640. AMFVariantSize(pDest) = *value;
  1641. }
  1642. return errRet;
  1643. }
  1644. //-------------------------------------------------------------------------------------------------
  1645. #if defined(__cplusplus)
  1646. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignPoint(AMFVariantStruct* pDest, const AMFPoint& value)
  1647. {
  1648. return AMFVariantAssignPoint(pDest, &value);
  1649. }
  1650. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatSize(AMFVariantStruct* pDest, const AMFFloatSize& value)
  1651. {
  1652. return AMFVariantAssignFloatSize(pDest, &value);
  1653. }
  1654. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint2D(AMFVariantStruct* pDest, const AMFFloatPoint2D& value)
  1655. {
  1656. return AMFVariantAssignFloatPoint2D(pDest, &value);
  1657. }
  1658. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint3D(AMFVariantStruct* pDest, const AMFFloatPoint3D& value)
  1659. {
  1660. return AMFVariantAssignFloatPoint3D(pDest, &value);
  1661. }
  1662. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatVector4D(AMFVariantStruct* pDest, const AMFFloatVector4D& value)
  1663. {
  1664. return AMFVariantAssignFloatVector4D(pDest, &value);
  1665. }
  1666. #endif
  1667. //-------------------------------------------------------------------------------------------------
  1668. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignPoint(AMFVariantStruct* pDest, const AMFPoint* value)
  1669. {
  1670. AMF_RESULT errRet = AMF_OK;
  1671. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1672. errRet = AMFVariantInit(pDest);
  1673. if(errRet == AMF_OK)
  1674. {
  1675. pDest->type = AMF_VARIANT_POINT;
  1676. AMFVariantPoint(pDest) = *value;
  1677. }
  1678. return errRet;
  1679. }
  1680. //-------------------------------------------------------------------------------------------------
  1681. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatSize(AMFVariantStruct* pDest, const AMFFloatSize* value)
  1682. {
  1683. AMF_RESULT errRet = AMF_OK;
  1684. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1685. errRet = AMFVariantInit(pDest);
  1686. if (errRet == AMF_OK)
  1687. {
  1688. pDest->type = AMF_VARIANT_FLOAT_SIZE;
  1689. AMFVariantFloatSize(pDest) = *value;
  1690. }
  1691. return errRet;
  1692. }
  1693. //-------------------------------------------------------------------------------------------------
  1694. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint2D(AMFVariantStruct* pDest, const AMFFloatPoint2D* value)
  1695. {
  1696. AMF_RESULT errRet = AMF_OK;
  1697. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1698. errRet = AMFVariantInit(pDest);
  1699. if (errRet == AMF_OK)
  1700. {
  1701. pDest->type = AMF_VARIANT_FLOAT_POINT2D;
  1702. AMFVariantFloatPoint2D(pDest) = *value;
  1703. }
  1704. return errRet;
  1705. }
  1706. //-------------------------------------------------------------------------------------------------
  1707. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatPoint3D(AMFVariantStruct* pDest, const AMFFloatPoint3D* value)
  1708. {
  1709. AMF_RESULT errRet = AMF_OK;
  1710. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1711. errRet = AMFVariantInit(pDest);
  1712. if (errRet == AMF_OK)
  1713. {
  1714. pDest->type = AMF_VARIANT_FLOAT_POINT3D;
  1715. AMFVariantFloatPoint3D(pDest) = *value;
  1716. }
  1717. return errRet;
  1718. }
  1719. //-------------------------------------------------------------------------------------------------
  1720. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignFloatVector4D(AMFVariantStruct* pDest, const AMFFloatVector4D* value)
  1721. {
  1722. AMF_RESULT errRet = AMF_OK;
  1723. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1724. errRet = AMFVariantInit(pDest);
  1725. if (errRet == AMF_OK)
  1726. {
  1727. pDest->type = AMF_VARIANT_FLOAT_VECTOR4D;
  1728. AMFVariantFloatVector4D(pDest) = *value;
  1729. }
  1730. return errRet;
  1731. }
  1732. //-------------------------------------------------------------------------------------------------
  1733. #if defined(__cplusplus)
  1734. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRate (AMFVariantStruct* pDest, const AMFRate& value)
  1735. {
  1736. return AMFVariantAssignRate (pDest, &value);
  1737. }
  1738. #endif
  1739. //-------------------------------------------------------------------------------------------------
  1740. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRate (AMFVariantStruct* pDest, const AMFRate* value)
  1741. {
  1742. AMF_RESULT errRet = AMF_OK;
  1743. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1744. errRet = AMFVariantInit(pDest);
  1745. if(errRet == AMF_OK)
  1746. {
  1747. pDest->type = AMF_VARIANT_RATE;
  1748. AMFVariantRate(pDest) = *value;
  1749. }
  1750. return errRet;
  1751. }
  1752. //-------------------------------------------------------------------------------------------------
  1753. #if defined(__cplusplus)
  1754. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRatio(AMFVariantStruct* pDest, const AMFRatio& value)
  1755. {
  1756. return AMFVariantAssignRatio(pDest, &value);
  1757. }
  1758. #endif
  1759. //-------------------------------------------------------------------------------------------------
  1760. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignRatio(AMFVariantStruct* pDest, const AMFRatio* value)
  1761. {
  1762. AMF_RESULT errRet = AMF_OK;
  1763. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1764. errRet = AMFVariantInit(pDest);
  1765. if(errRet == AMF_OK)
  1766. {
  1767. pDest->type = AMF_VARIANT_RATIO;
  1768. AMFVariantRatio(pDest) = *value;
  1769. }
  1770. return errRet;
  1771. }
  1772. //-------------------------------------------------------------------------------------------------
  1773. #if defined(__cplusplus)
  1774. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignColor(AMFVariantStruct* pDest, const AMFColor& value)
  1775. {
  1776. return AMFVariantAssignColor(pDest, &value);
  1777. }
  1778. #endif
  1779. //-------------------------------------------------------------------------------------------------
  1780. static AMF_INLINE AMF_RESULT AMF_CDECL_CALL AMFVariantAssignColor(AMFVariantStruct* pDest, const AMFColor* value)
  1781. {
  1782. AMF_RESULT errRet = AMF_OK;
  1783. AMF_VARIANT_RETURN_IF_INVALID_POINTER(pDest);
  1784. errRet = AMFVariantInit(pDest);
  1785. if(errRet == AMF_OK)
  1786. {
  1787. pDest->type = AMF_VARIANT_COLOR;
  1788. AMFVariantColor(pDest) = *value;
  1789. }
  1790. return errRet;
  1791. }
  1792. //-------------------------------------------------------------------------------------------------
  1793. static AMF_INLINE char* AMF_CDECL_CALL AMFVariantDuplicateString(const char* from)
  1794. {
  1795. char* ret = 0;
  1796. if(from)
  1797. {
  1798. ret = (char*)amf_variant_alloc(sizeof(char)*(strlen(from) + 1));
  1799. if(ret)
  1800. {
  1801. strcpy(ret, from);
  1802. }
  1803. }
  1804. return ret;
  1805. }
  1806. //-------------------------------------------------------------------------------------------------
  1807. static AMF_INLINE void AMF_CDECL_CALL AMFVariantFreeString(char* from)
  1808. {
  1809. amf_variant_free(from);
  1810. }
  1811. //-------------------------------------------------------------------------------------------------
  1812. static AMF_INLINE wchar_t* AMF_CDECL_CALL AMFVariantDuplicateWString(const wchar_t* from)
  1813. {
  1814. wchar_t* ret = 0;
  1815. if(from)
  1816. {
  1817. ret = (wchar_t*)amf_variant_alloc(sizeof(wchar_t)*(wcslen(from) + 1));
  1818. if(ret)
  1819. {
  1820. wcscpy(ret, from);
  1821. }
  1822. }
  1823. return ret;
  1824. }
  1825. //-------------------------------------------------------------------------------------------------
  1826. static AMF_INLINE void AMF_CDECL_CALL AMFVariantFreeWString(wchar_t* from)
  1827. {
  1828. amf_variant_free(from);
  1829. }
  1830. //----------------------------------------------------------------------------------------------
  1831. // AMF_INLINE implementation of AMFVariant class
  1832. //----------------------------------------------------------------------------------------------
  1833. #if defined(__cplusplus)
  1834. AMF_INLINE AMFVariant::AMFVariant(const AMFVariantStruct* pOther)
  1835. {
  1836. AMFVariantInit(this);
  1837. if(pOther != NULL)
  1838. {
  1839. AMFVariantCopy(this, const_cast<AMFVariantStruct*>(pOther));
  1840. }
  1841. }
  1842. //-------------------------------------------------------------------------------------------------
  1843. template<typename T>
  1844. AMFVariant::AMFVariant(const AMFInterfacePtr_T<T>& pValue)
  1845. {
  1846. AMFVariantInit(this);
  1847. AMFVariantAssignInterface(this, pValue);
  1848. }
  1849. //-------------------------------------------------------------------------------------------------
  1850. template<class ReturnType, AMF_VARIANT_TYPE variantType, typename Getter>
  1851. ReturnType AMFVariant::GetValue(Getter getter) const
  1852. {
  1853. ReturnType str = ReturnType();
  1854. if(AMFVariantGetType(this) == variantType)
  1855. {
  1856. str = static_cast<ReturnType>(getter(this));
  1857. }
  1858. else
  1859. {
  1860. AMFVariant varDest;
  1861. varDest.ChangeType(variantType, this);
  1862. if(varDest.type != AMF_VARIANT_EMPTY)
  1863. {
  1864. str = static_cast<ReturnType>(getter(&varDest));
  1865. }
  1866. }
  1867. return str;
  1868. }
  1869. //-------------------------------------------------------------------------------------------------
  1870. AMF_INLINE AMFVariant& AMFVariant::operator=(const AMFVariantStruct& other)
  1871. {
  1872. AMFVariantClear(this);
  1873. AMFVariantCopy(this, const_cast<AMFVariantStruct*>(&other));
  1874. return *this;
  1875. }
  1876. //-------------------------------------------------------------------------------------------------
  1877. AMF_INLINE AMFVariant& AMFVariant::operator=(const AMFVariantStruct* pOther)
  1878. {
  1879. if(pOther != NULL)
  1880. {
  1881. AMFVariantClear(this);
  1882. AMFVariantCopy(this, const_cast<AMFVariantStruct*>(pOther));
  1883. }
  1884. return *this;
  1885. }
  1886. //-------------------------------------------------------------------------------------------------
  1887. AMF_INLINE AMFVariant& AMFVariant::operator=(const AMFVariant& other)
  1888. {
  1889. AMFVariantClear(this);
  1890. AMFVariantCopy(this,
  1891. const_cast<AMFVariantStruct*>(static_cast<const AMFVariantStruct*>(&other)));
  1892. return *this;
  1893. }
  1894. //-------------------------------------------------------------------------------------------------
  1895. template<typename T>
  1896. AMFVariant& AMFVariant::operator=(const AMFInterfacePtr_T<T>& value)
  1897. {
  1898. AMFVariantClear(this);
  1899. AMFVariantAssignInterface(this, value);
  1900. return *this;
  1901. }
  1902. //-------------------------------------------------------------------------------------------------
  1903. AMF_INLINE bool AMFVariant::operator==(const AMFVariantStruct& other) const
  1904. {
  1905. return *this == &other;
  1906. }
  1907. //-------------------------------------------------------------------------------------------------
  1908. AMF_INLINE bool AMFVariant::operator==(const AMFVariantStruct* pOther) const
  1909. {
  1910. //TODO: double check
  1911. amf_bool ret = false;
  1912. if(pOther == NULL)
  1913. {
  1914. ret = false;
  1915. }
  1916. else
  1917. {
  1918. AMFVariantCompare(this, pOther, &ret);
  1919. }
  1920. return ret;
  1921. }
  1922. //-------------------------------------------------------------------------------------------------
  1923. AMF_INLINE bool AMFVariant::operator!=(const AMFVariantStruct& other) const
  1924. {
  1925. return !(*this == &other);
  1926. }
  1927. //-------------------------------------------------------------------------------------------------
  1928. AMF_INLINE bool AMFVariant::operator!=(const AMFVariantStruct* pOther) const
  1929. {
  1930. return !(*this == pOther);
  1931. }
  1932. //-------------------------------------------------------------------------------------------------
  1933. AMF_INLINE void AMFVariant::Attach(AMFVariantStruct& variant)
  1934. {
  1935. Clear();
  1936. memcpy(this, &variant, sizeof(variant));
  1937. AMFVariantGetType(&variant) = AMF_VARIANT_EMPTY;
  1938. }
  1939. //-------------------------------------------------------------------------------------------------
  1940. AMF_INLINE AMFVariantStruct AMFVariant::Detach()
  1941. {
  1942. AMFVariantStruct varResult = *this;
  1943. AMFVariantGetType(this) = AMF_VARIANT_EMPTY;
  1944. return varResult;
  1945. }
  1946. //-------------------------------------------------------------------------------------------------
  1947. AMF_INLINE AMFVariantStruct& AMFVariant::GetVariant()
  1948. {
  1949. return *static_cast<AMFVariantStruct*>(this);
  1950. }
  1951. //-------------------------------------------------------------------------------------------------
  1952. AMF_INLINE void AMFVariant::ChangeType(AMF_VARIANT_TYPE newType, const AMFVariant* pSrc)
  1953. {
  1954. AMFVariantChangeType(this, pSrc, newType);
  1955. }
  1956. //-------------------------------------------------------------------------------------------------
  1957. AMF_INLINE bool AMFVariant::Empty() const
  1958. {
  1959. return type == AMF_VARIANT_EMPTY;
  1960. }
  1961. //-------------------------------------------------------------------------------------------------
  1962. #endif // #if defined(__cplusplus)
  1963. #if defined(__cplusplus)
  1964. } //namespace amf
  1965. #endif
  1966. #endif //#ifndef AMF_Variant_h