Page 1 of 1
Specifying filter order
Posted: Thu Mar 15, 2007 7:48 pm
by Ambush Commander
Hello folks. I have a number of filters that need to be run on text. Sometimes order is important, sometimes it isn't. So, I need some way for users to arbitrarily order the filters. Some possibilities:
1. Assign each filter an integer weight, when the filter is added you stuff it in an array in an array, with the integer as the index
2. Assign each filter a float weight, the use array_multisort on a temporary array of all the filter's weights in order to get things in order
3. Require all filters to be specified at once, removing the need for weights
4. ???
What would you do?
Posted: Thu Mar 15, 2007 10:43 pm
by feyd
I think the most understandable and simple is simply an integer weight/priority. At some point it comes down to order of addition, but for the most part if they are grouped correctly, that part is moot.
Posted: Fri Mar 16, 2007 1:52 am
by Christopher
Depending on your needs it might be enough to have add() that appends and another method to add to the front of the list. That often handles enough other cases to be sufficient. If the filters are named/grouped/typed then you can also have insertBefore() and insertAfter(), which I find more specific than weights.
Posted: Fri Mar 16, 2007 3:48 am
by Maugrim_The_Reaper
Hello folks. I have a number of filters that need to be run on text. Sometimes order is important, sometimes it isn't. So, I need some way for users to arbitrarily order the filters. Some possibilities:
Priority seems the simplest - is it possible to allow filters check their own priority in comparison to others? Depending on the filter, it might need to run before, but never after another to ensure the text remains readable. Having rules for such filters would make it more difficult to accidentally put them in the wrong order. insertBefore() and insertAfter() as suggested by arborint would be a cool way of applying such rules.
Posted: Fri Mar 16, 2007 12:12 pm
by Ambush Commander
While weights are the most common implementation, I think I'll test drive arborint's idea and see how well it works for me.
Posted: Fri Mar 16, 2007 3:23 pm
by Ollie Saunders
Yeah I'd recommend going with arborint's idea. In fact I've done it in the past.
Possibly make sure you write in a way that will allow you to stick the weight idea on top as another layer or anything else for that matter.