33#include < csp/python/InitHelper.h>
44#include < csp/python/PyObjectPtr.h>
55#include < csp/python/PyStruct.h>
6+ #include < csp/python/PyStructList.hi>
67#include < csp/python/PyStructToJson.h>
7-
88#include < unordered_set>
99#include < type_traits>
1010
@@ -395,8 +395,10 @@ PyTypeObject PyStructMeta::PyType = {
395395
396396
397397// PyStruct
398- PyObject * getattr_ ( const StructField* field, const Struct * struct_ )
398+ PyObject * getattr_ ( const StructField * field, const Struct * struct_ )
399399{
400+ assert ( field -> type () -> type () != CspType::Type::ARRAY );
401+
400402 PyObject *v = switchCspType ( field -> type (), [ field, struct_ ]( auto tag )
401403 {
402404 using CType = typename decltype (tag)::type;
@@ -407,6 +409,21 @@ PyObject * getattr_( const StructField* field, const Struct * struct_ )
407409 return v;
408410}
409411
412+ PyObject * getarrayattr_ ( const StructField * field, const PyStruct * pystruct )
413+ {
414+ assert ( field -> type () -> type () == CspType::Type::ARRAY );
415+
416+ const CspArrayType * arrayType = static_cast <const CspArrayType *>( field -> type ().get () );
417+ PyObject *v = ArraySubTypeSwitch::invoke ( arrayType -> elemType (), [ field, pystruct ]( auto tag )
418+ {
419+ using StorageT = typename CspType::Type::toCArrayStorageType<typename decltype (tag)::type>::type;
420+ using ArrayT = typename StructField::upcast<std::vector<StorageT>>::type;
421+ auto * typedField = static_cast <const ArrayT *>( field );
422+ return toPython ( typedField -> value ( pystruct -> struct_.get () ), *field -> type (), pystruct );
423+ } );
424+ return v;
425+ }
426+
410427PyObject * PyStruct::getattr ( PyObject * attr )
411428{
412429 auto * field = structMeta () -> field ( attr );
@@ -424,7 +441,9 @@ PyObject * PyStruct::getattr( PyObject * attr )
424441 return nullptr ;
425442 }
426443
427- return getattr_ ( field, ( const Struct *)struct_.get () );
444+ if ( field -> type () -> type () == CspType::Type::ARRAY )
445+ return getarrayattr_ ( field, this );
446+ return getattr_ ( field, ( const Struct * ) struct_.get () );
428447}
429448
430449void PyStruct::setattr ( Struct * s, PyObject * attr, PyObject * value )
@@ -997,4 +1016,24 @@ PyTypeObject PyStruct::PyType = {
9971016REGISTER_TYPE_INIT ( &PyStructMeta::PyType, " PyStructMeta" )
9981017REGISTER_TYPE_INIT ( &PyStruct::PyType, " PyStruct" )
9991018
1019+ // Instantiate all templates for PyStructList class
1020+ template struct PyStructList <bool >;
1021+ template struct PyStructList <int8_t >;
1022+ template struct PyStructList <uint8_t >;
1023+ template struct PyStructList <int16_t >;
1024+ template struct PyStructList <uint16_t >;
1025+ template struct PyStructList <int32_t >;
1026+ template struct PyStructList <uint32_t >;
1027+ template struct PyStructList <int64_t >;
1028+ template struct PyStructList <uint64_t >;
1029+ template struct PyStructList <double >;
1030+ template struct PyStructList <DateTime>;
1031+ template struct PyStructList <TimeDelta>;
1032+ template struct PyStructList <Date>;
1033+ template struct PyStructList <Time>;
1034+ template struct PyStructList <std::string>;
1035+ template struct PyStructList <DialectGenericType>;
1036+ template struct PyStructList <StructPtr>;
1037+ template struct PyStructList <CspEnum>;
1038+
10001039}
0 commit comments