Commit d4d2794c authored by Ronan's avatar Ronan
Browse files

feat(Object): add a PropertyContainer class

parent af09244d
......@@ -89,6 +89,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
object/clonable-object.h
object/object-p.h
object/object.h
object/property-container.h
object/singleton.h
utils/payload-type-handler.h
variant/variant.h
......@@ -140,6 +141,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
nat/stun-client.cpp
object/clonable-object.cpp
object/object.cpp
object/property-container.cpp
utils/general.cpp
utils/payload-type-handler.cpp
utils/utils.cpp
......
......@@ -23,8 +23,6 @@
#include "linphone/utils/general.h"
#include "variant/variant.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
......@@ -43,8 +41,6 @@ private:
int nRefs = 0;
std::unordered_map<std::string, Variant> properties;
L_DECLARE_PUBLIC(ClonableObject);
// It's forbidden to copy directly one Clonable object private.
......
......@@ -82,20 +82,4 @@ void ClonableObject::setRef (const ClonableObjectPrivate &p) {
mPrivate->ref();
}
Variant ClonableObject::getProperty (const string &name) const {
L_D(const ClonableObject);
auto it = d->properties.find(name);
return it == d->properties.cend() ? Variant() : it->second;
}
void ClonableObject::setProperty (const string &name, const Variant &value) {
L_D(ClonableObject);
d->properties[name] = value;
}
void ClonableObject::setProperty (const string &name, Variant &&value) {
L_D(ClonableObject);
d->properties[name] = move(value);
}
LINPHONE_END_NAMESPACE
......@@ -23,20 +23,16 @@
#include "linphone/utils/general.h"
#include "property-container.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Variant;
class LINPHONE_PUBLIC ClonableObject {
class LINPHONE_PUBLIC ClonableObject : public PropertyContainer {
public:
virtual ~ClonableObject ();
Variant getProperty (const std::string &name) const;
void setProperty (const std::string &name, const Variant &value);
void setProperty (const std::string &name, Variant &&value);
protected:
// Use a new ClonableObjectPrivate without owner.
explicit ClonableObject (ClonableObjectPrivate &p);
......
......@@ -34,20 +34,4 @@ Object::Object (ObjectPrivate &p) : mPrivate(&p) {
mPrivate->mPublic = this;
}
Variant Object::getProperty (const string &name) const {
L_D(const Object);
auto it = d->properties.find(name);
return it == d->properties.cend() ? Variant() : it->second;
}
void Object::setProperty (const string &name, const Variant &value) {
L_D(Object);
d->properties[name] = value;
}
void Object::setProperty (const string &name, Variant &&value) {
L_D(Object);
d->properties[name] = move(value);
}
LINPHONE_END_NAMESPACE
......@@ -19,24 +19,18 @@
#ifndef _OBJECT_H_
#define _OBJECT_H_
#include <string>
#include "linphone/utils/general.h"
#include "property-container.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class Variant;
class LINPHONE_PUBLIC Object {
class LINPHONE_PUBLIC Object : public PropertyContainer {
public:
virtual ~Object ();
Variant getProperty (const std::string &name) const;
void setProperty (const std::string &name, const Variant &value);
void setProperty (const std::string &name, Variant &&value);
protected:
explicit Object (ObjectPrivate &p);
......
/*
* property-container.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 <unordered_map>
#include "property-container.h"
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
class PropertyContainerPrivate {
public:
unordered_map<std::string, Variant> properties;
};
// -----------------------------------------------------------------------------
// Empty copy constructor. Don't change this pattern.
// PropertyContainer is an Entity component, not a simple structure.
// An Entity is UNIQUE.
PropertyContainer::PropertyContainer (const PropertyContainer &) {}
PropertyContainer &PropertyContainer::operator= (const PropertyContainer &) {
return *this;
}
Variant PropertyContainer::getProperty (const string &name) const {
L_D(const PropertyContainer);
auto it = d->properties.find(name);
return it == d->properties.cend() ? Variant() : it->second;
}
void PropertyContainer::setProperty (const string &name, const Variant &value) {
L_D(PropertyContainer);
d->properties[name] = value;
}
void PropertyContainer::setProperty (const string &name, Variant &&value) {
L_D(PropertyContainer);
d->properties[name] = move(value);
}
LINPHONE_END_NAMESPACE
/*
* property-container.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 _PROPERTY_CONTAINER_H_
#define _PROPERTY_CONTAINER_H_
#include <string>
#include "linphone/utils/general.h"
#include "variant/variant.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class PropertyContainerPrivate;
class LINPHONE_PUBLIC PropertyContainer {
public:
PropertyContainer () = default;
PropertyContainer (const PropertyContainer &src);
virtual ~PropertyContainer () = default;
PropertyContainer &operator= (const PropertyContainer &src);
Variant getProperty (const std::string &name) const;
void setProperty (const std::string &name, const Variant &value);
void setProperty (const std::string &name, Variant &&value);
private:
PropertyContainerPrivate *mPrivate = nullptr;
L_DECLARE_PRIVATE(PropertyContainer);
};
LINPHONE_END_NAMESPACE
#endif // ifndef _PROPERTY_CONTAINER_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment