linphone-iphone/src/content/content.cpp
2017-09-12 17:46:04 +02:00

108 lines
2.6 KiB
C++

/*
* content.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "content-type.h"
#include "object/clonable-object-p.h"
#include "content.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
class ContentPrivate : public ClonableObjectPrivate {
public:
vector<char> body;
ContentType contentType;
};
// -----------------------------------------------------------------------------
Content::Content () : ClonableObject(*new ContentPrivate) {}
Content::Content (const Content &src) : ClonableObject(*new ContentPrivate) {
L_D(Content);
d->body = src.getBody();
d->contentType = src.getContentType();
}
Content::Content (Content &&src) {
L_D(Content);
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
}
Content &Content::operator= (const Content &src) {
L_D(Content);
if (this != &src) {
d->body = src.getBody();
d->contentType = src.getContentType();
}
return *this;
}
Content &Content::operator= (Content &&src) {
L_D(Content);
if (this != &src) {
d->body = move(src.getPrivate()->body);
d->contentType = move(src.getPrivate()->contentType);
}
return *this;
}
const ContentType &Content::getContentType () const {
L_D(const Content);
return d->contentType;
}
void Content::setContentType (const ContentType &contentType) {
L_D(Content);
d->contentType = contentType;
}
const std::vector<char> &Content::getBody () const {
L_D(const Content);
return d->body;
}
void Content::setBody (const std::vector<char> &body) {
L_D(Content);
d->body = body;
}
void Content::setBody (const std::string &body) {
L_D(Content);
d->body = vector<char>(body.cbegin(), body.cend());
}
void Content::setBody (const void *buffer, size_t size) {
L_D(Content);
const char *start = static_cast<const char *>(buffer);
d->body = vector<char>(start, start + size);
}
size_t Content::getSize () const {
L_D(const Content);
return d->body.size();
}
LINPHONE_END_NAMESPACE