wip: better foreign key management
This commit is contained in:
parent
72ecd1236d
commit
97757d57b6
|
|
@ -8,6 +8,7 @@ HEADERS += \
|
||||||
$$PWD/changelogtable.h \
|
$$PWD/changelogtable.h \
|
||||||
$$PWD/database.h \
|
$$PWD/database.h \
|
||||||
$$PWD/database_p.h \
|
$$PWD/database_p.h \
|
||||||
|
$$PWD/foreigncontainer.h \
|
||||||
$$PWD/propertysignalmapper.h \
|
$$PWD/propertysignalmapper.h \
|
||||||
$$PWD/query.h \
|
$$PWD/query.h \
|
||||||
$$PWD/table.h \
|
$$PWD/table.h \
|
||||||
|
|
@ -19,6 +20,7 @@ SOURCES += \
|
||||||
$$PWD/bulkinserter.cpp \
|
$$PWD/bulkinserter.cpp \
|
||||||
$$PWD/changelogtable.cpp \
|
$$PWD/changelogtable.cpp \
|
||||||
$$PWD/database.cpp \
|
$$PWD/database.cpp \
|
||||||
|
$$PWD/foreigncontainer.cpp \
|
||||||
$$PWD/propertysignalmapper.cpp \
|
$$PWD/propertysignalmapper.cpp \
|
||||||
$$PWD/query.cpp \
|
$$PWD/query.cpp \
|
||||||
$$PWD/table.cpp \
|
$$PWD/table.cpp \
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
#include "foreigncontainer.h"
|
||||||
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef FOREIGNCONTAINER_H
|
||||||
|
#define FOREIGNCONTAINER_H
|
||||||
|
|
||||||
|
template<class _OBJECT, typename _KEY>
|
||||||
|
class ForeignContainer
|
||||||
|
{
|
||||||
|
_OBJECT *_object{nullptr};
|
||||||
|
_KEY _key;
|
||||||
|
enum StorageType {
|
||||||
|
Key,
|
||||||
|
ClassValue
|
||||||
|
};
|
||||||
|
StorageType storageType;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ForeignContainer()
|
||||||
|
{}
|
||||||
|
|
||||||
|
ForeignContainer<_OBJECT, _KEY> operator =(const _KEY &key)
|
||||||
|
{
|
||||||
|
this->_key = key;
|
||||||
|
this->_object = nullptr;
|
||||||
|
this->storageType = Key;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
ForeignContainer<_OBJECT, _KEY> operator =(const _OBJECT *value)
|
||||||
|
{
|
||||||
|
this->_object = value;
|
||||||
|
this->storageType = ClassValue;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
_KEY key()
|
||||||
|
{
|
||||||
|
if (this->storageType == Key)
|
||||||
|
return _key;
|
||||||
|
else
|
||||||
|
return _object->primaryValue().template value<_KEY>();
|
||||||
|
}
|
||||||
|
|
||||||
|
_OBJECT *object()
|
||||||
|
{
|
||||||
|
return _object;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator _KEY()
|
||||||
|
{
|
||||||
|
return key();
|
||||||
|
}
|
||||||
|
|
||||||
|
operator _OBJECT()
|
||||||
|
{
|
||||||
|
return object();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FOREIGNCONTAINER_H
|
||||||
Loading…
Reference in New Issue