c++ - Named sub-arrays of an array -


i want design data structure following properties:

  1. accessible single array of type t. example s[i].
  2. ability access named ranges in it. example s.goodobjects[i], s.badobjects[j].
  3. iterate on whole (stl algorithms etc.).
  4. converting name-index index in whole array. here interface question too.

also desired behaviour ability to

  1. i want ranges names checked @ compile time, not string-named ranges, c++ identifier-named.
  2. add or remove elements subarrays. s.badobjects.push_back(yourmom).
  3. implement without using macros, c++ , templates, readability of usages of course #1 priority.
  4. 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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -