A general approach to hysteresis