![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Optional arguments for DXL function Topic Summary: How does one write a function to accept optional arguments? Created On: 1-Nov-2005 18:57 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Hi Jason, there is a very simple way of creating function with variable parameter set. In DXL it is possible to overload functions, so you can create many functions with the same name and different parameter sets. The best way of dooing that is to create one funtion with mostly all parameters, that could apear. Then create some wrapper functions with a smaller parameter set, that calls the original function with some default values. Example : void doSth (int a, b, c, string s) { ...... } void doSth (int a, string s) { doSth (a, 1, 2, s) } void doSth (int a, b) { doSth (a,b, 2, "Hello World!") } I hope, this will help you, greetings Reik | |
![]() |
|
Some built-in DOORS functions can accept various numbers of arguments. An example of this is when using "set()" to apply a filter to a module. According to the DXL Reference Manual, this set() function is declared as follows:
void set(Module m,
Filter f
[,int &accepted,
int &rejected])
This suggests to me that if I write a DXL function to accept optional arguments (such as "accepted" and "rejected" in set() above) that I only need to enclose them with square brackets. This doesn't seem to work.
Is there a way to write a function to accept a various number of arguments? The only work around for this would be to have a global variable declared before the function, and then have the function look to that variable (and therefore set that variable when desired or leave it at its default value if desired). And example program that I am shooting for is as follows:
void foo (string name [,int count, bool liar])
{
if(null(liar)) liar=false
if(null(count)) count = 43
print "hi " name", it looks like the rumor about losing your " count " sheep was " liar ""
}
foo("jason") //output: hi jason, it looks like the rumor about losing your 43 sheep was false
foo("jason, 2)// output: hi jason, it looks like the rumor about losing your 2 sheep was false
foo("jason, , true)//output: hi jason, it looks like the rumor about losing your 43 sheep was true
Any clues?
Jason
|
|
![]() |
|
![]() |
|
Hi Jason,
there is a very simple way of creating function with variable parameter set. In DXL it is possible to overload functions, so you can create many functions with the same name and different parameter sets. The best way of dooing that is to create one funtion with mostly all parameters, that could apear. Then create some wrapper functions with a smaller parameter set, that calls the original function with some default values. Example : void doSth (int a, b, c, string s) { ...... } void doSth (int a, string s) { doSth (a, 1, 2, s) } void doSth (int a, b) { doSth (a,b, 2, "Hello World!") } I hope, this will help you, greetings Reik ------------------------- Evosoft GmbH for Siemens Industry Sector Berlin, Germany Edited: 2-Nov-2005 at 11:15 by Reik Schroeder |
|
![]() |
|
![]() |
|
You do this by writing multiple functions with the same name. This is known as "function overloading", and each function should have a unique combination of parameter-list and return type. DOORS works out which function to call by examining the number and type of parameters supplied, and the return type required when the function is called.
Edited: 2-Nov-2005 at 12:15 by Paul Worrall |
|
![]() |
|
![]() |
|
The other responders are correct, declare various overloaded functions. They are also correct that its "better" if these overloaded functions default the missing parameters and call the main function that has all the parameters defined. You need to be careful about return parameters: if the main function changes a parameter value be sure to declare a variable in the overloaded version; don't use a constant such as "1" or "false".
When the DXL manual uses the brackets it means those parameters are optional. That means that they have defined various over-loaded functions with the same name. The interpreter uses the number, position, and types of parameters to determine which function gets called. If you declare two functions with the same name and identical parameters, then you are lucky when you get DXL errors and are unlucky when you real strange things happen and have to beat your head against the wall for hours. - Louie |
|
![]() |
|
![]() |
|
Please note that you cannot overload a function declared with void parameters.
In other words if you want to overload a function as follows, then it is important that they are declared in the correct order, with the void paramter function last. ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Beautiful! Thanks a million guys!
Jason
Edited: 3-Nov-2005 at 14:41 by jason haury |
|
![]() |
|
![]() |
|
|
|
![]() |
|
![]() |
|
The attached work on my system v71 (with autodeclare off and with autodeclare on).
|
|
![]() |
|
![]() |
|
When you're right Louie, you're right.
This DOES work! I have contacted support again to see if they got to the bottom of the problem yet. My original bug report was posted when I tried to overload refreshListView(), which still causes an error. I will keep you informed of any news I get. ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Optional arguments for DXL function
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.