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:
Martin Stein 2018-03-15 19:14:55 +01:00 committed by Christian Helmuth
parent 119b9f9c2c
commit 709afcd945

View 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_ */