// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2007 Wim Dumon, Leuven, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WMEMORY_RESOURCE_H_
#define WMEMORY_RESOURCE_H_

#include <string>
#include <WResource>

namespace Wt {

/*! \class WMemoryResource WMemoryResource WMemoryResource
 *  \brief A Resource which streams data from memory
 *
 * Use this resource if you want to serve resource data from memory. This
 * is suitable for relatively small resources, which still require some
 * computation.
 *
 * If you require little computation for creating the data, then
 * you may want to reimplement WResource and compute the data on the fly
 * while streaming.
 *
 * If you have a lot of data, you may want to use a WFileResource instead.
 */
class WT_API WMemoryResource : public WResource
{
public:
  /*! \brief Create a new resource with given mime-type and data
   */
  WMemoryResource(const std::string mimeType, const std::vector<char> &data);

  /*! \brief Set new data for the resource to serve.
   */
  void setData(const std::vector<char> &data);

  /*! \brief Get the mime-type.
   */
  const std::string mimeType() const { return mimeType_; }

  /*! \brief Set the mime-type.
   */
  void setMimeType(const std::string mimeType);

private:
  std::string mimeType_;
  std::vector<char> data_;

protected:

  /*! \brief Return the mimetype
   */
  virtual const std::string resourceMimeType() const;

  /*! \brief Stream the data for this resource.
   */
  virtual bool streamResourceData(std::ostream& stream);
};

}

#endif // WMEMORY_RESOURCE_H_
