Way to add some sort multimensionality as in array but in OwnedArray?


#1

I created an OwnedArray Object to hold undefined number of button objects. I would like to know which is in your opionion the best/elegant way to add some sort multimensionality as in array but in OwnedArray. Would you use the name property of the id property for that?

names like: button1_1

                  button1_2

                  button1_3

                  button2_1

                  button2_2

                  button2_3

                  button3_1

                  (...)

Probably is not a good aproach, any thoughts?

Should i overight of the button class to add some sort of indexation? is there any alternatives? or litle snippets i could look for?

 

Thank you much,

dee 


#2

This totally depends on what you're actually trying to do, and the scale.  Is the array to be rectangluar?  Is it being used as a small core container in a single class, or something that is used widely?

If it's a rectangle data structure, and used in a pretty humble way, you could simply use a one-dimensional array and index with (y * w) + x.

For more widely used code, probably you should create a container class that uses an OwnedArray internally, but exposes a two-dimensional array to outside code.  Again the internals would likely just be a 1-d array with offset indexing, unless the array is of non-uniform dimensions.  You can always use an array of arrays, but I personally wouldn't even make this my first (or even second) choice.

 

 

 

 

 

 


#3

An OwnedArray inside an OwnedArray inside an OwnedArray inside an OwnedArray....

:P


#4

It has to be simple has it's very widly used  so i will have in mind your advice ;) 

Again Thumbs up!


#5

:)