  In this paper we describe generic algorithms and data structures for the
implementation of $hp$-adaptive discontinuous finite element methods in the
Dune-Fem library. Special attention is given to the often tedious and
error-prone task of transferring user data during adaptation. Simultaneously,
we generalize the approach to the restriction and prolongation of data
currently implemented in Dune-Fem to the case of $p$- and $hp$-adaptation. The
dune-fem-hpdg module described in this paper provides an extensible reference
implementation of $hp$-adaptive discontinuous discrete function spaces. We give
details on its implementation and the extended adaptive interface. As proof of
concept we present the practical realization of an $hp$-adaptive interior
penalty method for elliptic problems.
