mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-29 05:34:23 +00:00
nic_router: overwritable reference wrapper
While references are const and always valid, this wrapper is like a reference that is only always valid and can be overwritten. Ref #2670
This commit is contained in:
parent
119b9f9c2c
commit
709afcd945
53
repos/os/src/server/nic_router/reference.h
Normal file
53
repos/os/src/server/nic_router/reference.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* \brief Reference that can be overwritten
|
||||||
|
* \author Martin Stein
|
||||||
|
* \date 2016-08-24
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016-2017 Genode Labs GmbH
|
||||||
|
*
|
||||||
|
* This file is part of the Genode OS framework, which is distributed
|
||||||
|
* under the terms of the GNU Affero General Public License version 3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _REFERENCE_H_
|
||||||
|
#define _REFERENCE_H_
|
||||||
|
|
||||||
|
namespace Net {
|
||||||
|
|
||||||
|
template <typename> class Reference;
|
||||||
|
template <typename> class Const_reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Net::Reference
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
T *_obj;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Reference(T &obj) : _obj(&obj) { }
|
||||||
|
|
||||||
|
T &operator () () const { return *_obj; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Net::Const_reference
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
T const *_obj;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Const_reference(T const &obj) : _obj(&obj) { }
|
||||||
|
|
||||||
|
T const &operator () () const { return *_obj; }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _REFERENCE_H_ */
|
Loading…
x
Reference in New Issue
Block a user