36 shared_ptr<char[]> dataPtr;
39 Data(shared_ptr<
char[]> dataPtr,
size_t size) : dataPtr(move(dataPtr)), size(size) {}
56File::
File(std::shared_ptr<
char[]> dataPtr,
size_t size) {
57 data = make_unique<Data>(move(dataPtr), size);
60File::File(std::string
const& data) {
61 shared_ptr<char[]> dataPtr(
new char[data.size()]);
62 memcpy(dataPtr.get(), data.c_str(), data.size());
63 this->data = make_unique<Data>(move(dataPtr), data.size());
71 return string(data->dataPtr.get(), data->size);
76 ios_base::iostate exceptionMask = outfile.exceptions() | ios::failbit;
77 outfile.exceptions(exceptionMask);
79 outfile.open(path, ofstream::out | ofstream::binary);
80 outfile.write(data->dataPtr.get(), data->size);
82 }
catch (ios_base::failure
const& e) {
83 throw Exception(__PRETTY_FUNCTION__, 1,
"Could not write file to disk.", e.what());
Exception class that can be used by apps to catch errors resulting from nawa function calls.
Container for (especially POST-submitted) files.
std::string toString() const
size_t size() const noexcept
void writeToDisk(std::string const &path) const
#define NAWA_DEFAULT_DESTRUCTOR_IMPL(Class)
#define NAWA_COPY_CONSTRUCTOR_IMPL(Class)
#define NAWA_COMPLEX_DATA_ACCESSORS_IMPL(Class, Member, Type)
#define NAWA_MOVE_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_COPY_ASSIGNMENT_OPERATOR_IMPL(Class)
#define NAWA_MOVE_CONSTRUCTOR_IMPL(Class)