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