diff --git a/src/nut/core/core.pri b/src/nut/core/core.pri index 3092946..05b39f2 100644 --- a/src/nut/core/core.pri +++ b/src/nut/core/core.pri @@ -8,6 +8,7 @@ HEADERS += \ $$PWD/changelogtable.h \ $$PWD/database.h \ $$PWD/database_p.h \ + $$PWD/foreigncontainer.h \ $$PWD/propertysignalmapper.h \ $$PWD/query.h \ $$PWD/table.h \ @@ -19,6 +20,7 @@ SOURCES += \ $$PWD/bulkinserter.cpp \ $$PWD/changelogtable.cpp \ $$PWD/database.cpp \ + $$PWD/foreigncontainer.cpp \ $$PWD/propertysignalmapper.cpp \ $$PWD/query.cpp \ $$PWD/table.cpp \ diff --git a/src/nut/core/foreigncontainer.cpp b/src/nut/core/foreigncontainer.cpp new file mode 100644 index 0000000..ca605c8 --- /dev/null +++ b/src/nut/core/foreigncontainer.cpp @@ -0,0 +1,2 @@ +#include "foreigncontainer.h" + diff --git a/src/nut/core/foreigncontainer.h b/src/nut/core/foreigncontainer.h new file mode 100644 index 0000000..5833422 --- /dev/null +++ b/src/nut/core/foreigncontainer.h @@ -0,0 +1,58 @@ +#ifndef FOREIGNCONTAINER_H +#define FOREIGNCONTAINER_H + +template +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