35 shared_ptr<char[]> dataPtr;
38 Data(shared_ptr<
char[]> dataPtr,
size_t size) : dataPtr(std::move(dataPtr)), size(size) {}
55File::
File(std::shared_ptr<
char[]> dataPtr,
size_t size) {
56 data = make_unique<Data>(std::move(dataPtr), size);
59File::File(std::string
const& data) {
60 shared_ptr<char[]> dataPtr(
new char[data.size()]);
61 memcpy(dataPtr.get(), data.c_str(), data.size());
62 this->data = make_unique<Data>(std::move(dataPtr), data.size());
70 return {data->dataPtr.get(), data->size};
75 ios_base::iostate exceptionMask = outfile.exceptions() | ios::failbit;
76 outfile.exceptions(exceptionMask);
78 outfile.open(path, ofstream::out | ofstream::binary);
79 outfile.write(data->dataPtr.get(), data->size);
81 }
catch (ios_base::failure
const& e) {
82 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.
size_t size() const noexcept
void writeToDisk(std::string const &path) const
std::string toString() 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)