1 module des.util.data.attrib; 2 3 import des.util.data.type; 4 5 /// data array description 6 interface Attribute 7 { 8 const @property 9 { 10 string desc(); /// 11 ref const(ElemInfo) info(); /// 12 protected size_t manual_stride(); /// 13 size_t offset(); /// 14 const(void[]) data(); /// 15 16 /// 17 final size_t stride() 18 { return manual_stride ? manual_stride : info.bpe; } 19 20 /// 21 final size_t count() 22 { return ( data.length - offset ) / stride; } 23 } 24 } 25 26 /++ 27 simple realisation of Attribute interface 28 +/ 29 class SimpleAttribute : Attribute 30 { 31 protected: 32 string _desc; /// 33 ElemInfo _info; /// 34 void[] _data; /// 35 36 public: 37 38 /// 39 this( string Desc, ElemInfo Info, in void[] Data ) 40 { 41 _desc = Desc; 42 _info = Info; 43 _data = Data.dup; 44 } 45 46 /// 47 this(T)( string Desc, in T[] Data ) 48 { 49 _desc = Desc; 50 _info = ElemInfo.fromType!T; 51 _data = Data.dup; 52 } 53 54 const @property 55 { 56 string desc() { return _desc; } 57 ref const(ElemInfo) info() { return _info; } 58 protected size_t manual_stride() { return 0; } 59 size_t offset() { return 0; } 60 const(void[]) data() { return _data; } 61 } 62 } 63 64 /// 65 unittest 66 { 67 import des.math.linear; 68 vec2[] data = [ vec2(1,2), vec2(3,4) ]; 69 auto a = new SimpleAttribute( "test", data ); 70 71 assert( a.stride == vec2.sizeof ); 72 assert( a.info.type == DataType.FLOAT ); 73 assert( a.info.comp == 2 ); 74 assert( a.data == cast(void[])data ); 75 }