I had a program where I wanted to transform all of all of parameters created using #define statement to command line arguments so that I could write an algorithm to test the effect of different values for these parameters.
First copy and past all of the define statements to another location of your program ( I wanted to keep the define statements to be used as defaults if no new parameter value is passed.
After you have copied the text should look something like
#define PED_BRAKING_RATE 0.95f
#define PED_COMFORT_ZONE 1.5f
#define PED_QUERY_RADIUS 10.0f
NOTE: Make sure you have Regular expressions check-box checked.To replace these lines with atribute definitions you can use ability of find and replace to capture strings (). Putting a regular expressions between () will save that string into a variable $1 that can be used in your replace with:. IN this case use "#define ([A-Z|_]*)[ |.|0-9|f]*" (don't include the quotes ") to find one of the above lines. Now this line can be replaced with "float $1;". very cool stuff.
If you want to change all of the character to lowercase you will have to use ctrl+shift+y. Highlight want you want to change then use ctrl+shift+y.
The last thing I did was copy and paste a bunch of lines that assigned the #defined macro to the class varaible
ped_max_speed = PED_MAX_SPEED;
That I had to do slightly by hand because find and replace does not replace with lowercase as far as I know.
I want to change these lines into the piece of code that will be used to check if there was a command line parameter option passed to change this value. If there was update the value. This part was really easy.
I could use this in my find statement:
([a-z|_]*)[a-z| |_|A-Z|=]*;
and this to replace each line with the code I wanted:
else if ((*optionIter).first == "$1")\n\t\t{\n\t\t\t
(*optionIter).second
>> $1;\n\t\t}
To result in:
else if ((*optionIter).first == "ped_max_speed")
{
(*optionIter).second >> ped_max_speed;
}
I used this to replace about 50 assignments. Took me about 30 seconds.
Now all of my #define statement parameters are also command line arguments that can be passed to easily test out different values.
Happy hunting!
References:
- Me.
No comments:
Post a Comment