// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WLENGTHVALIDATOR_H_
#define WLENGTHVALIDATOR_H_

#include <limits>

#include <WValidator>

namespace Wt {

/*! \class WLengthValidator WLengthValidator WLengthValidator
 *  \brief A validator that checks the string length of user input.
 *
 * This validator checks whether user input is within the specified range
 * of accepted string lengths
 */
class WLengthValidator : public WValidator
{
public:
  /*! \brief Create a new validator
   */
  WLengthValidator(int minLength = 0,
		   int maxLength = std::numeric_limits<int>::min());

  /*! \brief Return the minimum length.
   */
  double minimumLength() const { return minLength_; }

  /*! \brief Set the minimum length.
   */
  void setMinimumLength(int minimum);

  /*! \brief Set message to display when the input is too short
   */
  void setInvalidTooShortText(const WString& text);

  /*! \brief Return the maximum length.
   */
  double maximumLength() const { return maxLength_; }

  /*! \brief Set the maximum length.
   */
  void setMaximumLength(int maximum);

  /*! \brief Set message to display when the input is too long
   */
  void setInvalidTooLongText(const WString& text);

  /*! \brief Validate the input as an double within the given range.
   *
   * Returns Valid if the input is an double in the given range.
   * Returns Invalid if the input is not an double, or outside of the
   * given range.        
   */
  virtual State validate(WString& input, int& pos) const;

  virtual void createExtConfig(std::ostream& config) const;

private:
  int minLength_;
  int maxLength_;

  WString tooLongText_;
  WString tooShortText_;
};

}

#endif // WLENGTHVALIDATOR_H_
