yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#ifndef SLANG_COMPILER_CORE_JSON_NATIVE_H 2#define SLANG_COMPILER_CORE_JSON_NATIVE_H 3 4#include "slang-com-helper.h" 5#include "slang-com-ptr.h" 6#include "slang-json-value.h" 7#include "slang.h" 8 9namespace Slang 10{ 11 12struct JSONToNativeConverter 13{ 14SlangResult convert (const JSONValue & value ,const RttiInfo * rttiInfo ,void * out ); 15template < typename T > 16SlangResult convert (const JSONValue & value ,T * in ) 17 { 18return convert (value ,GetRttiInfo < T > ::get (),( void * )in); 19} 20 21template < typename T > 22SlangResult convertArrayToStruct ( const JSONValue & value, T * in) 23{ 24return convertArrayToStruct (value, GetRttiInfo < T > :: get (), ( void * )in); 25} 26SlangResult convertArrayToStruct ( const JSONValue & value, const RttiInfo * rttiInfo, void * out); 27 28JSONToNativeConverter (JSONContainer * container, RttiTypeFuncsMap * typeMap, DiagnosticSink * sink) 29: m_container (container), m_typeMap (typeMap), m_sink (sink) 30{ 31} 32 33protected : 34static Index _getFieldCount ( const StructRttiInfo * structRttiInfo); 35static Index _findFieldIndex ( 36const StructRttiInfo * structRttiInfo, 37const UnownedStringSlice & fieldName); 38 39SlangResult _structToNative ( 40const ConstArrayView < JSONKeyValue >& pairs, 41const StructRttiInfo * structRttiInfo, 42void * out, 43Index & outFieldCount); 44 45DiagnosticSink * m_sink; 46RttiTypeFuncsMap * m_typeMap; 47JSONContainer * m_container; 48}; 49 50struct NativeToJSONConverter 51{ 52SlangResult convert ( const RttiInfo * rttiInfo, const void * in, JSONValue & out); 53 54template < typename T > 55SlangResult convert ( T * in, JSONValue & out) 56{ 57return convert ( GetRttiInfo < T > :: get (), ( const void * )in, out ); 58} 59 60SlangResult convertStructToArray ( const RttiInfo * rttiInfo, const void * in, JSONValue & out); 61template < typename T > 62SlangResult convertStructToArray ( T * in, JSONValue & out) 63{ 64return convertStructToArray (GetRttiInfo < T > :: get (), ( const void * )in, out); 65} 66 67NativeToJSONConverter (JSONContainer * container, RttiTypeFuncsMap * typeMap, DiagnosticSink * sink) 68: m_container (container), m_typeMap (typeMap), m_sink (sink) 69{ 70} 71 72protected : 73SlangResult _structToJSON ( 74const StructRttiInfo * structRttiInfo, 75const void * src, 76List < JSONKeyValue >& outPairs); 77 78DiagnosticSink * m_sink; 79RttiTypeFuncsMap * m_typeMap; 80JSONContainer * m_container; 81}; 82 83struct JSONNativeUtil 84{ 85static RttiTypeFuncsMap getTypeFuncsMap (); 86}; 87 88} // namespace Slang 89 90#endif // SLANG_COMPILER_CORE_JSON_NATIVE_H