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 | * Baranyi, Botond |
11 | * |
12 | ******************************************************************************/ |
a38c6d4c |
13 | |
14 | #ifndef REFDINDEX_HH |
15 | #define REFDINDEX_HH |
16 | |
17 | #ifdef TITAN_RUNTIME_2 |
18 | |
19 | /** This class contains the functions needed for adding and removing referenced |
20 | * indexes to record of/set of types and the optional type (only in RT2). |
21 | * By default the functions are empty.*/ |
22 | class RefdIndexInterface |
23 | { |
24 | public: |
25 | virtual ~RefdIndexInterface() {} |
26 | virtual void add_refd_index(int) {} |
27 | virtual void remove_refd_index(int) {} |
28 | }; |
29 | |
30 | /** References to record of/set of elements through 'out' and 'inout' function |
31 | * parameters are handled by this class. |
32 | * Usage: create instances of this class before the function call (one instance |
33 | * for each referenced index), and place the instances and the function call in |
34 | * a block (so the destructor is called immediately after the function call). |
35 | * This way the referenced indexes are cleaned up even if the function call ends |
36 | * with an exception (DTE) */ |
37 | class RefdIndexHandler |
38 | { |
39 | public: |
40 | RefdIndexHandler(RefdIndexInterface* p_container, int p_index) |
41 | { |
42 | container = p_container; |
43 | index = p_index; |
44 | container->add_refd_index(index); |
45 | } |
46 | |
47 | ~RefdIndexHandler() |
48 | { |
49 | container->remove_refd_index(index); |
50 | } |
51 | |
52 | private: |
53 | RefdIndexInterface* container; |
54 | int index; |
55 | }; |
56 | |
57 | #endif /* TITAN_RUNTIME_2 */ |
58 | |
59 | #endif /* REFDINDEX_HH */ |
60 | |