Lax pair, rogue-wave and soliton solutions for a variable-coefficient generalized nonlinear Schrödinger equation in an optical fiber, fluid or plasma