Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SbDelegate.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Thibaut Andrieu (Mar 2015)
22**=======================================================================*/
23
24#ifndef _SB_DELEGATE_H_
25#define _SB_DELEGATE_H_
26
27#include <Inventor/SbDelegatePtrFunImpl.h>
28#include <Inventor/SbDelegateMemberFunImpl.h>
30namespace inventor
31{
32namespace helper
33{
34
40template<typename ReturnType, typename ArgType>
41
42{
43public:
44
46 SbDelegate()
47 {
48 }
49
51 SbDelegate( const SbDelegate<ReturnType, ArgType>& other )
52 : m_delegateImpl ( other.m_delegateImpl->clone() )
53 {
54 }
55
62 SbDelegate(ReturnType (*f)(ArgType))
63 {
64 if ( f != NULL )
65 m_delegateImpl = new inventor::impl::SbDelegatePtrFunImpl<ReturnType, ArgType>(f);
66 else
67 m_delegateImpl = NULL;
68 }
69
80 template<typename ClassType>
81 SbDelegate(ClassType& a, ReturnType (ClassType::*f)(ArgType))
82 {
83 if ( f != NULL )
84 m_delegateImpl = new inventor::impl::SbDelegateMemberFunImpl<ReturnType, ArgType, ClassType>(a, f);
85 else
86 m_delegateImpl = NULL;
87 }
88
93 ReturnType operator()(ArgType arg) const
94 {
95 if ( m_delegateImpl.ptr() != NULL )
96 return m_delegateImpl->call(arg);
97 else
98 return ReturnType();
99 }
100
105 bool equal(ReturnType (*f)(ArgType)) const
106 {
107 if ( m_delegateImpl.ptr() == NULL )
108 return (f == NULL);
109
110 inventor::impl::SbDelegatePtrFunImpl<ReturnType, ArgType>* delegatePtrFun = dynamic_cast< inventor::impl::SbDelegatePtrFunImpl<ReturnType, ArgType>* >(m_delegateImpl.ptr());
111 if ( delegatePtrFun != NULL )
112 return delegatePtrFun->equal(f);
113
114 return false;
115 }
116
121 template<typename ClassType>
122 bool equal(ClassType& a, ReturnType (ClassType::*f)(ArgType)) const
123 {
124 if ( m_delegateImpl.ptr() == NULL )
125 return (f == NULL);
126
127 inventor::impl::SbDelegateMemberFunImpl<ReturnType, ArgType, ClassType>* delegateMemberFun = NULL;
128 delegateMemberFun = dynamic_cast< inventor::impl::SbDelegateMemberFunImpl<ReturnType, ArgType, ClassType>* >(m_delegateImpl.ptr());
129 if ( delegateMemberFun != NULL )
130 return delegateMemberFun->equal(a, f);
131 else
132 return false;
133 }
134
135private:
136
139};
140
141} // helper
142} // inventor
144#endif // _SB_DELEGATE_H_
145
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90