/usr/include/Wt/WMemoryResource is in libwt-dev 3.3.0-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | // 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 <Wt/WResource>
namespace Wt {
/*! \class WMemoryResource Wt/WMemoryResource Wt/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 creating the data requires computation which you would like to
* post-pone until the resource is served, then you may want to
* directly reimplement WResource instead and compute the data on the
* fly while streaming.
*
* Usage examples:
* \code
* Wt::WMemoryResource *imageResource = new Wt::WMemoryResource("image/gif", this);
*
* static const unsigned char gifData[]
* = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
* 0x80, 0x00, 0x00, 0xdb, 0xdf, 0xef, 0x00, 0x00, 0x00, 0x21,
* 0xf9, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00,
* 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
* 0x01, 0x00, 0x3b };
*
* imageResource->setData(gifData, 43);
* Wt::WImage *image = new Wt::WImage(imageResource, "1 transparent pixel");
* \endcode
*
* \sa WFileResource.
*/
class WT_API WMemoryResource : public WResource
{
public:
/*! \brief Creates a new resource.
*
* You must call setMimeType() and setData() before using the resource.
*/
WMemoryResource(WObject *parent = 0);
/*! \brief Creates a new resource with given mime-type.
*
* You must call setData() before using the resource.
*/
WMemoryResource(const std::string& mimeType, WObject *parent = 0);
/*! \brief Creates a new resource with given mime-type and data
*/
WMemoryResource(const std::string& mimeType,
const std::vector<unsigned char> &data,
WObject *parent = 0);
~WMemoryResource();
/*! \brief Sets new data for the resource to serve.
*/
void setData(const std::vector<unsigned char> &data);
/*! \brief Sets new data for the resource to serve.
*
* Sets the data from using the first \p count bytes from the
* C-style \p data array.
*/
void setData(const unsigned char *data, int count);
/*! \brief Returns the data this resource will serve.
*/
const std::vector<unsigned char>& data() const;
/*! \brief Returns the mime-type.
*/
const std::string mimeType() const { return mimeType_; }
/*! \brief Sets the mime-type.
*/
void setMimeType(const std::string& mimeType);
virtual void handleRequest(const Http::Request& request,
Http::Response& response);
private:
std::string mimeType_;
std::vector<unsigned char> data_;
};
}
#endif // WMEMORY_RESOURCE_H_
|