DOORS DXL Array

DOORS DXL Array

In this series of articles, we are going to explain DOORS DXL Array. So, if you are a beginner in DXL scripting, hopefully, this article would help you. This is part-7 of the DOORS DXL tutorial.

So, if you are looking for a starting point to learn DXL scripting, you are on the right page! I know, we have the DXL reference manual and it’s a bit concise and difficult to grasp for beginners, especially if you do not have any previous experience in other programming languages.

In this article, we will mainly discuss the DOORS DXL array.

What is DOORS DXL Array?

Similar to C/C++, DXL also supports array data types. There can be two types of array in DOORS DXL:

  1. Static Array
  2. Dynamic Array

In this article, we are gonna look into both types of arrays. We will see several examples of how to define DOORS DXL array – static and dynamic and how to use them.

What is a static array?

An array can be declared for any DXL type. The size of the static array is fixed when it is declared. Here is an example of a static array in DXL of integer type.

Static Array – Integer Type

In this example, I am going to declare an array of size 10 of integer data type. I am going to initialize them during the declaration and print them all using a for loop. The size of the array can be found using the function called – sizeof().

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d7.1.dxl
* $DESCRIPTION: Static Array in DXL - Integer array.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// Static array - integer type
int iArr[10] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
int i

// print all the elements of the array
for i in 0 : (sizeof(iArr) - 1) do {

	print("iArr[" i "] = " iArr[i] "\n")	
}

DOORS DXL Array - 7.1

Static Array – String type

Now, let us see another example of a static array of string type. I am gonna declare and initialize the string array of size 7, at the same time and then print all the elements of the array using a for loop. Likewise, we can have a static array of ant DXL data types.

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d7.2.dxl
* $DESCRIPTION: Static Array in DXL - String array.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// Static array - string type
string sWeekDay[7] = {"Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Sun"}
int i

// print all the elements of the array
for i in 0 : (sizeof(sWeekDay) - 1) do {

	print("sWeekDay[" i "] = " sWeekDay[i] "\n")	
}

DOORS DXL Array - 7.2

What is Dynamic Array in DXL?

Dynamic array in DXL indicates the two-dimensional array data type and the memory for it gets allocated dynamically. The dynamic array is not a DXL fundamental data type, therefore the type name “Array” begins with an uppercase letter.

Please note that the DXL does not provide automatic garbage collection. Therefore, it is the programmer’s responsibility to delete memory/deallocate the memory when it is no longer required by the program.

How to create a dynamic array in DXL?

Here is the syntax to create a dynamic array in DXL:

Array create (int x_dimension, int y_dimension)

How to delete dynamic arrays in DXL?

Here is the syntax for deleting a dynamic array in DXL:

void delete (Array a)

How to store data in a dynamic array in DXL?

Once you created the dynamic array, you can store the data in this way:

void put (Array a, <any_data_type> data, int x, int y)

The first argument is basically the name of the array in which you would want to store the data and the second argument is the actual data that you want to store inside the array. The last two arguments are the position of the data; x denotes the x coordinate and y denotes the y coordinate.

Dynamic Array in DXL – An example

Here is an example program to demonstrate how a dynamic array works in DXL. In this program, I have declared a dynamic array of size 3×1. As you can see the y_position is set to 1, which means that this is just a one-dimensional array with 3 elements. Therefore, the possible indices where you can store the data are – (0,1), (1,1), and (2,1).

Similarly, you can define a two-dimensional array by mentioning the x_position and y_position.

// www.TheCloudStrap.Com

/************************************************************************
* $FILENAME: d7.3.dxl
* $DESCRIPTION: Dynamic Array in DXL.
*
* NOTICE: Copyright www.TheCloudStrap.Com. All rights reserved.
* Software comes without any warranties and guarantees, is provided 
* as is and is not supported. Use this software at your own risk. 
* Authors resume no liabilities.
* 
* Contact: admin {at} TheCloudStrap.com
************************************************************************/

// Dynamic array - memory allocation for dynamic array of size 3x1
Array dynArr = create(3,1)

// Store integer type data in 0th position of dynArr
// put(dynamic_array_name, data_value, x_position, y_position)
put(dynArr, 10, 0, 1)
put(dynArr, 15, 1, 1)
put(dynArr, 20, 2, 1)


// Here is the structure of the array would look like:
//      
//    --------------------
//    | 10  |  15  |  20 |
//    --------------------
//     (0,1)  (1,1)  (2,1)


int dynArrEle = 0

// always cast to desired type before get() function
dynArrEle = (int get(dynArr, 0, 1))
print("dynArr[0,1] = " dynArrEle "\n")


dynArrEle = (int get(dynArr, 1, 1))
print("dynArr[1,1] = " dynArrEle "\n")


dynArrEle = (int get(dynArr, 2, 1))
print("dynArr[2,1] = " dynArrEle "\n")
DOORS DXL Array - 7.3

Conclusion

In this article, we have discussed DOORS DXL Array – a static array in DXL as well as a dynamic array in DXL. We have explained how to declare and define a static array, how to print all the elements of the array, how to declare and define a dynamic array, etc. in DOORS DXL. I hope this was a helpful article. However, if you have any questions about the DOORS DXL array, please feel free to comment below.

DOORS DXL Array
Scroll to top
error: Content is protected !!