c++ - Named sub-arrays of an array -
i want design data structure following properties:
- accessible single array of type
t
. examples[i]
. - ability access named ranges in it. example
s.goodobjects[i]
,s.badobjects[j]
. - iterate on whole (stl algorithms etc.).
- converting name-index index in whole array. here interface question too.
also desired behaviour ability to
- i want ranges names checked @ compile time, not string-named ranges, c++ identifier-named.
- add or remove elements subarrays.
s.badobjects.push_back(yourmom)
. - implement without using macros, c++ , templates, readability of usages of course #1 priority.
- possibly range arrays have element type of pointer derived class
t
pointer base class.
so, how design such structure?
edit
looks haven't stated explicitly, 4th requirement (the first list) important one. maybe more general question follows: how design indexed collection of objects of different types (having common superclass) easy indexed access objects of particular subtype? so, having through index neccesity.
one can assume types known @ compile-time, , amount of every particular object in whole array constant (from config file).
if want to this, have class storing several std::vectors , supply operator[] class redirects these vectors, perhaps depending on respective size.
while you're @ it, outer class provide begin()
, end()
allow iteration on entire dataset.
i doubt though good-design
tag applicable here. :-)
Comments
Post a Comment