mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
feat(app): add new source folder with object base
This commit is contained in:
parent
339c7678f6
commit
ed69bd4505
3 changed files with 160 additions and 0 deletions
60
src/object/object.h
Normal file
60
src/object/object.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* object.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 _OBJECT_H_
|
||||
#define _OBJECT_H_
|
||||
|
||||
#include "utils/general.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace Linphone {
|
||||
class Object;
|
||||
|
||||
class ObjectPrivate {
|
||||
public:
|
||||
virtual ~ObjectPrivate () = default;
|
||||
|
||||
protected:
|
||||
Object *mPublic = nullptr;
|
||||
|
||||
private:
|
||||
L_DECLARE_PUBLIC(Object);
|
||||
};
|
||||
|
||||
class Object {
|
||||
public:
|
||||
virtual ~Object () {
|
||||
delete mPrivate;
|
||||
}
|
||||
|
||||
protected:
|
||||
explicit Object (ObjectPrivate *objectPrivate) : mPrivate(objectPrivate) {
|
||||
if (mPrivate)
|
||||
mPrivate->mPublic = this;
|
||||
}
|
||||
|
||||
ObjectPrivate *mPrivate = nullptr;
|
||||
|
||||
private:
|
||||
L_DECLARE_PRIVATE(Object);
|
||||
L_DISABLE_COPY(Object);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ifndef _OBJECT_H_
|
||||
51
src/object/singleton.h
Normal file
51
src/object/singleton.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* singleton.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 _SINGLETON_H_
|
||||
#define _SINGLETON_H_
|
||||
|
||||
#include "object.h"
|
||||
|
||||
// =============================================================================
|
||||
|
||||
namespace Linphone {
|
||||
template<class T>
|
||||
class Singleton : public Object {
|
||||
public:
|
||||
static Singleton<T> *getInstance () {
|
||||
if (!mInstance)
|
||||
mInstance = new Singleton<T>();
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
virtual ~Singleton () = default;
|
||||
|
||||
protected:
|
||||
explicit Singleton (ObjectPrivate *objectPrivate = nullptr) : Object(objectPrivate) {}
|
||||
|
||||
private:
|
||||
static Singleton<T> *mInstance;
|
||||
|
||||
L_DISABLE_COPY(Singleton);
|
||||
};
|
||||
|
||||
template<class T>
|
||||
Singleton<T> *Singleton<T>::mInstance = nullptr;
|
||||
}
|
||||
|
||||
#endif // ifndef _SINGLETON_H_
|
||||
49
src/utils/general.h
Normal file
49
src/utils/general.h
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* general.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 _GENERAL_H_
|
||||
#define _GENERAL_H_
|
||||
|
||||
#define L_DECLARE_PRIVATE(CLASS) \
|
||||
inline CLASS ## Private * getPrivate() { \
|
||||
return reinterpret_cast<CLASS ## Private *>(mPrivate); \
|
||||
} \
|
||||
inline const CLASS ## Private *getPrivate() const { \
|
||||
return reinterpret_cast<const CLASS ## Private *>(mPrivate); \
|
||||
} \
|
||||
friend class CLASS ## Private;
|
||||
|
||||
#define L_DECLARE_PUBLIC(CLASS) \
|
||||
inline CLASS * getPublic() { \
|
||||
return static_cast<CLASS *>(mPublic); \
|
||||
} \
|
||||
inline const CLASS *getPublic() const { \
|
||||
return static_cast<const CLASS *>(mPublic); \
|
||||
} \
|
||||
friend class CLASS;
|
||||
|
||||
#define L_DISABLE_COPY(CLASS) \
|
||||
CLASS(const CLASS &) = delete; \
|
||||
CLASS &operator= (const CLASS &) = delete;
|
||||
|
||||
#define L_D(CLASS) CLASS ## Private * const d = getPrivate();
|
||||
#define L_Q(CLASS) CLASS * const q = getPublic();
|
||||
|
||||
#endif // ifndef _GENERAL_H_
|
||||
Loading…
Add table
Reference in a new issue