Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TrackedUniqueObject.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef ARGUS_APPS_CAMERA_UI_COMMON_TRACKEDUNIQUEOBJECT_H
30 #define ARGUS_APPS_CAMERA_UI_COMMON_TRACKEDUNIQUEOBJECT_H
31
32 #include "Error.h"
33
34 namespace ArgusSamples
35 {
36
37 /**
38 * A class tracking an Argus object through the TrackedUniqueObj below. The track/untrack functions
39 * are called whenever an Argus object is assigend to/removed from the TrackedUniqueObj object.
40 */
41 template <typename T> class Tracker
42 {
43 public:
44 virtual ~Tracker()
45 {
46 }
47
48 /**
49 * Called when the object is assigned to a TrackedUniqueObj
50 */
51 virtual bool track(T *obj) = 0;
52
53 /**
54 * Called when the object is removed from a TrackedUniqueObj
55 */
56 virtual bool untrack(T *ob) = 0;
57 };
58
59 /**
60 * This class helps track construction and destruction of Argus objects. Tracker classes are
61 * using it to track Argus objects.
62 * It exposes several functions of the Argus::UniqueObj class to allow it to be seamlessly
63 * replaced by a TrackedUniqueObj.
64 */
65 template <typename T> class TrackedUniqueObj
66 {
67 public:
68 TrackedUniqueObj()
69 : m_tracker(NULL)
70 {
71 }
72
73 ~TrackedUniqueObj()
74 {
75 PROPAGATE_ERROR_CONTINUE(reset());
76 }
77
78 T* get() const
79 {
80 return m_obj.get();
81 }
82
83 bool reset(T *obj = NULL, Tracker<T> *tracker = NULL)
84 {
85 if (obj && !tracker)
86 ORIGINATE_ERROR("Need to specify a tracker if the object is set.");
87
88 // untrack the previous object
89 if (m_obj)
90 {
91 assert(m_tracker);
92 PROPAGATE_ERROR(m_tracker->untrack(m_obj.get()));
93 }
94
95 m_obj.reset(obj);
96
97 // track the new object
98 if (m_obj)
99 {
100 assert(tracker);
101 m_tracker = tracker;
102
103 PROPAGATE_ERROR(m_tracker->track(m_obj.get()));
104 }
105
106 return true;
107 }
108
109 operator bool() const
110 {
111 return !!m_obj;
112 }
113
114 // allow this class to access private track/untrack functions from the Tracker class
115 friend class Tracker<T>;
116
117 private:
118 Tracker<T> *m_tracker;
119 Argus::UniqueObj<T> m_obj;
120 };
121
122 }; // namespace ArgusSamples
123
124 #endif // ARGUS_APPS_CAMERA_UI_COMMON_TRACKEDUNIQUEOBJECT_H