Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Reik Schroeder, on Thursday, November 3, 2005 2:44 PM

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
 1-Nov-2005 18:57
User is offline View Users Profile Print this message


jason haury

Posts: 10
Joined: 13-Oct-2005

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
Report this to a Moderator Report this to a Moderator
 2-Nov-2005 11:13
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Answer 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

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany

Edited: 2-Nov-2005 at 11:15 by Reik Schroeder
Report this to a Moderator Report this to a Moderator
 2-Nov-2005 11:18
User is offline View Users Profile Print this message


Paul Worrall

Posts: 87
Joined: 30-Sep-2003

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
Report this to a Moderator Report this to a Moderator
 2-Nov-2005 19:27
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 3-Nov-2005 10:02
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 3-Nov-2005 14:40
User is offline View Users Profile Print this message


jason haury

Posts: 10
Joined: 13-Oct-2005

Beautiful! Thanks a million guys! Jason

Edited: 3-Nov-2005 at 14:41 by jason haury
Report this to a Moderator Report this to a Moderator
 3-Nov-2005 14:44
User is offline View Users Profile Print this message


jason haury

Posts: 10
Joined: 13-Oct-2005

Report this to a Moderator Report this to a Moderator
 7-Nov-2005 22:17
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

The attached work on my system v71 (with autodeclare off and with autodeclare on).
Report this to a Moderator Report this to a Moderator
 8-Nov-2005 09:17
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.