Commit | Line | Data |
---|---|---|
d44e3c4f | 1 | /****************************************************************************** |
2 | * Copyright (c) 2000-2016 Ericsson Telecom AB | |
3 | * All rights reserved. This program and the accompanying materials | |
4 | * are made available under the terms of the Eclipse Public License v1.0 | |
5 | * which accompanies this distribution, and is available at | |
6 | * http://www.eclipse.org/legal/epl-v10.html | |
7 | * | |
8 | * Contributors: | |
9 | * Balasko, Jeno | |
10 | * Delic, Adam | |
11 | * Raduly, Csaba | |
12 | * Szabo, Janos Zoltan – initial implementation | |
13 | * | |
14 | ******************************************************************************/ | |
970ed795 EL |
15 | #include "Array.hh" |
16 | ||
17 | unsigned int get_timer_array_index(int index_value, unsigned int array_size, | |
18 | int index_offset) | |
19 | { | |
20 | if (index_value < index_offset) TTCN_error("Index underflow when accessing " | |
21 | "an element of a timer array. The index value should be between %d and %d " | |
22 | "instead of %d.", index_offset, index_offset + array_size - 1, index_value); | |
23 | unsigned int ret_val = index_value - index_offset; | |
24 | if (ret_val >= array_size) | |
25 | TTCN_error("Index overflow when accessing an element of a timer array. " | |
26 | "The index value should be between %d and %d instead of %d.", index_offset, | |
27 | index_offset + array_size - 1, index_value); | |
28 | return ret_val; | |
29 | } | |
30 | ||
31 | unsigned int get_timer_array_index(const INTEGER& index_value, | |
32 | unsigned int array_size, int index_offset) | |
33 | { | |
34 | if (!index_value.is_bound()) TTCN_error("Accessing an element of a timer " | |
35 | "array using an unbound index."); | |
36 | return get_timer_array_index((int)index_value, array_size, index_offset); | |
37 | } | |
38 | ||
39 | unsigned int get_port_array_index(int index_value, unsigned int array_size, | |
40 | int index_offset) | |
41 | { | |
42 | if (index_value < index_offset) TTCN_error("Index underflow when accessing " | |
43 | "an element of a port array. The index value should be between %d and %d " | |
44 | "instead of %d.", index_offset, index_offset + array_size - 1, index_value); | |
45 | unsigned int ret_val = index_value - index_offset; | |
46 | if (ret_val >= array_size) | |
47 | TTCN_error("Index overflow when accessing an element of a port array. " | |
48 | "The index value should be between %d and %d instead of %d.", index_offset, | |
49 | index_offset + array_size - 1, index_value); | |
50 | return ret_val; | |
51 | } | |
52 | ||
53 | unsigned int get_port_array_index(const INTEGER& index_value, | |
54 | unsigned int array_size, int index_offset) | |
55 | { | |
56 | if (!index_value.is_bound()) TTCN_error("Accessing an element of a port " | |
57 | "array using an unbound index."); | |
58 | return get_timer_array_index((int)index_value, array_size, index_offset); | |
59 | } | |
60 | ||
61 | //////////////////////////////////////////////////////////////////////////////// | |
62 | ||
63 | unsigned int get_array_index(int index_value, unsigned int array_size, | |
64 | int index_offset) | |
65 | { | |
66 | if (index_value < index_offset) TTCN_error("Index underflow when accessing " | |
67 | "an element of an array. The index value should be between %d and %d " | |
68 | "instead of %d.", index_offset, index_offset + array_size - 1, index_value); | |
69 | unsigned int ret_val = index_value - index_offset; | |
70 | if (ret_val >= array_size) | |
71 | TTCN_error("Index overflow when accessing an element of an array. " | |
72 | "The index value should be between %d and %d instead of %d.", index_offset, | |
73 | index_offset + array_size - 1, index_value); | |
74 | return ret_val; | |
75 | } | |
76 | ||
77 | unsigned int get_array_index(const INTEGER& index_value, | |
78 | unsigned int array_size, int index_offset) | |
79 | { | |
80 | if (!index_value.is_bound()) TTCN_error("Accessing an element of an " | |
81 | "array using an unbound index."); | |
82 | return get_array_index((int)index_value, array_size, index_offset); | |
83 | } |