mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 19:48:07 +00:00
feat(core): add ContentType class
This commit is contained in:
parent
1e1d0d2f7f
commit
68bb508cb5
3 changed files with 176 additions and 3 deletions
|
|
@ -28,13 +28,13 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
call/call-listener.h
|
||||
call/call-p.h
|
||||
call/call.h
|
||||
chat/basic-chat-room.h
|
||||
chat/basic-chat-room-p.h
|
||||
chat/basic-chat-room.h
|
||||
chat/chat-message.h
|
||||
chat/chat-room-p.h
|
||||
chat/chat-room.h
|
||||
chat/client-group-chat-room.h
|
||||
chat/client-group-chat-room-p.h
|
||||
chat/client-group-chat-room.h
|
||||
chat/cpim/cpim.h
|
||||
chat/cpim/header/cpim-core-headers.h
|
||||
chat/cpim/header/cpim-generic-header.h
|
||||
|
|
@ -45,8 +45,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
chat/cpim/parser/cpim-parser.h
|
||||
chat/imdn.h
|
||||
chat/is-composing.h
|
||||
chat/real-time-text-chat-room.h
|
||||
chat/real-time-text-chat-room-p.h
|
||||
chat/real-time-text-chat-room.h
|
||||
conference/conference-listener.h
|
||||
conference/conference-p.h
|
||||
conference/conference.h
|
||||
|
|
@ -63,6 +63,8 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
|
|||
conference/session/call-session.h
|
||||
conference/session/media-session.h
|
||||
conference/session/port-config.h
|
||||
content/content-type.h
|
||||
content/content.h
|
||||
content/content.h
|
||||
core/core.h
|
||||
db/abstract/abstract-db-p.h
|
||||
|
|
@ -117,6 +119,8 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
|
|||
conference/remote-conference.cpp
|
||||
conference/session/call-session.cpp
|
||||
conference/session/media-session.cpp
|
||||
content/content-type.cpp
|
||||
content/content.cpp
|
||||
content/content.cpp
|
||||
core/core.cpp
|
||||
db/abstract/abstract-db.cpp
|
||||
|
|
|
|||
111
src/content/content-type.cpp
Normal file
111
src/content/content-type.cpp
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* content-type.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"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
using namespace std;
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ContentTypePrivate : public ClonableObjectPrivate {
|
||||
public:
|
||||
string type;
|
||||
string subType;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ContentType::ContentType (const string &contentType) : ClonableObject(*new ContentTypePrivate) {
|
||||
L_D(ContentType);
|
||||
|
||||
size_t pos = contentType.find('/');
|
||||
if (pos == string::npos)
|
||||
return;
|
||||
|
||||
if (setType(contentType.substr(0, pos))) {
|
||||
if (!setSubType(contentType.substr(pos + 1)))
|
||||
d->type.clear();
|
||||
}
|
||||
}
|
||||
|
||||
ContentType::ContentType (const string &type, const string &subType) : ClonableObject(*new ContentTypePrivate) {
|
||||
L_D(ContentType);
|
||||
|
||||
if (setType(type)) {
|
||||
if (!setSubType(subType))
|
||||
d->type.clear();
|
||||
}
|
||||
}
|
||||
|
||||
ContentType::ContentType (const ContentType &src) : ContentType(src.getType(), src.getSubType()) {}
|
||||
|
||||
ContentType &ContentType::operator= (const ContentType &src) {
|
||||
if (this != &src) {
|
||||
setType(src.getType());
|
||||
setSubType(src.getSubType());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool ContentType::operator== (const ContentType &contentType) {
|
||||
return getType() == contentType.getType() && getSubType() == contentType.getSubType();
|
||||
}
|
||||
|
||||
const string &ContentType::getType () const {
|
||||
L_D(const ContentType);
|
||||
return d->type;
|
||||
}
|
||||
|
||||
bool ContentType::setType (const std::string &type) {
|
||||
L_D(ContentType);
|
||||
if (type.find('/') == string::npos) {
|
||||
d->type = type;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const string &ContentType::getSubType () const {
|
||||
L_D(const ContentType);
|
||||
return d->subType;
|
||||
}
|
||||
|
||||
bool ContentType::setSubType (const std::string &subType) {
|
||||
L_D(ContentType);
|
||||
if (subType.find('/') == string::npos) {
|
||||
d->subType = subType;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ContentType::isValid () const {
|
||||
L_D(const ContentType);
|
||||
return !d->type.empty() && !d->subType.empty();
|
||||
}
|
||||
|
||||
string ContentType::asString () const {
|
||||
L_D(const ContentType);
|
||||
return isValid() ? d->type + "/" + d->subType : "";
|
||||
}
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
58
src/content/content-type.h
Normal file
58
src/content/content-type.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* content-type.h
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _CONTENT_TYPE_H_
|
||||
#define _CONTENT_TYPE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "object/clonable-object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class ContentTypePrivate;
|
||||
|
||||
class LINPHONE_PUBLIC ContentType : public ClonableObject {
|
||||
public:
|
||||
ContentType (const std::string &contentType = "");
|
||||
ContentType (const std::string &type, const std::string &subType);
|
||||
ContentType (const ContentType &src);
|
||||
|
||||
ContentType &operator= (const ContentType &src);
|
||||
|
||||
bool operator== (const ContentType &contentType);
|
||||
|
||||
bool isValid () const;
|
||||
|
||||
const std::string &getType () const;
|
||||
bool setType (const std::string &type);
|
||||
|
||||
const std::string &getSubType () const;
|
||||
bool setSubType (const std::string &subType);
|
||||
|
||||
std::string asString () const;
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(ContentType);
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
||||
#endif // ifndef _CONTENT_TYPE_H_
|
||||
Loading…
Add table
Reference in a new issue