Teuchos - Trilinos Tools Package Version of the Day
Loading...
Searching...
No Matches
Teuchos_Handle.hpp
1// @HEADER
2// *****************************************************************************
3// Teuchos: Common Tools Package
4//
5// Copyright 2004 NTESS and the Teuchos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TEUCHOS_HANDLE_HPP
11#define TEUCHOS_HANDLE_HPP
12
14#include "Teuchos_RCP.hpp"
15#include "Teuchos_Describable.hpp"
16#include "Teuchos_Handleable.hpp"
17
18namespace Teuchos
19{
20
46 template <typename PointerType>
47 class ConstHandle : public virtual Describable
48 {
49 public:
51 ConstHandle(const RCP<const PointerType>& ptr) : ptr_(ptr) {;}
54 explicit ConstHandle(const ConstHandleable<PointerType>* ptr) : ptr_(ptr->getConstRcp()) {;}
56 const RCP<const PointerType>& constPtr() const {return ptr_;}
58 const PointerType * const rawPtr() {return this->constPtr().get();}
59 protected:
61 explicit ConstHandle() : ptr_() {;}
74 private:
77 };
78
102 template <typename PointerType>
103 class Handle : public virtual ConstHandle<PointerType>
104 {
105 public:
112 {
113 /* \brief We need to set the rcp in the base class */
115 }
123 {
124 /* \brief We need to set the rcp in the base class. */
125 setRcp(rawPtr->getRcp());
126 }
129 RCP<PointerType> ptr() const {return this->nonConstPtr();}
131 PointerType* rawPtr() const {return this->nonConstPtr().get();}
132 };
133
134} // namespace Teuchos
135
147#define TEUCHOS_HANDLE_CTORS(handle, contents) \
148handle() : Teuchos::Handle<contents >() {;} \
149handle(Teuchos::Handleable<contents >* rawPtr) : Teuchos::Handle<contents >(rawPtr) {;} \
150handle(const Teuchos::RCP<contents >& smartPtr) : Teuchos::Handle<contents >(smartPtr){;}
151
163#define TEUCHOS_CONST_HANDLE_CTORS(handle, contents) \
164handle( Teuchos::ENull _null = Teuchos::null ) : Teuchos::ConstHandle<contents >() {;} \
165handle(const Teuchos::ConstHandleable<contents >* rawPtr) : Teuchos::ConstHandle<contents >(rawPtr) {;} \
166handle(const Teuchos::RCP<const contents >& smartPtr) : Teuchos::ConstHandle<contents >(smartPtr){;}
167
168#endif // TEUCHOS_CONSTHANDLE_HPP
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Reference-counted pointer class and non-member templated function implementations.
Templated handle class with strong const protection.
void setRcp(const RCP< PointerType > &ptr)
This function is needed in Handle ctors.
ConstHandle(const ConstHandleable< PointerType > *ptr)
Construct with a raw pointer to a ConstHandleable. This will make a call to rcp(),...
const PointerType *const rawPtr()
Access to raw pointer.
RCP< PointerType > nonConstPtr() const
Protected non-const access to the underlying smart pointer.
const RCP< const PointerType > & constPtr() const
Read-only access to the underlying smart pointer.
ConstHandle(const RCP< const PointerType > &ptr)
Construct with an existing RCP.
ConstHandle()
The empty ctor will only be called by Handle ctors.
Base class for all objects that can describe themselves.
Generic templated handle class.
RCP< PointerType > ptr() const
Read/write access to the underlying smart pointer.
Handle(const RCP< PointerType > &smartPtr)
Construct with an existing RCP.
PointerType * rawPtr() const
Access to non-const raw pointer.
Handle(Handleable< PointerType > *rawPtr)
Construct with a raw pointer to a Handleable.
Smart reference counting pointer class for automatic garbage collection.
T * get() const
Get the raw C++ pointer to the underlying object.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...